16.07.2024 - 10.12.2024 https://chatgpt.com/g/g-uib6qYHGw-tr...ipt-v5-creator
denemek isteyene..PHP Code:
//@version=6
indicator("deneme", shorttitle = "..", overlay = true)
// Inputs
maLength = input.int(5, 'MA Length', minval = 1)
maSource = input.source(close, 'MA Source')
// 5 MA
ma = ta.sma(maSource, maLength)
// Two most recent CLOSED dots
dot1 = ma[1]
dot2 = ma[5]
// Plot dots
plot(ma,"1-5", style = plot.style_line, color = color.rgb(255, 235, 59, 00), linewidth = 1)
maLengthj = input.int(20, 'MA Length', minval = 1)
maSourcej = input.source(close, 'MA Source')
// 20 MA
maj = ta.sma(maSourcej, maLengthj)
// Two most recent CLOSED dots
dot1j = maj[5]
dot2j = maj[20]
// Plot dots
plot(maj,"5-20", style = plot.style_line, color = color.rgb(0, 187, 212, 00), linewidth = 1)
//////////////////////////////
16.07.2024 - 10.12.2024 https://chatgpt.com/g/g-uib6qYHGw-tr...ipt-v5-creator
denemek isteyene... heikin ashi.... (bölme etiketlerini iptal edin ve boş mum kullanın)PHP Code:
//@version=6
indicator('Neural Network Buy and Sell Signals', shorttitle = '.', overlay = true, max_lines_count = 100, max_labels_count=100, max_boxes_count = 100, max_bars_back = 100)
var string scalpHelperGroup = 'Scalp Helper Signal Settings'
enable_scalp_helper = input.bool(true, 'Enable Scalp Helper Signals', group = scalpHelperGroup)
signalCandleType = input.string('Heikin Ashi', 'Signal Candle Type', options = ['Candlesticks', 'Heikin Ashi', 'Linear Regression'], group = scalpHelperGroup, tooltip = 'Choose which candle type to use for signal calculations. This will not change what candlestick type is displayed.')
signal_trigger_mult = input.float(0.1, 'Signal Trigger Sensitivity', minval = 0.1, maxval = 10.0, step = 0.1, group = scalpHelperGroup, tooltip = 'Controls both buy and sell signal sensitivity. Lower values = more sensitive signals, higher values = less sensitive signals.')
stop_atr_mult = input.float(1.5, 'Stop Loss ATR Multiplier', minval = 0.1, maxval = 10.0, step = 0.1, group = scalpHelperGroup, tooltip = 'Once a signal is triggered this stop will be initiated to tell how long the signal is valid. Higher values = wider stops and less signals, lower values = tighter stops and more signals.')
var string candleGroup = 'Candlestick Settings'
candleType = input.string('Heikin Ashi', 'Candle Type', options = ['Candlesticks', 'Heikin Ashi', 'Linear Regression'], group = candleGroup, tooltip = 'Choose the type of candles to display. This does not impact signal calculations.')
lrcLength1 = input.int(100, 'Linear Regression Length', minval = 1, group = candleGroup, tooltip = 'Length for Linear Regression calculations. Lower values are more responsive but noisier.')
var string visualGroup = 'Display Settings'
signalOffset = input.float(5, 'Signal Distance from Candles', minval = 0.1, maxval = 5.0, step = 0.1, group = visualGroup, tooltip = 'Distance of buy/sell labels from candles (ATR multiplier)')
signalLabelSize = input.string('medium', 'Signal Label Size', options = ['tiny', 'small', 'medium', 'large'], group = visualGroup, tooltip = 'Size of the neural network signal labels')
buy_signal_length = 2
buy_atr_length = 18
sell_signal_length = 2
sell_atr_length = 18
buy_signal_use_close = false
buy_atr_use_close = true
sell_signal_use_close = false
sell_atr_use_close = true
amf_length = 14
amf_signal_length = 9
amf_smoothing = 3
amf_fast_length = 5
amf_slow_length = 21
amf_far_threshold = 0.3
amf_slope_fast_threshold = 0.03
h1_amf_weight = 1.2
h1_alma_weight = 0.4
h1_sr_weight = 0.5
h1_swing_weight = 0.4
h1_regime_weight = 0.7
h1_bias = 0.2
h2_amf_weight = 1.4
h2_alma_weight = 0.3
h2_sr_weight = 0.6
h2_swing_weight = 0.3
h2_regime_weight = 0.8
h2_bias = 0.15
h3_amf_weight = 1.6
h3_alma_weight = 0.4
h3_sr_weight = 0.4
h3_swing_weight = 0.5
h3_regime_weight = 0.6
h3_bias = 0.25
out_h1_weight = 0.4
out_h2_weight = 0.4
out_h3_weight = 0.4
out_bias = 0.3
enable_input_normalization = true
normalization_lookback = 50
outlier_clipping = true
clipping_threshold = 3.0
almaLength = 20
almaOffset = 0.85
almaSigma = 6.0
alma2Length = 20
alma2Offset = 0.77
alma2Sigma = 6.0
alma_wide_gap_threshold = 0.1
pivot_lookback = 10
sr_proximity_threshold = 0.5
sr_breakout_threshold = 0.2
swing_structure_length = 20
regime_lookback = 30
trending_threshold = 0.6
showScalpLabels = true
var float signalOpen = open
var float signalHigh = high
var float signalLow = low
var float signalClose = close
customBuyColor = color.new(#00FFFF, 0)
customSellColor = color.new(#FF0000, 0)
scalpLongColor = color.new(#00B3B3, 0)
scalpShortColor = color.new(#FF0000, 0)
textColor = color.new(color.white, 0)
f_ema_amf(source, len) =>
float alpha = 2.0 / (len + 1)
var float ema_val = na
if not na(source) and len > 0
ema_val := alpha * source + (1 - alpha) * nz(ema_val[1])
ema_val
f_dema_amf(source, len) =>
float ema1 = f_ema_amf(source, len)
float ema2 = f_ema_amf(ema1, len)
float dema_val = 2 * ema1 - ema2
dema_val
f_zlema_amf(source, len) =>
int lag = int((len - 1) / 2)
float lag_source = lag > 0 ? source[lag] : source
float adjusted_source = source + (source - lag_source)
float zlema_val = f_ema_amf(adjusted_source, len)
zlema_val
f_sum_amf(source, len) =>
float sum_val = 0.0
for i = 0 to len - 1
sum_val += nz(source[i], 0)
sum_val
f_calculate_amf(src, length, fast_len, slow_len, smooth_len) =>
float current_atr = ta.atr(14)
float avg_atr = ta.sma(current_atr, 50)
float volatility_ratio = avg_atr > 0 ? current_atr / avg_atr : 1.0
float volatility_sensitivity = 2.0
float raw_adaptive_lookback = float(length) / math.pow(volatility_ratio, volatility_sensitivity)
int adaptive_lookback = int(math.max(5, math.min(50, raw_adaptive_lookback)))
if adaptive_lookback < 1
adaptive_lookback := 1
int zlema_fast_len = adaptive_lookback
int dema_medium_len = int(adaptive_lookback * 1.5)
int dema_slow_len = int(adaptive_lookback * 2.5)
if dema_medium_len < 1
dema_medium_len := 1
if dema_slow_len < 1
dema_slow_len := 1
float zlema_fast = f_zlema_amf(src, zlema_fast_len)
float dema_medium = f_dema_amf(src, dema_medium_len)
float dema_slow = f_dema_amf(src, dema_slow_len)
float pv = 0.0
if src > src[1]
pv := volume
else if src < src[1]
pv := -volume
float vzo_sum = f_sum_amf(pv, length)
float vol_sum = f_sum_amf(volume, length)
float vzo_value = vol_sum != 0 ? 100 * (vzo_sum / vol_sum) : 0.0
float smoothed_vzo = ta.sma(vzo_value, 3)
float price_vs_fast_weight = 30.0
float fast_vs_medium_weight = 30.0
float medium_vs_slow_weight = 40.0
float vzo_weight = 20.0
float oscillator_score = 0.0
if src > zlema_fast
oscillator_score += price_vs_fast_weight
else if src < zlema_fast
oscillator_score -= price_vs_fast_weight
if zlema_fast > dema_medium
oscillator_score += fast_vs_medium_weight
else if zlema_fast < dema_medium
oscillator_score -= fast_vs_medium_weight
if dema_medium > dema_slow
oscillator_score += medium_vs_slow_weight
else if dema_medium < dema_slow
oscillator_score -= medium_vs_slow_weight
oscillator_score += (smoothed_vzo / 100) * vzo_weight
float max_possible_score = price_vs_fast_weight + fast_vs_medium_weight + medium_vs_slow_weight + vzo_weight
float normalized_score = max_possible_score != 0.0 ? (oscillator_score / max_possible_score) * 100.0 : 0.0
float final_amf = ta.ema(normalized_score / 100.0, smooth_len)
final_amf
f_amf_signal(amf_line, signal_length) =>
ta.ema(amf_line, signal_length)
// ===========================================================================================================
// CACHED CALCULATIONS
// ===========================================================================================================
cached_atr = ta.atr(14)
// ===========================================================================================================
// NORMALIZATION FUNCTIONS
// ===========================================================================================================
f_normalizeInput(value, lookback_period, enable_clipping, clip_threshold) =>
if not enable_input_normalization
value
else
mean_val = ta.sma(value, lookback_period)
variance = ta.sma(math.pow(value - mean_val, 2), lookback_period)
std_val = math.sqrt(variance)
normalized = std_val > 0 ? (value - mean_val) / std_val : 0.0
if enable_clipping
math.max(-clip_threshold, math.min(clip_threshold, normalized))
else
normalized
f_robustNormalize(value, lookback_period) =>
if not enable_input_normalization
value
else
ema_val = ta.ema(value, lookback_period)
abs_dev = math.abs(value - ema_val)
mad_approx = ta.ema(abs_dev, lookback_period) * 1.4826
mad_approx > 0 ? (value - ema_val) / mad_approx : 0.0
// ===========================================================================================================
// SIGNAL SCORING
// ===========================================================================================================
// Tanh approximation
f_tanh(x) =>
ex = math.exp(2 * x)
(ex - 1) / (ex + 1)
f_scoreSignal(amf_score, alma_score, sr_score, swing_score, regime_score) =>
hidden1 = f_tanh(h1_amf_weight*amf_score + h1_alma_weight*alma_score + h1_sr_weight*sr_score + h1_swing_weight*swing_score + h1_regime_weight*regime_score + h1_bias)
hidden2 = f_tanh(h2_amf_weight*amf_score + h2_alma_weight*alma_score + h2_sr_weight*sr_score + h2_swing_weight*swing_score + h2_regime_weight*regime_score + h2_bias)
hidden3 = f_tanh(h3_amf_weight*amf_score + h3_alma_weight*alma_score + h3_sr_weight*sr_score + h3_swing_weight*swing_score + h3_regime_weight*regime_score + h3_bias)
raw_output = out_h1_weight*hidden1 + out_h2_weight*hidden2 + out_h3_weight*hidden3 + out_bias
1.0 / (1.0 + math.exp(-raw_output))
f_scoreSignalNormalized(amf_norm, alma_norm, sr_norm, swing_norm, regime_norm) =>
input_scale = 0.8
scaled_amf = amf_norm * input_scale
scaled_alma = alma_norm * input_scale
scaled_sr = sr_norm * input_scale
scaled_swing = swing_norm * input_scale
scaled_regime = regime_norm * input_scale
hidden1 = f_tanh(h1_amf_weight*scaled_amf + h1_alma_weight*scaled_alma +
h1_sr_weight*scaled_sr + h1_swing_weight*scaled_swing + h1_regime_weight*scaled_regime + h1_bias)
hidden2 = f_tanh(h2_amf_weight*scaled_amf + h2_alma_weight*scaled_alma +
h2_sr_weight*scaled_sr + h2_swing_weight*scaled_swing + h2_regime_weight*scaled_regime + h2_bias)
hidden3 = f_tanh(h3_amf_weight*scaled_amf + h3_alma_weight*scaled_alma +
h3_sr_weight*scaled_sr + h3_swing_weight*scaled_swing + h3_regime_weight*scaled_regime + h3_bias)
raw_output = out_h1_weight*hidden1 + out_h2_weight*hidden2 + out_h3_weight*hidden3 + out_bias
temperature = 1.2
1.0 / (1.0 + math.exp(-raw_output / temperature))
f_getSignalGrade(score) =>
if score >= 0.80
">80"
else if score >= 0.76
"76"
else if score >= 0.65
"65"
else if score >= 0.40
"40"
else if score >= 0.32
"32"
else
"<32" // (< 0.32)
f_getScoreColor(score) =>
var color result_color = color.maroon
if score >= 0.76
result_color := customBuyColor
else if score >= 0.65
result_color := color.new(customBuyColor, 20)
else if score >= 0.40
result_color := color.new(#00FFFF, 30)
else if score >= 0.32
result_color := color.new(#FFB000, 0)
else
result_color := customSellColor
result_color
// AMF Analysis Functions
f_analyzeAMF(amf_line, signal_line, is_buy, is_sell, cached_atr) =>
amf_vs_signal = amf_line - signal_line
crossing_up = amf_line > signal_line and amf_line[1] <= signal_line[1]
crossing_down = amf_line < signal_line and amf_line[1] >= signal_line[1]
normalized_distance = math.abs(amf_vs_signal) / cached_atr
is_far = normalized_distance > amf_far_threshold
signal_slope = (signal_line - signal_line[1]) / cached_atr
slope_fast_falling = signal_slope < -amf_slope_fast_threshold
slope_fast_rising = signal_slope > amf_slope_fast_threshold
var float amf_score = 0.0
if is_buy
if crossing_up or amf_line > signal_line
amf_score := 1.0
else if amf_line < signal_line
if is_far
amf_score := -0.8
else
amf_score := -0.4
else
amf_score := 0.0
if slope_fast_falling
amf_score := amf_score - 0.3
else if is_sell
if crossing_down or amf_line < signal_line
amf_score := 1.0
else if amf_line > signal_line
if is_far
amf_score := -0.8
else
amf_score := -0.4
else
amf_score := 0.0
if slope_fast_rising
amf_score := amf_score - 0.3
else
amf_score := 0.0
math.max(-1.0, math.min(1.0, amf_score))
f_analyzeALMA(fast_alma, slow_alma, is_buy, is_sell, cached_atr) =>
alma_gap = fast_alma - slow_alma
normalized_gap = math.abs(alma_gap) / cached_atr
is_wide_gap = normalized_gap > alma_wide_gap_threshold
crossing_up = fast_alma > slow_alma and fast_alma[1] <= slow_alma[1]
crossing_down = fast_alma < slow_alma and fast_alma[1] >= slow_alma[1]
var float alma_score = 0.0
if is_buy
if crossing_up or fast_alma > slow_alma
alma_score := 0.5
else if fast_alma < slow_alma
if is_wide_gap
alma_score := -0.8
else
alma_score := -0.2
else
alma_score := 0.0
else if is_sell
if crossing_down or fast_alma < slow_alma
alma_score := 0.5
else if fast_alma > slow_alma
if is_wide_gap
alma_score := -0.8
else
alma_score := -0.2
else
alma_score := 0.0
else
alma_score := 0.0
alma_score
f_analyzeSupportResistance(is_buy, is_sell, cached_atr, sig_high, sig_low, sig_close) =>
pivot_high = ta.pivothigh(sig_high, pivot_lookback, pivot_lookback)
pivot_low = ta.pivotlow(sig_low, pivot_lookback, pivot_lookback)
var float nearest_resistance = na
var float nearest_support = na
if not na(pivot_high)
nearest_resistance := pivot_high
if not na(pivot_low)
nearest_support := pivot_low
resistance_distance = nearest_resistance > 0 ? math.abs(sig_close - nearest_resistance) / cached_atr : 999
support_distance = nearest_support > 0 ? math.abs(sig_close - nearest_support) / cached_atr : 999
near_resistance = resistance_distance <= sr_proximity_threshold
near_support = support_distance <= sr_proximity_threshold
recent_resistance_break = nearest_resistance > 0 and sig_close > nearest_resistance and sig_close[5] <= nearest_resistance
recent_support_break = nearest_support > 0 and sig_close < nearest_support and sig_close[5] >= nearest_support
var float sr_score = 0.0
if is_buy
if recent_resistance_break
sr_score := 0.8
else if near_support
sr_score := 0.5
else if near_resistance
sr_score := -0.6
else
sr_score := 0.0
else if is_sell
if recent_support_break
sr_score := 0.8
else if near_resistance
sr_score := 0.5
else if near_support
sr_score := -0.6
else
sr_score := 0.0
else
sr_score := 0.0
sr_score
f_analyzeSwingStructure(is_buy, is_sell, sig_high, sig_low) =>
recent_high = ta.highest(sig_high, swing_structure_length)
recent_low = ta.lowest(sig_low, swing_structure_length)
previous_high = ta.highest(sig_high[swing_structure_length], swing_structure_length)
previous_low = ta.lowest(sig_low[swing_structure_length], swing_structure_length)
making_higher_highs = recent_high > previous_high
making_higher_lows = recent_low > previous_low
making_lower_highs = recent_high < previous_high
making_lower_lows = recent_low < previous_low
bullish_structure = making_higher_highs and making_higher_lows
bearish_structure = making_lower_highs and making_lower_lows
mixed_structure = not bullish_structure and not bearish_structure
var float swing_score = 0.0
if is_buy
if bullish_structure
swing_score := 0.6
else if bearish_structure
swing_score := -0.7
else
swing_score := -0.1
else if is_sell
if bearish_structure
swing_score := 0.6
else if bullish_structure
swing_score := -0.7
else
swing_score := -0.1
else
swing_score := 0.0
swing_score
f_analyzeMarketRegime(is_buy, is_sell, sig_open, sig_high, sig_low, sig_close) =>
tr1 = math.max(sig_high - sig_low, math.abs(sig_high - sig_close[1]))
tr = math.max(tr1, math.abs(sig_low - sig_close[1]))
plus_dm = sig_high - sig_high[1] > sig_low[1] - sig_low ? math.max(sig_high - sig_high[1], 0) : 0
minus_dm = sig_low[1] - sig_low > sig_high - sig_high[1] ? math.max(sig_low[1] - sig_low, 0) : 0
plus_di = 100 * ta.rma(plus_dm, regime_lookback) / ta.rma(tr, regime_lookback)
minus_di = 100 * ta.rma(minus_dm, regime_lookback) / ta.rma(tr, regime_lookback)
dx = math.abs(plus_di - minus_di) / (plus_di + minus_di) * 100
adx = ta.rma(dx, regime_lookback)
trending_market = adx >= trending_threshold * 100
ranging_market = not trending_market
bullish_trend = trending_market and plus_di > minus_di
bearish_trend = trending_market and minus_di > plus_di
var float regime_score = 0.0
if is_buy
if bullish_trend
regime_score := 0.7
else if bearish_trend
regime_score := -0.8
else
regime_score := -0.2
else if is_sell
if bearish_trend
regime_score := 0.7
else if bullish_trend
regime_score := -0.8
else
regime_score := -0.2
else
regime_score := 0.0
regime_score
// ===========================================================================================================
// CANDLE TYPE CALCULATIONS
// ===========================================================================================================
// Heikin Ashi
calculateHA111() =>
var haOpen = 0.0
var haHigh = 0.0
var haLow = 0.0
var haClose = 0.0
newHaClose = (open + high + low + close) / 4
newHaOpen = na(haOpen[1]) ? (open + close) / 2 : (haOpen[1] + haClose[1]) / 2
newHaHigh = math.max(high, math.max(newHaOpen, newHaClose))
newHaLow = math.min(low, math.min(newHaOpen, newHaClose))
haClose := newHaClose
haOpen := newHaOpen
haHigh := newHaHigh
haLow := newHaLow
[newHaOpen, newHaHigh, newHaLow, newHaClose]
[oHA, hHA, lHA, cHA] = calculateHA111()
var float displayOpen = na
var float displayHigh = na
var float displayLow = na
var float displayClose = na
if candleType == 'Candlesticks'
displayOpen := open
displayHigh := high
displayLow := low
displayClose := close
else if candleType == 'Heikin Ashi'
displayOpen := oHA
displayHigh := hHA
displayLow := lHA
displayClose := cHA
else if candleType == 'Linear Regression'
displayOpen := ta.linreg(open, lrcLength1, 0)
displayHigh := ta.linreg(high, lrcLength1, 0)
displayLow := ta.linreg(low, lrcLength1, 0)
displayClose := ta.linreg(close, lrcLength1, 0)
// Determine coloring
isBullishCandle = displayClose > displayOpen
isBearishCandle = displayClose < displayOpen
// ===========================================================================================================
// SIGNAL DATA SOURCE SELECTION
// ===========================================================================================================
var float signalOpenCalc = na
var float signalHighCalc = na
var float signalLowCalc = na
var float signalCloseCalc = na
if signalCandleType == 'Candlesticks'
signalOpenCalc := open
signalHighCalc := high
signalLowCalc := low
signalCloseCalc := close
else if signalCandleType == 'Heikin Ashi'
signalOpenCalc := oHA
signalHighCalc := hHA
signalLowCalc := lHA
signalCloseCalc := cHA
else if signalCandleType == 'Linear Regression'
signalOpenCalc := ta.linreg(open, lrcLength1, 0)
signalHighCalc := ta.linreg(high, lrcLength1, 0)
signalLowCalc := ta.linreg(low, lrcLength1, 0)
signalCloseCalc := ta.linreg(close, lrcLength1, 0)
signalOpen := signalOpenCalc
signalHigh := signalHighCalc
signalLow := signalLowCalc
signalClose := signalCloseCalc
// ===========================================================================================================
// SCALP HELPER SIGNAL SYSTEM
// ===========================================================================================================
buy_signal_buySignal = false
sell_signal_sellSignal = false
buy_atr_sellSignal = false
sell_atr_buySignal = false
buy_atr_longStop = close
sell_atr_shortStop = close
var bool buy_atr_stop_active = false
var bool sell_atr_stop_active = false
if enable_scalp_helper
// ============================================================================
// BUY SIGNAL
// ============================================================================
buy_signal_atr = ta.atr(buy_signal_length) * signal_trigger_mult
buy_signal_longStop = (buy_signal_use_close ? ta.highest(signalClose, buy_signal_length) : ta.highest(signalHigh, buy_signal_length)) - buy_signal_atr
buy_signal_longStopPrev = nz(buy_signal_longStop[1], buy_signal_longStop)
buy_signal_longStop := signalClose[1] > buy_signal_longStopPrev ? math.max(buy_signal_longStop, buy_signal_longStopPrev) : buy_signal_longStop
buy_signal_shortStop = (buy_signal_use_close ? ta.lowest(signalClose, buy_signal_length) : ta.lowest(signalLow, buy_signal_length)) + buy_signal_atr
buy_signal_shortStopPrev = nz(buy_signal_shortStop[1], buy_signal_shortStop)
buy_signal_shortStop := signalClose[1] < buy_signal_shortStopPrev ? math.min(buy_signal_shortStop, buy_signal_shortStopPrev) : buy_signal_shortStop
var int buy_signal_dir = 1
buy_signal_dir := signalClose > buy_signal_shortStopPrev ? 1 : signalClose < buy_signal_longStopPrev ? -1 : buy_signal_dir
buy_signal_buySignal := buy_signal_dir == 1 and buy_signal_dir[1] == -1
// ============================================================================
// BUY ATR STOP
// ============================================================================
buy_atr_atr = ta.atr(buy_atr_length) * stop_atr_mult
buy_atr_longStop := (buy_atr_use_close ? ta.highest(signalClose, buy_atr_length) : ta.highest(signalHigh, buy_atr_length)) - buy_atr_atr
buy_atr_longStopPrev = nz(buy_atr_longStop[1], buy_atr_longStop)
buy_atr_longStop := signalClose[1] > buy_atr_longStopPrev ? math.max(buy_atr_longStop, buy_atr_longStopPrev) : buy_atr_longStop
buy_atr_shortStop = (buy_atr_use_close ? ta.lowest(signalClose, buy_atr_length) : ta.lowest(signalLow, buy_atr_length)) + buy_atr_atr
buy_atr_shortStopPrev = nz(buy_atr_shortStop[1], buy_atr_shortStop)
buy_atr_shortStop := signalClose[1] < buy_atr_shortStopPrev ? math.min(buy_atr_shortStop, buy_atr_shortStopPrev) : buy_atr_shortStop
var int buy_atr_dir = 1
buy_atr_dir := signalClose > buy_atr_shortStopPrev ? 1 : signalClose < buy_atr_longStopPrev ? -1 : buy_atr_dir
buy_atr_sellSignal := buy_atr_dir == -1 and buy_atr_dir[1] == 1
// ============================================================================
// SELL SIGNAL
// ============================================================================
sell_signal_atr = ta.atr(sell_signal_length) * signal_trigger_mult
sell_signal_longStop = (sell_signal_use_close ? ta.highest(signalClose, sell_signal_length) : ta.highest(signalHigh, sell_signal_length)) - sell_signal_atr
sell_signal_longStopPrev = nz(sell_signal_longStop[1], sell_signal_longStop)
sell_signal_longStop := signalClose[1] > sell_signal_longStopPrev ? math.max(sell_signal_longStop, sell_signal_longStopPrev) : sell_signal_longStop
sell_signal_shortStop = (sell_signal_use_close ? ta.lowest(signalClose, sell_signal_length) : ta.lowest(signalLow, sell_signal_length)) + sell_signal_atr
sell_signal_shortStopPrev = nz(sell_signal_shortStop[1], sell_signal_shortStop)
sell_signal_shortStop := signalClose[1] < sell_signal_shortStopPrev ? math.min(sell_signal_shortStop, sell_signal_shortStopPrev) : sell_signal_shortStop
var int sell_signal_dir = 1
sell_signal_dir := signalClose > sell_signal_shortStopPrev ? 1 : signalClose < sell_signal_longStopPrev ? -1 : sell_signal_dir
sell_signal_sellSignal := sell_signal_dir == -1 and sell_signal_dir[1] == 1
// ============================================================================
// SELL ATR STOP
// ============================================================================
sell_atr_atr = ta.atr(sell_atr_length) * stop_atr_mult
sell_atr_longStop = (sell_atr_use_close ? ta.highest(signalClose, sell_atr_length) : ta.highest(signalHigh, sell_atr_length)) - sell_atr_atr
sell_atr_longStopPrev = nz(sell_atr_longStop[1], sell_atr_longStop)
sell_atr_longStop := signalClose[1] > sell_atr_longStopPrev ? math.max(sell_atr_longStop, sell_atr_longStopPrev) : sell_atr_longStop
sell_atr_shortStop := (sell_atr_use_close ? ta.lowest(signalClose, sell_atr_length) : ta.lowest(signalLow, sell_atr_length)) + sell_atr_atr
sell_atr_shortStopPrev = nz(sell_atr_shortStop[1], sell_atr_shortStop)
sell_atr_shortStop := signalClose[1] < sell_atr_shortStopPrev ? math.min(sell_atr_shortStop, sell_atr_shortStopPrev) : sell_atr_shortStop
var int sell_atr_dir = 1
sell_atr_dir := signalClose > sell_atr_shortStopPrev ? 1 : signalClose < sell_atr_longStopPrev ? -1 : sell_atr_dir
sell_atr_buySignal := sell_atr_dir == 1 and sell_atr_dir[1] == -1
// ============================================================================
// SIGNAL STATE MANAGEMENT
// ============================================================================
if not buy_atr_stop_active
if buy_signal_buySignal
buy_atr_stop_active := true
else
if buy_atr_sellSignal
buy_atr_stop_active := false
if not sell_atr_stop_active
if sell_signal_sellSignal
sell_atr_stop_active := true
else
if sell_atr_buySignal
sell_atr_stop_active := false
// ===========================================================================================================
// CORE CALCULATIONS
// ===========================================================================================================
// AMF Calculations
amf_line = f_calculate_amf(signalClose, amf_length, amf_fast_length, amf_slow_length, amf_smoothing)
amf_signal = f_amf_signal(amf_line, amf_signal_length)
// Cached ATR
atr14 = ta.atr(14)
// ALMA calculations for neural network (Use Signal Candles for analysis)
alma200 = ta.alma(signalClose, almaLength, almaOffset, almaSigma)
alma2 = ta.alma(signalClose, alma2Length, alma2Offset, alma2Sigma)
// ===========================================================================================================
// NEURAL NETWORK
// ===========================================================================================================
is_buy_signal = buy_signal_buySignal
is_sell_signal = sell_signal_sellSignal
amf_context = f_analyzeAMF(amf_line, amf_signal, is_buy_signal, is_sell_signal, atr14)
alma_context = f_analyzeALMA(alma200, alma2, is_buy_signal, is_sell_signal, atr14)
sr_context = f_analyzeSupportResistance(is_buy_signal, is_sell_signal, atr14, signalHigh, signalLow, signalClose)
swing_context = f_analyzeSwingStructure(is_buy_signal, is_sell_signal, signalHigh, signalLow)
regime_context = f_analyzeMarketRegime(is_buy_signal, is_sell_signal, signalOpen, signalHigh, signalLow, signalClose)
amf_context_normalized = f_normalizeInput(amf_context, normalization_lookback, outlier_clipping, clipping_threshold)
alma_context_normalized = f_normalizeInput(alma_context, normalization_lookback, outlier_clipping, clipping_threshold)
sr_context_normalized = f_normalizeInput(sr_context, normalization_lookback, outlier_clipping, clipping_threshold)
swing_context_normalized = f_normalizeInput(swing_context, normalization_lookback, outlier_clipping, clipping_threshold)
regime_context_normalized = f_normalizeInput(regime_context, normalization_lookback, outlier_clipping, clipping_threshold)
signal_score = (is_buy_signal or is_sell_signal) ?
f_scoreSignalNormalized(amf_context_normalized, alma_context_normalized,
sr_context_normalized, swing_context_normalized, regime_context_normalized) : 0.5
signal_grade = f_getSignalGrade(signal_score)
score_color = f_getScoreColor(signal_score)
// ===========================================================================================================
// CANDLE PLOTTING
// ===========================================================================================================
candleColor = isBullishCandle ? customBuyColor : customSellColor
plotcandle(candleType != 'Candlesticks' ? displayOpen : na,
candleType != 'Candlesticks' ? displayHigh : na,
candleType != 'Candlesticks' ? displayLow : na,
candleType != 'Candlesticks' ? displayClose : na,
title = 'BAR',
color = candleType != 'Candlesticks' ? candleColor : na,
wickcolor = candleType != 'Candlesticks' ? candleColor : na,
bordercolor = candleType != 'Candlesticks' ? candleColor : na)
// ===========================================================================================================
// SCALP HELPER SIGNAL PLOTS
// ===========================================================================================================
atr_offset = signalOffset * atr14
show_buy_signal = enable_scalp_helper and buy_signal_buySignal and not buy_atr_stop_active[1]
show_sell_signal = enable_scalp_helper and sell_signal_sellSignal and not sell_atr_stop_active[1]
label_size = signalLabelSize == 'tiny' ? size.tiny :
signalLabelSize == 'small' ? size.small :
signalLabelSize == 'large' ? size.large : size.normal
if showScalpLabels and show_buy_signal
buy_label_text = signal_grade
label.new(bar_index, signalLow - atr_offset,
text = buy_label_text,
style = label.style_label_up,
size = label_size,
color = score_color,
textcolor = color.black)
if showScalpLabels and show_sell_signal
sell_label_text = signal_grade
label.new(bar_index, signalHigh + atr_offset,
text = sell_label_text,
style = label.style_label_down,
size = label_size,
color = score_color,
textcolor = color.black)
//////////////////////////////////asla silme renklendirme yapıyor///////////////////////////////////
https://www.tradingview.com/x/6F852ZIa/
16.07.2024 - 10.12.2024 https://chatgpt.com/g/g-uib6qYHGw-tr...ipt-v5-creator
Her ne kadar kodunu anlamasam da eline sağlık hocam
“Başarısızlık yeniden ve daha zekice başlayabilme fırsatından başka bir şey değildir.” Henry Ford
üsteki heikin ashi...ye ....ilave...
10 atr ve eliot....
https://www.tradingview.com/x/fbbXZ8mm/
denemek isteyene kod....
PHP Code:
//@version=6
indicator('Neural Network Buy and Sell Signals', shorttitle = '.', overlay = true, max_lines_count = 100, max_labels_count=100, max_boxes_count = 100, max_bars_back = 100)
var string scalpHelperGroup = 'Scalp Helper Signal Settings'
enable_scalp_helper = input.bool(true, 'Enable Scalp Helper Signals', group = scalpHelperGroup)
signalCandleType = input.string('Heikin Ashi', 'Signal Candle Type', options = ['Candlesticks', 'Heikin Ashi', 'Linear Regression'], group = scalpHelperGroup, tooltip = 'Choose which candle type to use for signal calculations. This will not change what candlestick type is displayed.')
signal_trigger_mult = input.float(0.1, 'Signal Trigger Sensitivity', minval = 0.1, maxval = 10.0, step = 0.1, group = scalpHelperGroup, tooltip = 'Controls both buy and sell signal sensitivity. Lower values = more sensitive signals, higher values = less sensitive signals.')
stop_atr_mult = input.float(1.5, 'Stop Loss ATR Multiplier', minval = 0.1, maxval = 10.0, step = 0.1, group = scalpHelperGroup, tooltip = 'Once a signal is triggered this stop will be initiated to tell how long the signal is valid. Higher values = wider stops and less signals, lower values = tighter stops and more signals.')
var string candleGroup = 'Candlestick Settings'
candleType = input.string('Heikin Ashi', 'Candle Type', options = ['Candlesticks', 'Heikin Ashi', 'Linear Regression'], group = candleGroup, tooltip = 'Choose the type of candles to display. This does not impact signal calculations.')
lrcLength1 = input.int(100, 'Linear Regression Length', minval = 1, group = candleGroup, tooltip = 'Length for Linear Regression calculations. Lower values are more responsive but noisier.')
var string visualGroup = 'Display Settings'
signalOffset = input.float(5, 'Signal Distance from Candles', minval = 0.1, maxval = 5.0, step = 0.1, group = visualGroup, tooltip = 'Distance of buy/sell labels from candles (ATR multiplier)')
signalLabelSize = input.string('medium', 'Signal Label Size', options = ['tiny', 'small', 'medium', 'large'], group = visualGroup, tooltip = 'Size of the neural network signal labels')
buy_signal_length = 2
buy_atr_length = 18
sell_signal_length = 2
sell_atr_length = 18
buy_signal_use_close = false
buy_atr_use_close = true
sell_signal_use_close = false
sell_atr_use_close = true
amf_length = 14
amf_signal_length = 9
amf_smoothing = 3
amf_fast_length = 5
amf_slow_length = 21
amf_far_threshold = 0.3
amf_slope_fast_threshold = 0.03
h1_amf_weight = 1.2
h1_alma_weight = 0.4
h1_sr_weight = 0.5
h1_swing_weight = 0.4
h1_regime_weight = 0.7
h1_bias = 0.2
h2_amf_weight = 1.4
h2_alma_weight = 0.3
h2_sr_weight = 0.6
h2_swing_weight = 0.3
h2_regime_weight = 0.8
h2_bias = 0.15
h3_amf_weight = 1.6
h3_alma_weight = 0.4
h3_sr_weight = 0.4
h3_swing_weight = 0.5
h3_regime_weight = 0.6
h3_bias = 0.25
out_h1_weight = 0.4
out_h2_weight = 0.4
out_h3_weight = 0.4
out_bias = 0.3
enable_input_normalization = true
normalization_lookback = 50
outlier_clipping = true
clipping_threshold = 3.0
almaLength = 20
almaOffset = 0.85
almaSigma = 6.0
alma2Length = 20
alma2Offset = 0.77
alma2Sigma = 6.0
alma_wide_gap_threshold = 0.1
pivot_lookback = 10
sr_proximity_threshold = 0.5
sr_breakout_threshold = 0.2
swing_structure_length = 20
regime_lookback = 30
trending_threshold = 0.6
showScalpLabels = true
var float signalOpen = open
var float signalHigh = high
var float signalLow = low
var float signalClose = close
customBuyColor = color.new(#00FFFF, 0)
customSellColor = color.new(#FF0000, 0)
scalpLongColor = color.new(#00B3B3, 0)
scalpShortColor = color.new(#FF0000, 0)
textColor = color.new(color.white, 0)
f_ema_amf(source, len) =>
float alpha = 2.0 / (len + 1)
var float ema_val = na
if not na(source) and len > 0
ema_val := alpha * source + (1 - alpha) * nz(ema_val[1])
ema_val
f_dema_amf(source, len) =>
float ema1 = f_ema_amf(source, len)
float ema2 = f_ema_amf(ema1, len)
float dema_val = 2 * ema1 - ema2
dema_val
f_zlema_amf(source, len) =>
int lag = int((len - 1) / 2)
float lag_source = lag > 0 ? source[lag] : source
float adjusted_source = source + (source - lag_source)
float zlema_val = f_ema_amf(adjusted_source, len)
zlema_val
f_sum_amf(source, len) =>
float sum_val = 0.0
for i = 0 to len - 1
sum_val += nz(source[i], 0)
sum_val
f_calculate_amf(src, length, fast_len, slow_len, smooth_len) =>
float current_atr = ta.atr(14)
float avg_atr = ta.sma(current_atr, 50)
float volatility_ratio = avg_atr > 0 ? current_atr / avg_atr : 1.0
float volatility_sensitivity = 2.0
float raw_adaptive_lookback = float(length) / math.pow(volatility_ratio, volatility_sensitivity)
int adaptive_lookback = int(math.max(5, math.min(50, raw_adaptive_lookback)))
if adaptive_lookback < 1
adaptive_lookback := 1
int zlema_fast_len = adaptive_lookback
int dema_medium_len = int(adaptive_lookback * 1.5)
int dema_slow_len = int(adaptive_lookback * 2.5)
if dema_medium_len < 1
dema_medium_len := 1
if dema_slow_len < 1
dema_slow_len := 1
float zlema_fast = f_zlema_amf(src, zlema_fast_len)
float dema_medium = f_dema_amf(src, dema_medium_len)
float dema_slow = f_dema_amf(src, dema_slow_len)
float pv = 0.0
if src > src[1]
pv := volume
else if src < src[1]
pv := -volume
float vzo_sum = f_sum_amf(pv, length)
float vol_sum = f_sum_amf(volume, length)
float vzo_value = vol_sum != 0 ? 100 * (vzo_sum / vol_sum) : 0.0
float smoothed_vzo = ta.sma(vzo_value, 3)
float price_vs_fast_weight = 30.0
float fast_vs_medium_weight = 30.0
float medium_vs_slow_weight = 40.0
float vzo_weight = 20.0
float oscillator_score = 0.0
if src > zlema_fast
oscillator_score += price_vs_fast_weight
else if src < zlema_fast
oscillator_score -= price_vs_fast_weight
if zlema_fast > dema_medium
oscillator_score += fast_vs_medium_weight
else if zlema_fast < dema_medium
oscillator_score -= fast_vs_medium_weight
if dema_medium > dema_slow
oscillator_score += medium_vs_slow_weight
else if dema_medium < dema_slow
oscillator_score -= medium_vs_slow_weight
oscillator_score += (smoothed_vzo / 100) * vzo_weight
float max_possible_score = price_vs_fast_weight + fast_vs_medium_weight + medium_vs_slow_weight + vzo_weight
float normalized_score = max_possible_score != 0.0 ? (oscillator_score / max_possible_score) * 100.0 : 0.0
float final_amf = ta.ema(normalized_score / 100.0, smooth_len)
final_amf
f_amf_signal(amf_line, signal_length) =>
ta.ema(amf_line, signal_length)
// ===========================================================================================================
// CACHED CALCULATIONS
// ===========================================================================================================
cached_atr = ta.atr(14)
// ===========================================================================================================
// NORMALIZATION FUNCTIONS
// ===========================================================================================================
f_normalizeInput(value, lookback_period, enable_clipping, clip_threshold) =>
if not enable_input_normalization
value
else
mean_val = ta.sma(value, lookback_period)
variance = ta.sma(math.pow(value - mean_val, 2), lookback_period)
std_val = math.sqrt(variance)
normalized = std_val > 0 ? (value - mean_val) / std_val : 0.0
if enable_clipping
math.max(-clip_threshold, math.min(clip_threshold, normalized))
else
normalized
f_robustNormalize(value, lookback_period) =>
if not enable_input_normalization
value
else
ema_val = ta.ema(value, lookback_period)
abs_dev = math.abs(value - ema_val)
mad_approx = ta.ema(abs_dev, lookback_period) * 1.4826
mad_approx > 0 ? (value - ema_val) / mad_approx : 0.0
// ===========================================================================================================
// SIGNAL SCORING
// ===========================================================================================================
// Tanh approximation
f_tanh(x) =>
ex = math.exp(2 * x)
(ex - 1) / (ex + 1)
f_scoreSignal(amf_score, alma_score, sr_score, swing_score, regime_score) =>
hidden1 = f_tanh(h1_amf_weight*amf_score + h1_alma_weight*alma_score + h1_sr_weight*sr_score + h1_swing_weight*swing_score + h1_regime_weight*regime_score + h1_bias)
hidden2 = f_tanh(h2_amf_weight*amf_score + h2_alma_weight*alma_score + h2_sr_weight*sr_score + h2_swing_weight*swing_score + h2_regime_weight*regime_score + h2_bias)
hidden3 = f_tanh(h3_amf_weight*amf_score + h3_alma_weight*alma_score + h3_sr_weight*sr_score + h3_swing_weight*swing_score + h3_regime_weight*regime_score + h3_bias)
raw_output = out_h1_weight*hidden1 + out_h2_weight*hidden2 + out_h3_weight*hidden3 + out_bias
1.0 / (1.0 + math.exp(-raw_output))
f_scoreSignalNormalized(amf_norm, alma_norm, sr_norm, swing_norm, regime_norm) =>
input_scale = 0.8
scaled_amf = amf_norm * input_scale
scaled_alma = alma_norm * input_scale
scaled_sr = sr_norm * input_scale
scaled_swing = swing_norm * input_scale
scaled_regime = regime_norm * input_scale
hidden1 = f_tanh(h1_amf_weight*scaled_amf + h1_alma_weight*scaled_alma +
h1_sr_weight*scaled_sr + h1_swing_weight*scaled_swing + h1_regime_weight*scaled_regime + h1_bias)
hidden2 = f_tanh(h2_amf_weight*scaled_amf + h2_alma_weight*scaled_alma +
h2_sr_weight*scaled_sr + h2_swing_weight*scaled_swing + h2_regime_weight*scaled_regime + h2_bias)
hidden3 = f_tanh(h3_amf_weight*scaled_amf + h3_alma_weight*scaled_alma +
h3_sr_weight*scaled_sr + h3_swing_weight*scaled_swing + h3_regime_weight*scaled_regime + h3_bias)
raw_output = out_h1_weight*hidden1 + out_h2_weight*hidden2 + out_h3_weight*hidden3 + out_bias
temperature = 1.2
1.0 / (1.0 + math.exp(-raw_output / temperature))
f_getSignalGrade(score) =>
if score >= 0.80
">80"
else if score >= 0.76
"76"
else if score >= 0.65
"65"
else if score >= 0.40
"40"
else if score >= 0.32
"32"
else
"<32" // (< 0.32)
f_getScoreColor(score) =>
var color result_color = color.maroon
if score >= 0.76
result_color := customBuyColor
else if score >= 0.65
result_color := color.new(customBuyColor, 20)
else if score >= 0.40
result_color := color.new(#00FFFF, 30)
else if score >= 0.32
result_color := color.new(#FFB000, 0)
else
result_color := customSellColor
result_color
// AMF Analysis Functions
f_analyzeAMF(amf_line, signal_line, is_buy, is_sell, cached_atr) =>
amf_vs_signal = amf_line - signal_line
crossing_up = amf_line > signal_line and amf_line[1] <= signal_line[1]
crossing_down = amf_line < signal_line and amf_line[1] >= signal_line[1]
normalized_distance = math.abs(amf_vs_signal) / cached_atr
is_far = normalized_distance > amf_far_threshold
signal_slope = (signal_line - signal_line[1]) / cached_atr
slope_fast_falling = signal_slope < -amf_slope_fast_threshold
slope_fast_rising = signal_slope > amf_slope_fast_threshold
var float amf_score = 0.0
if is_buy
if crossing_up or amf_line > signal_line
amf_score := 1.0
else if amf_line < signal_line
if is_far
amf_score := -0.8
else
amf_score := -0.4
else
amf_score := 0.0
if slope_fast_falling
amf_score := amf_score - 0.3
else if is_sell
if crossing_down or amf_line < signal_line
amf_score := 1.0
else if amf_line > signal_line
if is_far
amf_score := -0.8
else
amf_score := -0.4
else
amf_score := 0.0
if slope_fast_rising
amf_score := amf_score - 0.3
else
amf_score := 0.0
math.max(-1.0, math.min(1.0, amf_score))
f_analyzeALMA(fast_alma, slow_alma, is_buy, is_sell, cached_atr) =>
alma_gap = fast_alma - slow_alma
normalized_gap = math.abs(alma_gap) / cached_atr
is_wide_gap = normalized_gap > alma_wide_gap_threshold
crossing_up = fast_alma > slow_alma and fast_alma[1] <= slow_alma[1]
crossing_down = fast_alma < slow_alma and fast_alma[1] >= slow_alma[1]
var float alma_score = 0.0
if is_buy
if crossing_up or fast_alma > slow_alma
alma_score := 0.5
else if fast_alma < slow_alma
if is_wide_gap
alma_score := -0.8
else
alma_score := -0.2
else
alma_score := 0.0
else if is_sell
if crossing_down or fast_alma < slow_alma
alma_score := 0.5
else if fast_alma > slow_alma
if is_wide_gap
alma_score := -0.8
else
alma_score := -0.2
else
alma_score := 0.0
else
alma_score := 0.0
alma_score
f_analyzeSupportResistance(is_buy, is_sell, cached_atr, sig_high, sig_low, sig_close) =>
pivot_high = ta.pivothigh(sig_high, pivot_lookback, pivot_lookback)
pivot_low = ta.pivotlow(sig_low, pivot_lookback, pivot_lookback)
var float nearest_resistance = na
var float nearest_support = na
if not na(pivot_high)
nearest_resistance := pivot_high
if not na(pivot_low)
nearest_support := pivot_low
resistance_distance = nearest_resistance > 0 ? math.abs(sig_close - nearest_resistance) / cached_atr : 999
support_distance = nearest_support > 0 ? math.abs(sig_close - nearest_support) / cached_atr : 999
near_resistance = resistance_distance <= sr_proximity_threshold
near_support = support_distance <= sr_proximity_threshold
recent_resistance_break = nearest_resistance > 0 and sig_close > nearest_resistance and sig_close[5] <= nearest_resistance
recent_support_break = nearest_support > 0 and sig_close < nearest_support and sig_close[5] >= nearest_support
var float sr_score = 0.0
if is_buy
if recent_resistance_break
sr_score := 0.8
else if near_support
sr_score := 0.5
else if near_resistance
sr_score := -0.6
else
sr_score := 0.0
else if is_sell
if recent_support_break
sr_score := 0.8
else if near_resistance
sr_score := 0.5
else if near_support
sr_score := -0.6
else
sr_score := 0.0
else
sr_score := 0.0
sr_score
f_analyzeSwingStructure(is_buy, is_sell, sig_high, sig_low) =>
recent_high = ta.highest(sig_high, swing_structure_length)
recent_low = ta.lowest(sig_low, swing_structure_length)
previous_high = ta.highest(sig_high[swing_structure_length], swing_structure_length)
previous_low = ta.lowest(sig_low[swing_structure_length], swing_structure_length)
making_higher_highs = recent_high > previous_high
making_higher_lows = recent_low > previous_low
making_lower_highs = recent_high < previous_high
making_lower_lows = recent_low < previous_low
bullish_structure = making_higher_highs and making_higher_lows
bearish_structure = making_lower_highs and making_lower_lows
mixed_structure = not bullish_structure and not bearish_structure
var float swing_score = 0.0
if is_buy
if bullish_structure
swing_score := 0.6
else if bearish_structure
swing_score := -0.7
else
swing_score := -0.1
else if is_sell
if bearish_structure
swing_score := 0.6
else if bullish_structure
swing_score := -0.7
else
swing_score := -0.1
else
swing_score := 0.0
swing_score
f_analyzeMarketRegime(is_buy, is_sell, sig_open, sig_high, sig_low, sig_close) =>
tr1 = math.max(sig_high - sig_low, math.abs(sig_high - sig_close[1]))
tr = math.max(tr1, math.abs(sig_low - sig_close[1]))
plus_dm = sig_high - sig_high[1] > sig_low[1] - sig_low ? math.max(sig_high - sig_high[1], 0) : 0
minus_dm = sig_low[1] - sig_low > sig_high - sig_high[1] ? math.max(sig_low[1] - sig_low, 0) : 0
plus_di = 100 * ta.rma(plus_dm, regime_lookback) / ta.rma(tr, regime_lookback)
minus_di = 100 * ta.rma(minus_dm, regime_lookback) / ta.rma(tr, regime_lookback)
dx = math.abs(plus_di - minus_di) / (plus_di + minus_di) * 100
adx = ta.rma(dx, regime_lookback)
trending_market = adx >= trending_threshold * 100
ranging_market = not trending_market
bullish_trend = trending_market and plus_di > minus_di
bearish_trend = trending_market and minus_di > plus_di
var float regime_score = 0.0
if is_buy
if bullish_trend
regime_score := 0.7
else if bearish_trend
regime_score := -0.8
else
regime_score := -0.2
else if is_sell
if bearish_trend
regime_score := 0.7
else if bullish_trend
regime_score := -0.8
else
regime_score := -0.2
else
regime_score := 0.0
regime_score
// ===========================================================================================================
// CANDLE TYPE CALCULATIONS
// ===========================================================================================================
// Heikin Ashi
calculateHA111() =>
var haOpen = 0.0
var haHigh = 0.0
var haLow = 0.0
var haClose = 0.0
newHaClose = (open + high + low + close) / 4
newHaOpen = na(haOpen[1]) ? (open + close) / 2 : (haOpen[1] + haClose[1]) / 2
newHaHigh = math.max(high, math.max(newHaOpen, newHaClose))
newHaLow = math.min(low, math.min(newHaOpen, newHaClose))
haClose := newHaClose
haOpen := newHaOpen
haHigh := newHaHigh
haLow := newHaLow
[newHaOpen, newHaHigh, newHaLow, newHaClose]
[oHA, hHA, lHA, cHA] = calculateHA111()
var float displayOpen = na
var float displayHigh = na
var float displayLow = na
var float displayClose = na
if candleType == 'Candlesticks'
displayOpen := open
displayHigh := high
displayLow := low
displayClose := close
else if candleType == 'Heikin Ashi'
displayOpen := oHA
displayHigh := hHA
displayLow := lHA
displayClose := cHA
else if candleType == 'Linear Regression'
displayOpen := ta.linreg(open, lrcLength1, 0)
displayHigh := ta.linreg(high, lrcLength1, 0)
displayLow := ta.linreg(low, lrcLength1, 0)
displayClose := ta.linreg(close, lrcLength1, 0)
// Determine coloring
isBullishCandle = displayClose > displayOpen
isBearishCandle = displayClose < displayOpen
// ===========================================================================================================
// SIGNAL DATA SOURCE SELECTION
// ===========================================================================================================
var float signalOpenCalc = na
var float signalHighCalc = na
var float signalLowCalc = na
var float signalCloseCalc = na
if signalCandleType == 'Candlesticks'
signalOpenCalc := open
signalHighCalc := high
signalLowCalc := low
signalCloseCalc := close
else if signalCandleType == 'Heikin Ashi'
signalOpenCalc := oHA
signalHighCalc := hHA
signalLowCalc := lHA
signalCloseCalc := cHA
else if signalCandleType == 'Linear Regression'
signalOpenCalc := ta.linreg(open, lrcLength1, 0)
signalHighCalc := ta.linreg(high, lrcLength1, 0)
signalLowCalc := ta.linreg(low, lrcLength1, 0)
signalCloseCalc := ta.linreg(close, lrcLength1, 0)
signalOpen := signalOpenCalc
signalHigh := signalHighCalc
signalLow := signalLowCalc
signalClose := signalCloseCalc
// ===========================================================================================================
// SCALP HELPER SIGNAL SYSTEM
// ===========================================================================================================
buy_signal_buySignal = false
sell_signal_sellSignal = false
buy_atr_sellSignal = false
sell_atr_buySignal = false
buy_atr_longStop = close
sell_atr_shortStop = close
var bool buy_atr_stop_active = false
var bool sell_atr_stop_active = false
if enable_scalp_helper
// ============================================================================
// BUY SIGNAL
// ============================================================================
buy_signal_atr = ta.atr(buy_signal_length) * signal_trigger_mult
buy_signal_longStop = (buy_signal_use_close ? ta.highest(signalClose, buy_signal_length) : ta.highest(signalHigh, buy_signal_length)) - buy_signal_atr
buy_signal_longStopPrev = nz(buy_signal_longStop[1], buy_signal_longStop)
buy_signal_longStop := signalClose[1] > buy_signal_longStopPrev ? math.max(buy_signal_longStop, buy_signal_longStopPrev) : buy_signal_longStop
buy_signal_shortStop = (buy_signal_use_close ? ta.lowest(signalClose, buy_signal_length) : ta.lowest(signalLow, buy_signal_length)) + buy_signal_atr
buy_signal_shortStopPrev = nz(buy_signal_shortStop[1], buy_signal_shortStop)
buy_signal_shortStop := signalClose[1] < buy_signal_shortStopPrev ? math.min(buy_signal_shortStop, buy_signal_shortStopPrev) : buy_signal_shortStop
var int buy_signal_dir = 1
buy_signal_dir := signalClose > buy_signal_shortStopPrev ? 1 : signalClose < buy_signal_longStopPrev ? -1 : buy_signal_dir
buy_signal_buySignal := buy_signal_dir == 1 and buy_signal_dir[1] == -1
// ============================================================================
// BUY ATR STOP
// ============================================================================
buy_atr_atr = ta.atr(buy_atr_length) * stop_atr_mult
buy_atr_longStop := (buy_atr_use_close ? ta.highest(signalClose, buy_atr_length) : ta.highest(signalHigh, buy_atr_length)) - buy_atr_atr
buy_atr_longStopPrev = nz(buy_atr_longStop[1], buy_atr_longStop)
buy_atr_longStop := signalClose[1] > buy_atr_longStopPrev ? math.max(buy_atr_longStop, buy_atr_longStopPrev) : buy_atr_longStop
buy_atr_shortStop = (buy_atr_use_close ? ta.lowest(signalClose, buy_atr_length) : ta.lowest(signalLow, buy_atr_length)) + buy_atr_atr
buy_atr_shortStopPrev = nz(buy_atr_shortStop[1], buy_atr_shortStop)
buy_atr_shortStop := signalClose[1] < buy_atr_shortStopPrev ? math.min(buy_atr_shortStop, buy_atr_shortStopPrev) : buy_atr_shortStop
var int buy_atr_dir = 1
buy_atr_dir := signalClose > buy_atr_shortStopPrev ? 1 : signalClose < buy_atr_longStopPrev ? -1 : buy_atr_dir
buy_atr_sellSignal := buy_atr_dir == -1 and buy_atr_dir[1] == 1
// ============================================================================
// SELL SIGNAL
// ============================================================================
sell_signal_atr = ta.atr(sell_signal_length) * signal_trigger_mult
sell_signal_longStop = (sell_signal_use_close ? ta.highest(signalClose, sell_signal_length) : ta.highest(signalHigh, sell_signal_length)) - sell_signal_atr
sell_signal_longStopPrev = nz(sell_signal_longStop[1], sell_signal_longStop)
sell_signal_longStop := signalClose[1] > sell_signal_longStopPrev ? math.max(sell_signal_longStop, sell_signal_longStopPrev) : sell_signal_longStop
sell_signal_shortStop = (sell_signal_use_close ? ta.lowest(signalClose, sell_signal_length) : ta.lowest(signalLow, sell_signal_length)) + sell_signal_atr
sell_signal_shortStopPrev = nz(sell_signal_shortStop[1], sell_signal_shortStop)
sell_signal_shortStop := signalClose[1] < sell_signal_shortStopPrev ? math.min(sell_signal_shortStop, sell_signal_shortStopPrev) : sell_signal_shortStop
var int sell_signal_dir = 1
sell_signal_dir := signalClose > sell_signal_shortStopPrev ? 1 : signalClose < sell_signal_longStopPrev ? -1 : sell_signal_dir
sell_signal_sellSignal := sell_signal_dir == -1 and sell_signal_dir[1] == 1
// ============================================================================
// SELL ATR STOP
// ============================================================================
sell_atr_atr = ta.atr(sell_atr_length) * stop_atr_mult
sell_atr_longStop = (sell_atr_use_close ? ta.highest(signalClose, sell_atr_length) : ta.highest(signalHigh, sell_atr_length)) - sell_atr_atr
sell_atr_longStopPrev = nz(sell_atr_longStop[1], sell_atr_longStop)
sell_atr_longStop := signalClose[1] > sell_atr_longStopPrev ? math.max(sell_atr_longStop, sell_atr_longStopPrev) : sell_atr_longStop
sell_atr_shortStop := (sell_atr_use_close ? ta.lowest(signalClose, sell_atr_length) : ta.lowest(signalLow, sell_atr_length)) + sell_atr_atr
sell_atr_shortStopPrev = nz(sell_atr_shortStop[1], sell_atr_shortStop)
sell_atr_shortStop := signalClose[1] < sell_atr_shortStopPrev ? math.min(sell_atr_shortStop, sell_atr_shortStopPrev) : sell_atr_shortStop
var int sell_atr_dir = 1
sell_atr_dir := signalClose > sell_atr_shortStopPrev ? 1 : signalClose < sell_atr_longStopPrev ? -1 : sell_atr_dir
sell_atr_buySignal := sell_atr_dir == 1 and sell_atr_dir[1] == -1
// ============================================================================
// SIGNAL STATE MANAGEMENT
// ============================================================================
if not buy_atr_stop_active
if buy_signal_buySignal
buy_atr_stop_active := true
else
if buy_atr_sellSignal
buy_atr_stop_active := false
if not sell_atr_stop_active
if sell_signal_sellSignal
sell_atr_stop_active := true
else
if sell_atr_buySignal
sell_atr_stop_active := false
// ===========================================================================================================
// CORE CALCULATIONS
// ===========================================================================================================
// AMF Calculations
amf_line = f_calculate_amf(signalClose, amf_length, amf_fast_length, amf_slow_length, amf_smoothing)
amf_signal = f_amf_signal(amf_line, amf_signal_length)
// Cached ATR
atr14 = ta.atr(14)
// ALMA calculations for neural network (Use Signal Candles for analysis)
alma200 = ta.alma(signalClose, almaLength, almaOffset, almaSigma)
alma2 = ta.alma(signalClose, alma2Length, alma2Offset, alma2Sigma)
// ===========================================================================================================
// NEURAL NETWORK
// ===========================================================================================================
is_buy_signal = buy_signal_buySignal
is_sell_signal = sell_signal_sellSignal
amf_context = f_analyzeAMF(amf_line, amf_signal, is_buy_signal, is_sell_signal, atr14)
alma_context = f_analyzeALMA(alma200, alma2, is_buy_signal, is_sell_signal, atr14)
sr_context = f_analyzeSupportResistance(is_buy_signal, is_sell_signal, atr14, signalHigh, signalLow, signalClose)
swing_context = f_analyzeSwingStructure(is_buy_signal, is_sell_signal, signalHigh, signalLow)
regime_context = f_analyzeMarketRegime(is_buy_signal, is_sell_signal, signalOpen, signalHigh, signalLow, signalClose)
amf_context_normalized = f_normalizeInput(amf_context, normalization_lookback, outlier_clipping, clipping_threshold)
alma_context_normalized = f_normalizeInput(alma_context, normalization_lookback, outlier_clipping, clipping_threshold)
sr_context_normalized = f_normalizeInput(sr_context, normalization_lookback, outlier_clipping, clipping_threshold)
swing_context_normalized = f_normalizeInput(swing_context, normalization_lookback, outlier_clipping, clipping_threshold)
regime_context_normalized = f_normalizeInput(regime_context, normalization_lookback, outlier_clipping, clipping_threshold)
signal_score = (is_buy_signal or is_sell_signal) ?
f_scoreSignalNormalized(amf_context_normalized, alma_context_normalized,
sr_context_normalized, swing_context_normalized, regime_context_normalized) : 0.5
signal_grade = f_getSignalGrade(signal_score)
score_color = f_getScoreColor(signal_score)
// ===========================================================================================================
// CANDLE PLOTTING
// ===========================================================================================================
candleColor = isBullishCandle ? customBuyColor : customSellColor
plotcandle(candleType != 'Candlesticks' ? displayOpen : na,
candleType != 'Candlesticks' ? displayHigh : na,
candleType != 'Candlesticks' ? displayLow : na,
candleType != 'Candlesticks' ? displayClose : na,
title = 'BAR',
color = candleType != 'Candlesticks' ? candleColor : na,
wickcolor = candleType != 'Candlesticks' ? candleColor : na,
bordercolor = candleType != 'Candlesticks' ? candleColor : na)
// ===========================================================================================================
/////////////////////////////////////////////////////////////////////
// ================= User Inputs =================
Periods = input.int(10, title="ATR Period", minval=1)
src = input.source(close, title="Source")
Multiplier = input.float(5.7, title="ATR Multiplier")
changeATR = input.bool(true, title="Use True ATR?")
showsignals = input.bool(true, title="Show Buy/Sell Signals")
highlighting = input.bool(true, title="Enable Trend Highlighting")
// ================= ATR Calculation =================
atr2 = ta.sma(ta.tr, Periods)
atr = changeATR ? ta.atr(Periods) : atr2
// ================= Trend Calculation =================
up = src - (Multiplier * atr)
up1 = nz(up[1], up)
up := close[1] > up1 ? math.max(up, up1) : up
dn = src + (Multiplier * atr)
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? math.min(dn, dn1) : dn
var int trend = 1
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
// ================= Plotting Up/Down Trend Lines =================
upPlot = plot(trend == 1 ? up : na, title="ATRX", style=plot.style_linebr, linewidth=1, color=color.rgb(4, 255, 12))
dnPlot = plot(trend == -1 ? dn : na, title="ATRY", style=plot.style_linebr, linewidth=1, color=color.red)
// ================= Buy/Sell Signals =================
//buySignal = trend == 1 and trend[1] == -1
//sellSignal = trend == -1 and trend[1] == 1
//plotshape(buySignal and showsignals ? up : na, title="Buy", text="A", style=shape.labelup, location=location.bottom, size=size.small, color=#ffbf00, textcolor=color.black)
//plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="S", location=location.top, style=shape.labeldown, size=size.small, color=#ffbf00, textcolor=color.black)
// INPUTS ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
len = input.int(5, "Length", step = 5)
lblSize = input.string("normal", "Text Size", ["tiny", "small", "normal", "large"])
showBroken = input.bool(true, "Show Broken")
color_up = input.color(color.rgb(35, 209, 125, 100), "", inline = "color")
txtSize = switch lblSize
"tiny" => size.tiny
"small" => size.small
"normal" => size.normal
"large" => size.large
var int index_low = na
var float loww = na
var int index_high = na
var float highh = na
var bool direction = bool(na)
type pivot
float value
int index
bool isLow
type drawObj
polyline poly
polyline poly1
array<label> lbl
var storeDraws = array.new<drawObj>()
var storePivots = array.new<pivot>()
var start = 0
var broke = false
var level5 = 0.
var line breaker = na
// }
// CALCULATIONS――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
float highest = ta.highest(len)
float lowest = ta.lowest(len)
if storePivots.size() > 6
storePivots.shift()
labels = array.new<label>()
stl1 = line.style_solid
if high == highest
direction := true
if low == lowest
direction := false
if low[1] == lowest[1] and low > lowest
index_low := bar_index[1]
loww := low[1]
if high[1] == highest[1] and high < highest
index_high := bar_index[1]
highh := high[1]
if direction != direction[1] and direction
storePivots.push(pivot.new(loww, index_low, true))
if direction != direction[1] and not direction
storePivots.push(pivot.new(highh, index_high, false))
// ==============================
if storePivots.size() > 6
pivot0 = storePivots.get(0)
pivot1 = storePivots.get(1)
pivot2 = storePivots.get(2)
pivot3 = storePivots.get(3)
pivot4 = storePivots.get(4)
pivot5 = storePivots.get(5)
pivot6 = storePivots.get(6)
bPoint = math.avg(pivot5.value, pivot6.value)
cond = pivot1.value > pivot2.value
and pivot1.value < pivot3.value
and pivot3.value < pivot5.value
and pivot4.value < pivot3.value
and pivot4.value > pivot2.value
and pivot6.value < pivot5.value
and pivot6.value < pivot3.value
and pivot6.value > pivot1.value
// }
// PLOT ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
if cond and not broke and bar_index - start > 200
start := bar_index
cp = array.new<chart.point>()
cp1 = array.new<chart.point>()
//breaker := line.new(pivot5.index, pivot5.value, bar_index, pivot5.value, style = line.style_dotted, color = chart.fg_color)
//line.new(pivot4.index, pivot4.value, bar_index-25, pivot4.value, style = line.style_dotted, color = chart.fg_color)
level5 := pivot5.value
for p in storePivots
l = label.new(p.index, p.value
, text = storePivots.indexof(p) == 6 ? "(a)" : storePivots.indexof(p) == 0 ? "" : str.tostring(storePivots.indexof(p))
, style = p.isLow ? label.style_label_up : label.style_label_down
, color = color(na)
, textcolor = storePivots.indexof(p) == 6 ? color.orange : chart.fg_color
, size = txtSize
)
labels.push(l)
cp.push(chart.point.from_index(p.index, p.value))
cp1.push(chart.point.from_index(pivot6.index, pivot6.value))
cp1.push(chart.point.from_index(bar_index+15, bPoint))
cp1.push(chart.point.from_index(bar_index+45, pivot6.value))
lbl1 = label.new(bar_index+15, bPoint, "(b)", style = label.style_label_down, color = color(na), textcolor = color.orange, size = txtSize)
lbl2 = label.new(bar_index+45, pivot6.value, "(c)", style = label.style_label_up, color = color(na), textcolor = color.orange, size = txtSize)
labels.push(lbl1)
labels.push(lbl2)
//poly = polyline.new(cp, line_color = color_up, line_width = 2)
//poly1 = polyline.new(cp1, line_color = chart.fg_color, line_style = line.style_dashed)
//storeDraws.push(drawObj.new(poly, poly1, labels))
if close > level5 and close[1] < level5 and bar_index - start < 100 and not broke and not showBroken
if storeDraws.size() > 0
last = storeDraws.pop()
last.poly.delete()
last.poly1.delete()
for lbl in last.lbl
lbl.delete()
breaker.set_x2(bar_index)
broke := true
if bar_index - start > 100
broke := false
// }////////////
16.07.2024 - 10.12.2024 https://chatgpt.com/g/g-uib6qYHGw-tr...ipt-v5-creator
hoşuma giden bir kod....
denemek isteyene.....
PHP Code:
//@version=6
indicator('Adaptive Parabolic SAR (PSAR) [Loxx]', shorttitle = '.', overlay = true, timeframe = '', timeframe_gaps = true)
//thanks to @Bjorgum
calcBaseUnit() =>
bool isForexSymbol = syminfo.type == 'forex'
bool isYenPair = syminfo.currency == 'JPY'
float result = isForexSymbol ? isYenPair ? 0.01 : 0.0001 : syminfo.mintick
result
greencolor = #2DD204
redcolor = #D2042D
_afact(mode, input, per, smooth) =>
eff = 0.
seff = 0.
len = 0
sum = 0.
max = 0.
min = 1000000000.
len := mode == 'Kaufman' ? math.ceil(per) : math.ceil(math.max(20, 5 * per))
for i = 0 to len by 1
if mode == 'Kaufman'
sum := sum + math.abs(input[i] - input[i + 1])
sum
else
max := input[i] > max ? input[i] : max
min := input[i] < min ? input[i] : min
min
if mode == 'Kaufman' and sum != 0
eff := math.abs(input - input[len]) / sum
eff
else
if mode == 'Ehlers' and max - min > 0
eff := (input - min) / (max - min)
eff
seff := ta.ema(eff, smooth)
seff
src = input.source(close, 'Sourse', group = 'Basic Settings')
startAFactor = input.float(0.1, 'Starting Acceleration Factor', step = 0.001, group = 'Basic Settings')
minStep = input.float(0.0, 'Min Step', step = 0.001, group = 'Basic Settings')
maxStep = input.float(0.2, 'Max Step', step = 0.001, group = 'Basic Settings')
maxAFactor = input.float(0.2, 'Max Acceleration Factor', step = 0.001, group = 'Basic Settings')
hiloMode = input.string('On', 'HiLo Mode', options = ['Off', 'On'], group = 'Advanced Settings')
adaptMode = input.string('Kaufman', 'Adaptive Mode', options = ['Off', 'Kaufman', 'Ehlers'], group = 'Advanced Settings')
adaptSmth = input.int(5, 'Adaptive Smoothing Period', minval = 1, group = 'Advanced Settings')
filt = input.float(0.0, 'Filter in Pips', group = 'Advanced Settings', minval = 0)
minChng = input.float(0.0, 'Min Change in Pips', group = 'Advanced Settings', minval = 0)
SignalMode = input.string('Only Stops', 'Signal Mode', options = ['Only Stops', 'Signals & Stops'], group = 'Advanced Settings')
colorbars = input.bool(false, 'Color bars?', group = 'UI Options')
hVal2 = nz(high[2])
hVal1 = nz(high[1])
hVal0 = high
lowVal2 = nz(low[2])
lowVal1 = nz(low[1])
lowVal0 = low
hiprice2 = nz(high[2])
hiprice1 = nz(high[1])
hiprice0 = high
loprice2 = nz(low[2])
loprice1 = nz(low[1])
loprice0 = low
upSig = 0.
dnSig = 0.
aFactor = 0.
step = 0.
trend = 0.
upTrndSAR = 0.
dnTrndSAR = 0.
length = 2 / maxAFactor - 1
if hiloMode == 'On'
hiprice0 := high
loprice0 := low
loprice0
else
hiprice0 := src
loprice0 := hiprice0
loprice0
if bar_index == 1
trend := 1
hVal1 := hiprice1
hVal0 := math.max(hiprice0, hVal1)
lowVal1 := loprice1
lowVal0 := math.min(loprice0, lowVal1)
aFactor := startAFactor
upTrndSAR := lowVal0
dnTrndSAR := 0.
dnTrndSAR
else
hVal0 := hVal1
lowVal0 := lowVal1
trend := nz(trend[1])
aFactor := nz(aFactor[1])
inputs = 0.
inprice = src
if adaptMode != 'Off'
if hiloMode == 'On'
inprice := src
inprice
else
inprice := hiprice0
inprice
if adaptMode == 'Kaufman'
inputs := inprice
inputs
else
if adaptMode == 'Ehlers'
if nz(upTrndSAR[1]) != 0.
inputs := math.abs(inprice - nz(upTrndSAR[1]))
inputs
else
if nz(dnTrndSAR[1]) != 0.
inputs := math.abs(inprice - nz(dnTrndSAR[1]))
inputs
step := minStep + _afact(adaptMode, inputs, length, adaptSmth) * (maxStep - minStep)
step
else
step := maxStep
step
upTrndSAR := 0.
dnTrndSAR := 0.
upSig := 0.
dnSig := 0.
if nz(trend[1]) > 0
if nz(trend[1]) == nz(trend[2])
aFactor := hVal1 > hVal2 ? nz(aFactor[1]) + step : aFactor
aFactor := aFactor > maxAFactor ? maxAFactor : aFactor
aFactor := hVal1 < hVal2 ? startAFactor : aFactor
aFactor
else
aFactor := nz(aFactor[1])
aFactor
upTrndSAR := nz(upTrndSAR[1]) + aFactor * (hVal1 - nz(upTrndSAR[1]))
upTrndSAR := upTrndSAR > loprice1 ? loprice1 : upTrndSAR
upTrndSAR := upTrndSAR > loprice2 ? loprice2 : upTrndSAR
upTrndSAR
else
if nz(trend[1]) == nz(trend[2])
aFactor := lowVal1 < lowVal2 ? nz(aFactor[1]) + step : aFactor
aFactor := aFactor > maxAFactor ? maxAFactor : aFactor
aFactor := lowVal1 > lowVal2 ? startAFactor : aFactor
aFactor
else
aFactor := nz(aFactor[1])
aFactor
dnTrndSAR := nz(dnTrndSAR[1]) + aFactor * (lowVal1 - nz(dnTrndSAR[1]))
dnTrndSAR := dnTrndSAR < hiprice1 ? hiprice1 : dnTrndSAR
dnTrndSAR := dnTrndSAR < hiprice2 ? hiprice2 : dnTrndSAR
dnTrndSAR
hVal0 := hiprice0 > hVal0 ? hiprice0 : hVal0
lowVal0 := loprice0 < lowVal0 ? loprice0 : lowVal0
if minChng > 0
if upTrndSAR - nz(upTrndSAR[1]) < minChng * calcBaseUnit() and upTrndSAR != 0. and nz(upTrndSAR[1]) != 0.
upTrndSAR := nz(upTrndSAR[1])
upTrndSAR
if nz(dnTrndSAR[1]) - dnTrndSAR < minChng * calcBaseUnit() and dnTrndSAR != 0. and nz(dnTrndSAR[1]) != 0.
dnTrndSAR := nz(dnTrndSAR[1])
dnTrndSAR
dnTrndSAR := trend < 0 and dnTrndSAR > nz(dnTrndSAR[1]) ? nz(dnTrndSAR[1]) : dnTrndSAR
upTrndSAR := trend > 0 and upTrndSAR < nz(upTrndSAR[1]) ? nz(upTrndSAR[1]) : upTrndSAR
if trend < 0 and hiprice0 >= dnTrndSAR + filt * calcBaseUnit()
trend := 1
upTrndSAR := lowVal0
upSig := SignalMode == 'Signals & Stops' ? lowVal0 : upSig
dnTrndSAR := 0.
aFactor := startAFactor
lowVal0 := loprice0
hVal0 := hiprice0
hVal0
else if trend > 0 and loprice0 <= upTrndSAR - filt * calcBaseUnit()
trend := -1
dnTrndSAR := hVal0
dnSig := SignalMode == 'Signals & Stops' ? hVal0 : dnSig
upTrndSAR := 0.
aFactor := startAFactor
lowVal0 := loprice0
hVal0 := hiprice0
hVal0
outer = upTrndSAR > 0 ? upTrndSAR : dnTrndSAR
colorout = outer >= src ? redcolor : greencolor
plot(upTrndSAR > 0 ? upTrndSAR : dnTrndSAR, "Trend", color = colorout, style = plot.style_stepline_diamond, linewidth = 2)
//barcolor(colorbars ? colorout : na)
//plotshape(SignalMode == 'Signals & Stops' ? dnSig : na, color = redcolor, textcolor = redcolor, style = shape.triangledown, location = location.abovebar, size = size.small, title = 'Short', text = 'S')
//plotshape(SignalMode == 'Signals & Stops' ? upSig : na, color = greencolor, textcolor = greencolor, style = shape.triangleup, location = location.belowbar, size = size.small, title = 'Long', text = 'L')
16.07.2024 - 10.12.2024 https://chatgpt.com/g/g-uib6qYHGw-tr...ipt-v5-creator
atr ile kombine.... denemek isteyene....PHP Code:
//@version=6
indicator('Adaptive Parabolic SAR (PSAR) [Loxx]', shorttitle = '.', overlay = true, timeframe = '', timeframe_gaps = true, max_lines_count = 100, max_labels_count=100, max_boxes_count = 100, max_bars_back = 100)
//thanks to @Bjorgum
calcBaseUnit() =>
bool isForexSymbol = syminfo.type == 'forex'
bool isYenPair = syminfo.currency == 'JPY'
float result = isForexSymbol ? isYenPair ? 0.01 : 0.0001 : syminfo.mintick
result
greencolor = #2DD204
redcolor = #D2042D
_afact(mode, input, per, smooth) =>
eff = 0.
seff = 0.
len = 0
sum = 0.
max = 0.
min = 1000000000.
len := mode == 'Kaufman' ? math.ceil(per) : math.ceil(math.max(20, 5 * per))
for i = 0 to len by 1
if mode == 'Kaufman'
sum := sum + math.abs(input[i] - input[i + 1])
sum
else
max := input[i] > max ? input[i] : max
min := input[i] < min ? input[i] : min
min
if mode == 'Kaufman' and sum != 0
eff := math.abs(input - input[len]) / sum
eff
else
if mode == 'Ehlers' and max - min > 0
eff := (input - min) / (max - min)
eff
seff := ta.ema(eff, smooth)
seff
src = input.source(close, 'Sourse', group = 'Basic Settings')
startAFactor = input.float(0.1, 'Starting Acceleration Factor', step = 0.001, group = 'Basic Settings')
minStep = input.float(0.0, 'Min Step', step = 0.001, group = 'Basic Settings')
maxStep = input.float(0.2, 'Max Step', step = 0.001, group = 'Basic Settings')
maxAFactor = input.float(0.2, 'Max Acceleration Factor', step = 0.001, group = 'Basic Settings')
hiloMode = input.string('On', 'HiLo Mode', options = ['Off', 'On'], group = 'Advanced Settings')
adaptMode = input.string('Kaufman', 'Adaptive Mode', options = ['Off', 'Kaufman', 'Ehlers'], group = 'Advanced Settings')
adaptSmth = input.int(5, 'Adaptive Smoothing Period', minval = 1, group = 'Advanced Settings')
filt = input.float(0.0, 'Filter in Pips', group = 'Advanced Settings', minval = 0)
minChng = input.float(0.0, 'Min Change in Pips', group = 'Advanced Settings', minval = 0)
SignalMode = input.string('Only Stops', 'Signal Mode', options = ['Only Stops', 'Signals & Stops'], group = 'Advanced Settings')
colorbars = input.bool(false, 'Color bars?', group = 'UI Options')
hVal2 = nz(high[2])
hVal1 = nz(high[1])
hVal0 = high
lowVal2 = nz(low[2])
lowVal1 = nz(low[1])
lowVal0 = low
hiprice2 = nz(high[2])
hiprice1 = nz(high[1])
hiprice0 = high
loprice2 = nz(low[2])
loprice1 = nz(low[1])
loprice0 = low
upSig = 0.
dnSig = 0.
aFactor = 0.
step = 0.
trend = 0.
upTrndSAR = 0.
dnTrndSAR = 0.
length = 2 / maxAFactor - 1
if hiloMode == 'On'
hiprice0 := high
loprice0 := low
loprice0
else
hiprice0 := src
loprice0 := hiprice0
loprice0
if bar_index == 1
trend := 1
hVal1 := hiprice1
hVal0 := math.max(hiprice0, hVal1)
lowVal1 := loprice1
lowVal0 := math.min(loprice0, lowVal1)
aFactor := startAFactor
upTrndSAR := lowVal0
dnTrndSAR := 0.
dnTrndSAR
else
hVal0 := hVal1
lowVal0 := lowVal1
trend := nz(trend[1])
aFactor := nz(aFactor[1])
inputs = 0.
inprice = src
if adaptMode != 'Off'
if hiloMode == 'On'
inprice := src
inprice
else
inprice := hiprice0
inprice
if adaptMode == 'Kaufman'
inputs := inprice
inputs
else
if adaptMode == 'Ehlers'
if nz(upTrndSAR[1]) != 0.
inputs := math.abs(inprice - nz(upTrndSAR[1]))
inputs
else
if nz(dnTrndSAR[1]) != 0.
inputs := math.abs(inprice - nz(dnTrndSAR[1]))
inputs
step := minStep + _afact(adaptMode, inputs, length, adaptSmth) * (maxStep - minStep)
step
else
step := maxStep
step
upTrndSAR := 0.
dnTrndSAR := 0.
upSig := 0.
dnSig := 0.
if nz(trend[1]) > 0
if nz(trend[1]) == nz(trend[2])
aFactor := hVal1 > hVal2 ? nz(aFactor[1]) + step : aFactor
aFactor := aFactor > maxAFactor ? maxAFactor : aFactor
aFactor := hVal1 < hVal2 ? startAFactor : aFactor
aFactor
else
aFactor := nz(aFactor[1])
aFactor
upTrndSAR := nz(upTrndSAR[1]) + aFactor * (hVal1 - nz(upTrndSAR[1]))
upTrndSAR := upTrndSAR > loprice1 ? loprice1 : upTrndSAR
upTrndSAR := upTrndSAR > loprice2 ? loprice2 : upTrndSAR
upTrndSAR
else
if nz(trend[1]) == nz(trend[2])
aFactor := lowVal1 < lowVal2 ? nz(aFactor[1]) + step : aFactor
aFactor := aFactor > maxAFactor ? maxAFactor : aFactor
aFactor := lowVal1 > lowVal2 ? startAFactor : aFactor
aFactor
else
aFactor := nz(aFactor[1])
aFactor
dnTrndSAR := nz(dnTrndSAR[1]) + aFactor * (lowVal1 - nz(dnTrndSAR[1]))
dnTrndSAR := dnTrndSAR < hiprice1 ? hiprice1 : dnTrndSAR
dnTrndSAR := dnTrndSAR < hiprice2 ? hiprice2 : dnTrndSAR
dnTrndSAR
hVal0 := hiprice0 > hVal0 ? hiprice0 : hVal0
lowVal0 := loprice0 < lowVal0 ? loprice0 : lowVal0
if minChng > 0
if upTrndSAR - nz(upTrndSAR[1]) < minChng * calcBaseUnit() and upTrndSAR != 0. and nz(upTrndSAR[1]) != 0.
upTrndSAR := nz(upTrndSAR[1])
upTrndSAR
if nz(dnTrndSAR[1]) - dnTrndSAR < minChng * calcBaseUnit() and dnTrndSAR != 0. and nz(dnTrndSAR[1]) != 0.
dnTrndSAR := nz(dnTrndSAR[1])
dnTrndSAR
dnTrndSAR := trend < 0 and dnTrndSAR > nz(dnTrndSAR[1]) ? nz(dnTrndSAR[1]) : dnTrndSAR
upTrndSAR := trend > 0 and upTrndSAR < nz(upTrndSAR[1]) ? nz(upTrndSAR[1]) : upTrndSAR
if trend < 0 and hiprice0 >= dnTrndSAR + filt * calcBaseUnit()
trend := 1
upTrndSAR := lowVal0
upSig := SignalMode == 'Signals & Stops' ? lowVal0 : upSig
dnTrndSAR := 0.
aFactor := startAFactor
lowVal0 := loprice0
hVal0 := hiprice0
hVal0
else if trend > 0 and loprice0 <= upTrndSAR - filt * calcBaseUnit()
trend := -1
dnTrndSAR := hVal0
dnSig := SignalMode == 'Signals & Stops' ? hVal0 : dnSig
upTrndSAR := 0.
aFactor := startAFactor
lowVal0 := loprice0
hVal0 := hiprice0
hVal0
outer = upTrndSAR > 0 ? upTrndSAR : dnTrndSAR
colorout = outer >= src ? redcolor : greencolor
plot(upTrndSAR > 0 ? upTrndSAR : dnTrndSAR, "Trend", color = colorout, style = plot.style_stepline_diamond, linewidth = 2)
//barcolor(colorbars ? colorout : na)
//plotshape(SignalMode == 'Signals & Stops' ? dnSig : na, color = redcolor, textcolor = redcolor, style = shape.triangledown, location = location.abovebar, size = size.small, title = 'Short', text = 'S')
//plotshape(SignalMode == 'Signals & Stops' ? upSig : na, color = greencolor, textcolor = greencolor, style = shape.triangleup, location = location.belowbar, size = size.small, title = 'Long', text = 'L')
/////////////////////////////////
var string scalpHelperGroup = 'Scalp Helper Signal Settings'
enable_scalp_helper = input.bool(true, 'Enable Scalp Helper Signals', group = scalpHelperGroup)
signalCandleType = input.string('Heikin Ashi', 'Signal Candle Type', options = ['Candlesticks', 'Heikin Ashi', 'Linear Regression'], group = scalpHelperGroup, tooltip = 'Choose which candle type to use for signal calculations. This will not change what candlestick type is displayed.')
signal_trigger_mult = input.float(0.1, 'Signal Trigger Sensitivity', minval = 0.1, maxval = 10.0, step = 0.1, group = scalpHelperGroup, tooltip = 'Controls both buy and sell signal sensitivity. Lower values = more sensitive signals, higher values = less sensitive signals.')
stop_atr_mult = input.float(1.5, 'Stop Loss ATR Multiplier', minval = 0.1, maxval = 10.0, step = 0.1, group = scalpHelperGroup, tooltip = 'Once a signal is triggered this stop will be initiated to tell how long the signal is valid. Higher values = wider stops and less signals, lower values = tighter stops and more signals.')
var string candleGroup = 'Candlestick Settings'
candleType = input.string('Heikin Ashi', 'Candle Type', options = ['Candlesticks', 'Heikin Ashi', 'Linear Regression'], group = candleGroup, tooltip = 'Choose the type of candles to display. This does not impact signal calculations.')
lrcLength1 = input.int(100, 'Linear Regression Length', minval = 1, group = candleGroup, tooltip = 'Length for Linear Regression calculations. Lower values are more responsive but noisier.')
var string visualGroup = 'Display Settings'
signalOffset = input.float(5, 'Signal Distance from Candles', minval = 0.1, maxval = 5.0, step = 0.1, group = visualGroup, tooltip = 'Distance of buy/sell labels from candles (ATR multiplier)')
signalLabelSize = input.string('medium', 'Signal Label Size', options = ['tiny', 'small', 'medium', 'large'], group = visualGroup, tooltip = 'Size of the neural network signal labels')
buy_signal_length = 2
buy_atr_length = 18
sell_signal_length = 2
sell_atr_length = 18
buy_signal_use_close = false
buy_atr_use_close = true
sell_signal_use_close = false
sell_atr_use_close = true
amf_length = 14
amf_signal_length = 9
amf_smoothing = 3
amf_fast_length = 5
amf_slow_length = 21
amf_far_threshold = 0.3
amf_slope_fast_threshold = 0.03
h1_amf_weight = 1.2
h1_alma_weight = 0.4
h1_sr_weight = 0.5
h1_swing_weight = 0.4
h1_regime_weight = 0.7
h1_bias = 0.2
h2_amf_weight = 1.4
h2_alma_weight = 0.3
h2_sr_weight = 0.6
h2_swing_weight = 0.3
h2_regime_weight = 0.8
h2_bias = 0.15
h3_amf_weight = 1.6
h3_alma_weight = 0.4
h3_sr_weight = 0.4
h3_swing_weight = 0.5
h3_regime_weight = 0.6
h3_bias = 0.25
out_h1_weight = 0.4
out_h2_weight = 0.4
out_h3_weight = 0.4
out_bias = 0.3
enable_input_normalization = true
normalization_lookback = 50
outlier_clipping = true
clipping_threshold = 3.0
almaLength = 20
almaOffset = 0.85
almaSigma = 6.0
alma2Length = 20
alma2Offset = 0.77
alma2Sigma = 6.0
alma_wide_gap_threshold = 0.1
pivot_lookback = 10
sr_proximity_threshold = 0.5
sr_breakout_threshold = 0.2
swing_structure_length = 20
regime_lookback = 30
trending_threshold = 0.6
showScalpLabels = true
var float signalOpen = open
var float signalHigh = high
var float signalLow = low
var float signalClose = close
customBuyColor = color.new(#00FFFF, 0)
customSellColor = color.new(#FF0000, 0)
scalpLongColor = color.new(#00B3B3, 0)
scalpShortColor = color.new(#FF0000, 0)
textColor = color.new(color.white, 0)
f_ema_amf(source, len) =>
float alpha = 2.0 / (len + 1)
var float ema_val = na
if not na(source) and len > 0
ema_val := alpha * source + (1 - alpha) * nz(ema_val[1])
ema_val
f_dema_amf(source, len) =>
float ema1 = f_ema_amf(source, len)
float ema2 = f_ema_amf(ema1, len)
float dema_val = 2 * ema1 - ema2
dema_val
f_zlema_amf(source, len) =>
int lag = int((len - 1) / 2)
float lag_source = lag > 0 ? source[lag] : source
float adjusted_source = source + (source - lag_source)
float zlema_val = f_ema_amf(adjusted_source, len)
zlema_val
f_sum_amf(source, len) =>
float sum_val = 0.0
for i = 0 to len - 1
sum_val += nz(source[i], 0)
sum_val
f_calculate_amf(src, length, fast_len, slow_len, smooth_len) =>
float current_atr = ta.atr(14)
float avg_atr = ta.sma(current_atr, 50)
float volatility_ratio = avg_atr > 0 ? current_atr / avg_atr : 1.0
float volatility_sensitivity = 2.0
float raw_adaptive_lookback = float(length) / math.pow(volatility_ratio, volatility_sensitivity)
int adaptive_lookback = int(math.max(5, math.min(50, raw_adaptive_lookback)))
if adaptive_lookback < 1
adaptive_lookback := 1
int zlema_fast_len = adaptive_lookback
int dema_medium_len = int(adaptive_lookback * 1.5)
int dema_slow_len = int(adaptive_lookback * 2.5)
if dema_medium_len < 1
dema_medium_len := 1
if dema_slow_len < 1
dema_slow_len := 1
float zlema_fast = f_zlema_amf(src, zlema_fast_len)
float dema_medium = f_dema_amf(src, dema_medium_len)
float dema_slow = f_dema_amf(src, dema_slow_len)
float pv = 0.0
if src > src[1]
pv := volume
else if src < src[1]
pv := -volume
float vzo_sum = f_sum_amf(pv, length)
float vol_sum = f_sum_amf(volume, length)
float vzo_value = vol_sum != 0 ? 100 * (vzo_sum / vol_sum) : 0.0
float smoothed_vzo = ta.sma(vzo_value, 3)
float price_vs_fast_weight = 30.0
float fast_vs_medium_weight = 30.0
float medium_vs_slow_weight = 40.0
float vzo_weight = 20.0
float oscillator_score = 0.0
if src > zlema_fast
oscillator_score += price_vs_fast_weight
else if src < zlema_fast
oscillator_score -= price_vs_fast_weight
if zlema_fast > dema_medium
oscillator_score += fast_vs_medium_weight
else if zlema_fast < dema_medium
oscillator_score -= fast_vs_medium_weight
if dema_medium > dema_slow
oscillator_score += medium_vs_slow_weight
else if dema_medium < dema_slow
oscillator_score -= medium_vs_slow_weight
oscillator_score += (smoothed_vzo / 100) * vzo_weight
float max_possible_score = price_vs_fast_weight + fast_vs_medium_weight + medium_vs_slow_weight + vzo_weight
float normalized_score = max_possible_score != 0.0 ? (oscillator_score / max_possible_score) * 100.0 : 0.0
float final_amf = ta.ema(normalized_score / 100.0, smooth_len)
final_amf
f_amf_signal(amf_line, signal_length) =>
ta.ema(amf_line, signal_length)
// ===========================================================================================================
// CACHED CALCULATIONS
// ===========================================================================================================
cached_atr = ta.atr(14)
// ===========================================================================================================
// NORMALIZATION FUNCTIONS
// ===========================================================================================================
f_normalizeInput(value, lookback_period, enable_clipping, clip_threshold) =>
if not enable_input_normalization
value
else
mean_val = ta.sma(value, lookback_period)
variance = ta.sma(math.pow(value - mean_val, 2), lookback_period)
std_val = math.sqrt(variance)
normalized = std_val > 0 ? (value - mean_val) / std_val : 0.0
if enable_clipping
math.max(-clip_threshold, math.min(clip_threshold, normalized))
else
normalized
f_robustNormalize(value, lookback_period) =>
if not enable_input_normalization
value
else
ema_val = ta.ema(value, lookback_period)
abs_dev = math.abs(value - ema_val)
mad_approx = ta.ema(abs_dev, lookback_period) * 1.4826
mad_approx > 0 ? (value - ema_val) / mad_approx : 0.0
// ===========================================================================================================
// SIGNAL SCORING
// ===========================================================================================================
// Tanh approximation
f_tanh(x) =>
ex = math.exp(2 * x)
(ex - 1) / (ex + 1)
f_scoreSignal(amf_score, alma_score, sr_score, swing_score, regime_score) =>
hidden1 = f_tanh(h1_amf_weight*amf_score + h1_alma_weight*alma_score + h1_sr_weight*sr_score + h1_swing_weight*swing_score + h1_regime_weight*regime_score + h1_bias)
hidden2 = f_tanh(h2_amf_weight*amf_score + h2_alma_weight*alma_score + h2_sr_weight*sr_score + h2_swing_weight*swing_score + h2_regime_weight*regime_score + h2_bias)
hidden3 = f_tanh(h3_amf_weight*amf_score + h3_alma_weight*alma_score + h3_sr_weight*sr_score + h3_swing_weight*swing_score + h3_regime_weight*regime_score + h3_bias)
raw_output = out_h1_weight*hidden1 + out_h2_weight*hidden2 + out_h3_weight*hidden3 + out_bias
1.0 / (1.0 + math.exp(-raw_output))
f_scoreSignalNormalized(amf_norm, alma_norm, sr_norm, swing_norm, regime_norm) =>
input_scale = 0.8
scaled_amf = amf_norm * input_scale
scaled_alma = alma_norm * input_scale
scaled_sr = sr_norm * input_scale
scaled_swing = swing_norm * input_scale
scaled_regime = regime_norm * input_scale
hidden1 = f_tanh(h1_amf_weight*scaled_amf + h1_alma_weight*scaled_alma +
h1_sr_weight*scaled_sr + h1_swing_weight*scaled_swing + h1_regime_weight*scaled_regime + h1_bias)
hidden2 = f_tanh(h2_amf_weight*scaled_amf + h2_alma_weight*scaled_alma +
h2_sr_weight*scaled_sr + h2_swing_weight*scaled_swing + h2_regime_weight*scaled_regime + h2_bias)
hidden3 = f_tanh(h3_amf_weight*scaled_amf + h3_alma_weight*scaled_alma +
h3_sr_weight*scaled_sr + h3_swing_weight*scaled_swing + h3_regime_weight*scaled_regime + h3_bias)
raw_output = out_h1_weight*hidden1 + out_h2_weight*hidden2 + out_h3_weight*hidden3 + out_bias
temperature = 1.2
1.0 / (1.0 + math.exp(-raw_output / temperature))
f_getSignalGrade(score) =>
if score >= 0.80
">80"
else if score >= 0.76
"76"
else if score >= 0.65
"65"
else if score >= 0.40
"40"
else if score >= 0.32
"32"
else
"<32" // (< 0.32)
f_getScoreColor(score) =>
var color result_color = color.maroon
if score >= 0.76
result_color := customBuyColor
else if score >= 0.65
result_color := color.new(customBuyColor, 20)
else if score >= 0.40
result_color := color.new(#00FFFF, 30)
else if score >= 0.32
result_color := color.new(#FFB000, 0)
else
result_color := customSellColor
result_color
// AMF Analysis Functions
f_analyzeAMF(amf_line, signal_line, is_buy, is_sell, cached_atr) =>
amf_vs_signal = amf_line - signal_line
crossing_up = amf_line > signal_line and amf_line[1] <= signal_line[1]
crossing_down = amf_line < signal_line and amf_line[1] >= signal_line[1]
normalized_distance = math.abs(amf_vs_signal) / cached_atr
is_far = normalized_distance > amf_far_threshold
signal_slope = (signal_line - signal_line[1]) / cached_atr
slope_fast_falling = signal_slope < -amf_slope_fast_threshold
slope_fast_rising = signal_slope > amf_slope_fast_threshold
var float amf_score = 0.0
if is_buy
if crossing_up or amf_line > signal_line
amf_score := 1.0
else if amf_line < signal_line
if is_far
amf_score := -0.8
else
amf_score := -0.4
else
amf_score := 0.0
if slope_fast_falling
amf_score := amf_score - 0.3
else if is_sell
if crossing_down or amf_line < signal_line
amf_score := 1.0
else if amf_line > signal_line
if is_far
amf_score := -0.8
else
amf_score := -0.4
else
amf_score := 0.0
if slope_fast_rising
amf_score := amf_score - 0.3
else
amf_score := 0.0
math.max(-1.0, math.min(1.0, amf_score))
f_analyzeALMA(fast_alma, slow_alma, is_buy, is_sell, cached_atr) =>
alma_gap = fast_alma - slow_alma
normalized_gap = math.abs(alma_gap) / cached_atr
is_wide_gap = normalized_gap > alma_wide_gap_threshold
crossing_up = fast_alma > slow_alma and fast_alma[1] <= slow_alma[1]
crossing_down = fast_alma < slow_alma and fast_alma[1] >= slow_alma[1]
var float alma_score = 0.0
if is_buy
if crossing_up or fast_alma > slow_alma
alma_score := 0.5
else if fast_alma < slow_alma
if is_wide_gap
alma_score := -0.8
else
alma_score := -0.2
else
alma_score := 0.0
else if is_sell
if crossing_down or fast_alma < slow_alma
alma_score := 0.5
else if fast_alma > slow_alma
if is_wide_gap
alma_score := -0.8
else
alma_score := -0.2
else
alma_score := 0.0
else
alma_score := 0.0
alma_score
f_analyzeSupportResistance(is_buy, is_sell, cached_atr, sig_high, sig_low, sig_close) =>
pivot_high = ta.pivothigh(sig_high, pivot_lookback, pivot_lookback)
pivot_low = ta.pivotlow(sig_low, pivot_lookback, pivot_lookback)
var float nearest_resistance = na
var float nearest_support = na
if not na(pivot_high)
nearest_resistance := pivot_high
if not na(pivot_low)
nearest_support := pivot_low
resistance_distance = nearest_resistance > 0 ? math.abs(sig_close - nearest_resistance) / cached_atr : 999
support_distance = nearest_support > 0 ? math.abs(sig_close - nearest_support) / cached_atr : 999
near_resistance = resistance_distance <= sr_proximity_threshold
near_support = support_distance <= sr_proximity_threshold
recent_resistance_break = nearest_resistance > 0 and sig_close > nearest_resistance and sig_close[5] <= nearest_resistance
recent_support_break = nearest_support > 0 and sig_close < nearest_support and sig_close[5] >= nearest_support
var float sr_score = 0.0
if is_buy
if recent_resistance_break
sr_score := 0.8
else if near_support
sr_score := 0.5
else if near_resistance
sr_score := -0.6
else
sr_score := 0.0
else if is_sell
if recent_support_break
sr_score := 0.8
else if near_resistance
sr_score := 0.5
else if near_support
sr_score := -0.6
else
sr_score := 0.0
else
sr_score := 0.0
sr_score
f_analyzeSwingStructure(is_buy, is_sell, sig_high, sig_low) =>
recent_high = ta.highest(sig_high, swing_structure_length)
recent_low = ta.lowest(sig_low, swing_structure_length)
previous_high = ta.highest(sig_high[swing_structure_length], swing_structure_length)
previous_low = ta.lowest(sig_low[swing_structure_length], swing_structure_length)
making_higher_highs = recent_high > previous_high
making_higher_lows = recent_low > previous_low
making_lower_highs = recent_high < previous_high
making_lower_lows = recent_low < previous_low
bullish_structure = making_higher_highs and making_higher_lows
bearish_structure = making_lower_highs and making_lower_lows
mixed_structure = not bullish_structure and not bearish_structure
var float swing_score = 0.0
if is_buy
if bullish_structure
swing_score := 0.6
else if bearish_structure
swing_score := -0.7
else
swing_score := -0.1
else if is_sell
if bearish_structure
swing_score := 0.6
else if bullish_structure
swing_score := -0.7
else
swing_score := -0.1
else
swing_score := 0.0
swing_score
f_analyzeMarketRegime(is_buy, is_sell, sig_open, sig_high, sig_low, sig_close) =>
tr1 = math.max(sig_high - sig_low, math.abs(sig_high - sig_close[1]))
tr = math.max(tr1, math.abs(sig_low - sig_close[1]))
plus_dm = sig_high - sig_high[1] > sig_low[1] - sig_low ? math.max(sig_high - sig_high[1], 0) : 0
minus_dm = sig_low[1] - sig_low > sig_high - sig_high[1] ? math.max(sig_low[1] - sig_low, 0) : 0
plus_di = 100 * ta.rma(plus_dm, regime_lookback) / ta.rma(tr, regime_lookback)
minus_di = 100 * ta.rma(minus_dm, regime_lookback) / ta.rma(tr, regime_lookback)
dx = math.abs(plus_di - minus_di) / (plus_di + minus_di) * 100
adx = ta.rma(dx, regime_lookback)
trending_market = adx >= trending_threshold * 100
ranging_market = not trending_market
bullish_trend = trending_market and plus_di > minus_di
bearish_trend = trending_market and minus_di > plus_di
var float regime_score = 0.0
if is_buy
if bullish_trend
regime_score := 0.7
else if bearish_trend
regime_score := -0.8
else
regime_score := -0.2
else if is_sell
if bearish_trend
regime_score := 0.7
else if bullish_trend
regime_score := -0.8
else
regime_score := -0.2
else
regime_score := 0.0
regime_score
// ===========================================================================================================
// CANDLE TYPE CALCULATIONS
// ===========================================================================================================
// Heikin Ashi
calculateHA111() =>
var haOpen = 0.0
var haHigh = 0.0
var haLow = 0.0
var haClose = 0.0
newHaClose = (open + high + low + close) / 4
newHaOpen = na(haOpen[1]) ? (open + close) / 2 : (haOpen[1] + haClose[1]) / 2
newHaHigh = math.max(high, math.max(newHaOpen, newHaClose))
newHaLow = math.min(low, math.min(newHaOpen, newHaClose))
haClose := newHaClose
haOpen := newHaOpen
haHigh := newHaHigh
haLow := newHaLow
[newHaOpen, newHaHigh, newHaLow, newHaClose]
[oHA, hHA, lHA, cHA] = calculateHA111()
var float displayOpen = na
var float displayHigh = na
var float displayLow = na
var float displayClose = na
if candleType == 'Candlesticks'
displayOpen := open
displayHigh := high
displayLow := low
displayClose := close
else if candleType == 'Heikin Ashi'
displayOpen := oHA
displayHigh := hHA
displayLow := lHA
displayClose := cHA
else if candleType == 'Linear Regression'
displayOpen := ta.linreg(open, lrcLength1, 0)
displayHigh := ta.linreg(high, lrcLength1, 0)
displayLow := ta.linreg(low, lrcLength1, 0)
displayClose := ta.linreg(close, lrcLength1, 0)
// Determine coloring
isBullishCandle = displayClose > displayOpen
isBearishCandle = displayClose < displayOpen
// ===========================================================================================================
// SIGNAL DATA SOURCE SELECTION
// ===========================================================================================================
var float signalOpenCalc = na
var float signalHighCalc = na
var float signalLowCalc = na
var float signalCloseCalc = na
if signalCandleType == 'Candlesticks'
signalOpenCalc := open
signalHighCalc := high
signalLowCalc := low
signalCloseCalc := close
else if signalCandleType == 'Heikin Ashi'
signalOpenCalc := oHA
signalHighCalc := hHA
signalLowCalc := lHA
signalCloseCalc := cHA
else if signalCandleType == 'Linear Regression'
signalOpenCalc := ta.linreg(open, lrcLength1, 0)
signalHighCalc := ta.linreg(high, lrcLength1, 0)
signalLowCalc := ta.linreg(low, lrcLength1, 0)
signalCloseCalc := ta.linreg(close, lrcLength1, 0)
signalOpen := signalOpenCalc
signalHigh := signalHighCalc
signalLow := signalLowCalc
signalClose := signalCloseCalc
// ===========================================================================================================
// SCALP HELPER SIGNAL SYSTEM
// ===========================================================================================================
buy_signal_buySignal = false
sell_signal_sellSignal = false
buy_atr_sellSignal = false
sell_atr_buySignal = false
buy_atr_longStop = close
sell_atr_shortStop = close
var bool buy_atr_stop_active = false
var bool sell_atr_stop_active = false
if enable_scalp_helper
// ============================================================================
// BUY SIGNAL
// ============================================================================
buy_signal_atr = ta.atr(buy_signal_length) * signal_trigger_mult
buy_signal_longStop = (buy_signal_use_close ? ta.highest(signalClose, buy_signal_length) : ta.highest(signalHigh, buy_signal_length)) - buy_signal_atr
buy_signal_longStopPrev = nz(buy_signal_longStop[1], buy_signal_longStop)
buy_signal_longStop := signalClose[1] > buy_signal_longStopPrev ? math.max(buy_signal_longStop, buy_signal_longStopPrev) : buy_signal_longStop
buy_signal_shortStop = (buy_signal_use_close ? ta.lowest(signalClose, buy_signal_length) : ta.lowest(signalLow, buy_signal_length)) + buy_signal_atr
buy_signal_shortStopPrev = nz(buy_signal_shortStop[1], buy_signal_shortStop)
buy_signal_shortStop := signalClose[1] < buy_signal_shortStopPrev ? math.min(buy_signal_shortStop, buy_signal_shortStopPrev) : buy_signal_shortStop
var int buy_signal_dir = 1
buy_signal_dir := signalClose > buy_signal_shortStopPrev ? 1 : signalClose < buy_signal_longStopPrev ? -1 : buy_signal_dir
buy_signal_buySignal := buy_signal_dir == 1 and buy_signal_dir[1] == -1
// ============================================================================
// BUY ATR STOP
// ============================================================================
buy_atr_atr = ta.atr(buy_atr_length) * stop_atr_mult
buy_atr_longStop := (buy_atr_use_close ? ta.highest(signalClose, buy_atr_length) : ta.highest(signalHigh, buy_atr_length)) - buy_atr_atr
buy_atr_longStopPrev = nz(buy_atr_longStop[1], buy_atr_longStop)
buy_atr_longStop := signalClose[1] > buy_atr_longStopPrev ? math.max(buy_atr_longStop, buy_atr_longStopPrev) : buy_atr_longStop
buy_atr_shortStop = (buy_atr_use_close ? ta.lowest(signalClose, buy_atr_length) : ta.lowest(signalLow, buy_atr_length)) + buy_atr_atr
buy_atr_shortStopPrev = nz(buy_atr_shortStop[1], buy_atr_shortStop)
buy_atr_shortStop := signalClose[1] < buy_atr_shortStopPrev ? math.min(buy_atr_shortStop, buy_atr_shortStopPrev) : buy_atr_shortStop
var int buy_atr_dir = 1
buy_atr_dir := signalClose > buy_atr_shortStopPrev ? 1 : signalClose < buy_atr_longStopPrev ? -1 : buy_atr_dir
buy_atr_sellSignal := buy_atr_dir == -1 and buy_atr_dir[1] == 1
// ============================================================================
// SELL SIGNAL
// ============================================================================
sell_signal_atr = ta.atr(sell_signal_length) * signal_trigger_mult
sell_signal_longStop = (sell_signal_use_close ? ta.highest(signalClose, sell_signal_length) : ta.highest(signalHigh, sell_signal_length)) - sell_signal_atr
sell_signal_longStopPrev = nz(sell_signal_longStop[1], sell_signal_longStop)
sell_signal_longStop := signalClose[1] > sell_signal_longStopPrev ? math.max(sell_signal_longStop, sell_signal_longStopPrev) : sell_signal_longStop
sell_signal_shortStop = (sell_signal_use_close ? ta.lowest(signalClose, sell_signal_length) : ta.lowest(signalLow, sell_signal_length)) + sell_signal_atr
sell_signal_shortStopPrev = nz(sell_signal_shortStop[1], sell_signal_shortStop)
sell_signal_shortStop := signalClose[1] < sell_signal_shortStopPrev ? math.min(sell_signal_shortStop, sell_signal_shortStopPrev) : sell_signal_shortStop
var int sell_signal_dir = 1
sell_signal_dir := signalClose > sell_signal_shortStopPrev ? 1 : signalClose < sell_signal_longStopPrev ? -1 : sell_signal_dir
sell_signal_sellSignal := sell_signal_dir == -1 and sell_signal_dir[1] == 1
// ============================================================================
// SELL ATR STOP
// ============================================================================
sell_atr_atr = ta.atr(sell_atr_length) * stop_atr_mult
sell_atr_longStop = (sell_atr_use_close ? ta.highest(signalClose, sell_atr_length) : ta.highest(signalHigh, sell_atr_length)) - sell_atr_atr
sell_atr_longStopPrev = nz(sell_atr_longStop[1], sell_atr_longStop)
sell_atr_longStop := signalClose[1] > sell_atr_longStopPrev ? math.max(sell_atr_longStop, sell_atr_longStopPrev) : sell_atr_longStop
sell_atr_shortStop := (sell_atr_use_close ? ta.lowest(signalClose, sell_atr_length) : ta.lowest(signalLow, sell_atr_length)) + sell_atr_atr
sell_atr_shortStopPrev = nz(sell_atr_shortStop[1], sell_atr_shortStop)
sell_atr_shortStop := signalClose[1] < sell_atr_shortStopPrev ? math.min(sell_atr_shortStop, sell_atr_shortStopPrev) : sell_atr_shortStop
var int sell_atr_dir = 1
sell_atr_dir := signalClose > sell_atr_shortStopPrev ? 1 : signalClose < sell_atr_longStopPrev ? -1 : sell_atr_dir
sell_atr_buySignal := sell_atr_dir == 1 and sell_atr_dir[1] == -1
// ============================================================================
// SIGNAL STATE MANAGEMENT
// ============================================================================
if not buy_atr_stop_active
if buy_signal_buySignal
buy_atr_stop_active := true
else
if buy_atr_sellSignal
buy_atr_stop_active := false
if not sell_atr_stop_active
if sell_signal_sellSignal
sell_atr_stop_active := true
else
if sell_atr_buySignal
sell_atr_stop_active := false
// ===========================================================================================================
// CORE CALCULATIONS
// ===========================================================================================================
// AMF Calculations
amf_line = f_calculate_amf(signalClose, amf_length, amf_fast_length, amf_slow_length, amf_smoothing)
amf_signal = f_amf_signal(amf_line, amf_signal_length)
// Cached ATR
atr14 = ta.atr(14)
// ALMA calculations for neural network (Use Signal Candles for analysis)
alma200 = ta.alma(signalClose, almaLength, almaOffset, almaSigma)
alma2 = ta.alma(signalClose, alma2Length, alma2Offset, alma2Sigma)
// ===========================================================================================================
// NEURAL NETWORK
// ===========================================================================================================
is_buy_signal = buy_signal_buySignal
is_sell_signal = sell_signal_sellSignal
amf_context = f_analyzeAMF(amf_line, amf_signal, is_buy_signal, is_sell_signal, atr14)
alma_context = f_analyzeALMA(alma200, alma2, is_buy_signal, is_sell_signal, atr14)
sr_context = f_analyzeSupportResistance(is_buy_signal, is_sell_signal, atr14, signalHigh, signalLow, signalClose)
swing_context = f_analyzeSwingStructure(is_buy_signal, is_sell_signal, signalHigh, signalLow)
regime_context = f_analyzeMarketRegime(is_buy_signal, is_sell_signal, signalOpen, signalHigh, signalLow, signalClose)
amf_context_normalized = f_normalizeInput(amf_context, normalization_lookback, outlier_clipping, clipping_threshold)
alma_context_normalized = f_normalizeInput(alma_context, normalization_lookback, outlier_clipping, clipping_threshold)
sr_context_normalized = f_normalizeInput(sr_context, normalization_lookback, outlier_clipping, clipping_threshold)
swing_context_normalized = f_normalizeInput(swing_context, normalization_lookback, outlier_clipping, clipping_threshold)
regime_context_normalized = f_normalizeInput(regime_context, normalization_lookback, outlier_clipping, clipping_threshold)
signal_score = (is_buy_signal or is_sell_signal) ?
f_scoreSignalNormalized(amf_context_normalized, alma_context_normalized,
sr_context_normalized, swing_context_normalized, regime_context_normalized) : 0.5
signal_grade = f_getSignalGrade(signal_score)
score_color = f_getScoreColor(signal_score)
// ===========================================================================================================
// CANDLE PLOTTING
// ===========================================================================================================
candleColor = isBullishCandle ? customBuyColor : customSellColor
plotcandle(candleType != 'Candlesticks' ? displayOpen : na,
candleType != 'Candlesticks' ? displayHigh : na,
candleType != 'Candlesticks' ? displayLow : na,
candleType != 'Candlesticks' ? displayClose : na,
title = 'BAR',
color = candleType != 'Candlesticks' ? candleColor : na,
wickcolor = candleType != 'Candlesticks' ? candleColor : na,
bordercolor = candleType != 'Candlesticks' ? candleColor : na)
// ===========================================================================================================
/////////////////////////////////////////////////////////////////////
// ================= User Inputs =================
Periods = input.int(10, title="ATR Period", minval=1)
src23 = input.source(close, title="Source")
Multiplier = input.float(5.7, title="ATR Multiplier")
changeATR = input.bool(true, title="Use True ATR?")
showsignals = input.bool(true, title="Show Buy/Sell Signals")
highlighting = input.bool(true, title="Enable Trend Highlighting")
// ================= ATR Calculation =================
atr2 = ta.sma(ta.tr, Periods)
atr = changeATR ? ta.atr(Periods) : atr2
// ================= Trend Calculation =================
up = src23 - (Multiplier * atr)
up1 = nz(up[1], up)
up := close[1] > up1 ? math.max(up, up1) : up
dn = src23 + (Multiplier * atr)
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? math.min(dn, dn1) : dn
var int trend23 = 1
trend23 := trend23 == -1 and close > dn1 ? 1 : trend23 == 1 and close < up1 ? -1 : trend23
// ================= Plotting Up/Down Trend Lines =================
upPlot = plot(trend23 == 1 ? up : na, title="ATRX", style=plot.style_linebr, linewidth=1, color=color.rgb(4, 255, 12))
dnPlot = plot(trend23 == -1 ? dn : na, title="ATRY", style=plot.style_linebr, linewidth=1, color=color.red)
// ================= Buy/Sell Signals =================
//buySignal = trend == 1 and trend[1] == -1
//sellSignal = trend == -1 and trend[1] == 1
//plotshape(buySignal and showsignals ? up : na, title="Buy", text="A", style=shape.labelup, location=location.bottom, size=size.small, color=#ffbf00, textcolor=color.black)
//plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="S", location=location.top, style=shape.labeldown, size=size.small, color=#ffbf00, textcolor=color.black)
16.07.2024 - 10.12.2024 https://chatgpt.com/g/g-uib6qYHGw-tr...ipt-v5-creator
Yer İmleri