PHP Code:
//@version=6
indicator('..', overlay = false, max_lines_count = 500, max_boxes_count = 500, max_bars_back = 500)
/////////////////////
// KAMA PARAMETERS
// ============================================================================
kama1_length = input.int(2, 'KAMA 1 Length', minval = 1, group = 'KAMA Settings')
kama1_fast = input.int(1, 'KAMA 1 Fast Length', minval = 1, group = 'KAMA Settings')
kama1_slow = input.int(3, 'KAMA 1 Slow Length', minval = 1, group = 'KAMA Settings')
kama2_length = input.int(3, 'KAMA 2 Length', minval = 1, group = 'KAMA Settings')
kama2_fast = input.int(2, 'KAMA 2 Fast Length', minval = 1, group = 'KAMA Settings')
kama2_slow = input.int(4, 'KAMA 2 Slow Length', minval = 1, group = 'KAMA Settings')
kama3_length = input.int(4, 'KAMA 3 Length', minval = 1, group = 'KAMA Settings')
kama3_fast = input.int(3, 'KAMA 3 Fast Length', minval = 1, group = 'KAMA Settings')
kama3_slow = input.int(5, 'KAMA 3 Slow Length', minval = 1, group = 'KAMA Settings')
kama4_length = input.int(5, 'KAMA 4 Length', minval = 1, group = 'KAMA Settings')
kama4_fast = input.int(4, 'KAMA 4 Fast Length', minval = 1, group = 'KAMA Settings')
kama4_slow = input.int(6, 'KAMA 4 Slow Length', minval = 1, group = 'KAMA Settings')
kama5_length = input.int(6, 'KAMA 5 Length', minval = 1, group = 'KAMA Settings')
kama5_fast = input.int(7, 'KAMA 5 Fast Length', minval = 1, group = 'KAMA Settings')
kama5_slow = input.int(8, 'KAMA 5 Slow Length', minval = 1, group = 'KAMA Settings')
src874 = input.source(close, 'Source', group = 'KAMA Settings')
// ============================================================================
// TREND COLORING PARAMETERS
// ============================================================================
color color_bearish_price_state = input.color(color.rgb(2, 243, 251, 00), 'Bearish Trend', group = 'Colors')
color color_bullish_price_state = input.color(color.rgb(241, 247, 248, 00), 'Bullish Trend', group = 'Colors')
color color_bullish_resistance_state = input.color(color.rgb(243, 3, 3, 00), 'Bullish Resistance', group = 'Colors')
color color_bearish_support_state = input.color(color.rgb(226, 247, 2, 00), 'Bearish Support', group = 'Colors')
float atr_multiplier_gray = input.float(14, 'ATR Multiplier (Gray Zone)', minval = 0.1, group = 'Ribbon Settings')
float atr_multiplier_yellow = input.float(14, 'ATR Multiplier (Yellow Zone)', minval = 0.1, group = 'Ribbon Settings')
// ============================================================================
// KAMA CALCULATION FUNCTION
// ============================================================================
f_kama(float src874, int length, int fastLength, int slowLength) =>
mom = math.abs(ta.change(src874, length))
volatility = math.sum(math.abs(ta.change(src874)), length)
er = volatility != 0 ? mom / volatility : 0
fastAlpha = 2 / (fastLength + 1)
slowAlpha = 2 / (slowLength + 1)
alpha = math.pow(er * (fastAlpha - slowAlpha) + slowAlpha, 2)
var float kama = na
kama := alpha * src874 + (1 - alpha) * nz(kama[1], src874)
kama
// ============================================================================
// CALCULATE ALL KAMAS
// ============================================================================
float kama1 = f_kama(src874, kama1_length, kama1_fast, kama1_slow)
float kama2 = f_kama(src874, kama2_length, kama2_fast, kama2_slow)
float kama3 = f_kama(src874, kama3_length, kama3_fast, kama3_slow)
float kama4 = f_kama(src874, kama4_length, kama4_fast, kama4_slow)
float kama5 = f_kama(src874, kama5_length, kama5_fast, kama5_slow)
// ============================================================================
// KAMA STACK RIBBON LOGIC (Replaces SMA Stack)
// ============================================================================
bool is_bullish_stack = kama1 > kama2 and kama2 > kama3 and kama3 > kama4 and kama4 > kama5
bool is_bearish_stack = kama1 < kama2 and kama2 < kama3 and kama3 < kama4 and kama4 < kama5
float atr_gray = ta.atr(14) * atr_multiplier_gray
float atr_yellow = ta.atr(14) * atr_multiplier_yellow
float kama_spread = math.abs(kama1 - kama5)
bool is_narrowing_gray = not is_bullish_stack and not is_bearish_stack and kama_spread < atr_gray
bool is_narrowing_yellow = not is_bullish_stack and not is_bearish_stack and kama_spread < atr_yellow
var bool was_bullish_stack = false
var bool was_bearish_stack = false
was_bullish_stack := is_bullish_stack ? true : is_bearish_stack ? false : was_bullish_stack
was_bearish_stack := is_bearish_stack ? true : is_bullish_stack ? false : was_bearish_stack
// ============================================================================
color kama_ribbon_color = is_bearish_stack ? color_bearish_price_state : is_narrowing_yellow and not was_bullish_stack ? color_bearish_support_state : is_narrowing_gray and was_bullish_stack ? color_bullish_resistance_state : is_bullish_stack ? color_bullish_price_state : na
// ============================================================================
plotcandle(open, high, low, close, color = kama_ribbon_color, wickcolor = kama_ribbon_color, bordercolor = kama_ribbon_color, title = 'BAR')
////////////////BU KODUN SONUDUR.///////////////
len985 = input.int(100, title = 'len985', minval = 1, maxval = 166, group = 'Advanced Donchian Channel')
fut_tog = input.bool(true, title = 'Plot Future Lines?')
color1 = input.color(color.rgb(7, 245, 126, 100), title = '', inline = '1', group = 'Colors')
color2 = input.color(color.rgb(229, 255, 0, 100), title = '', inline = '1', group = 'Colors')
color3 = input.color(color.rgb(255, 3, 62, 100), title = '', inline = '1', group = 'Colors')
highst = ta.highest(high, len985)
lowst = ta.lowest(low, len985)
mean985 = math.avg(highst, lowst)
highbar = ta.barssince(high == highst)
lowbar = ta.barssince(low == lowst)
dir985 = highbar > lowbar ? 2 : lowbar > highbar ? 1 : 0
var fut_lines = array.new_line(na)
if array.size(fut_lines) > 0
for i = 0 to array.size(fut_lines) - 1 by 1
line.delete(array.get(fut_lines, i))
array.clear(fut_lines)
if fut_tog
for i = len985 to 2 by 1
low1 = ta.lowest(low, i)
low2 = ta.lowest(low, i - 1)
high1 = ta.highest(high, i)
high2 = ta.highest(high, i - 1)
array.push(fut_lines, line.new(bar_index + len985 - i, high1, bar_index + len985 - i + 1, high2, color = color1, style = line.style_dotted))
array.push(fut_lines, line.new(bar_index + len985 - i, math.avg(high1, low1), bar_index + len985 - i + 1, math.avg(high2, low2), color = color2, style = line.style_dotted))
array.push(fut_lines, line.new(bar_index + len985 - i, low1, bar_index + len985 - i + 1, low2, color = color3, style = line.style_dotted))
//PLOTS
plot(highst, title = 'Tepe', color = color1, linewidth = 2, editable = false)
plot(mean985, title = 'Dnge', color = color2, linewidth = 1, editable = false)
plot(lowst, title = 'Dip', color = color3, linewidth = 2, editable = false)
//ALERTS////////////////////////////////////////////////////////////////////////
up985 = (close <= mean985)[1] and close > mean985
down985 = (close >= mean985)[1] and close < mean985
alertcondition(up985, 'Close Over mean985')
alertcondition(down985, 'Close Under mean985')
//////////////////////////////////////////
// Global Settings
chartTimeframe = input.int(title = 'Chart Timeframe (minutes)', defval = 1, minval = 1, maxval = 60, group = 'Global Settings')
labelPosition = input.float(title = 'Label Position', defval = 0.4, minval = -2.0, maxval = 2.0, group = 'Global Settings')
// Candle 1 Settings (30min)
enableCandle1 = input.bool(title = 'Enable Candle 1', defval = true, group = 'Candle 1 Settings')
lookbackMinutes1 = input.int(title = 'Candle 1 Time Period (minutes)', defval = 15, minval = 1, maxval = 1440, group = 'Candle 1 Settings')
offsetBars1 = input.int(title = 'Offset (bars) for Candle 1', defval = 2, minval = 1, maxval = 500, group = 'Candle 1 Settings')
showLookbackLine1 = input.bool(title = 'Show Lookback Line (Candle 1)', defval = true, group = 'Candle 1 Settings')
lookbackLineWidth1 = input.int(title = 'Lookback Line Width (Candle 1)', defval = 1, minval = 1, maxval = 10, group = 'Candle 1 Settings')
lookbackLineColor1 = input.color(title = 'Lookback Line Color (Candle 1)', defval = color.rgb(0, 188, 212), group = 'Candle 1 Settings')
lookbackLineStyle1 = input.string(title = 'Lookback Line Style (Candle 1)', defval = 'dotted', options = ['solid', 'dotted', 'dashed'], group = 'Candle 1 Settings')
showHighLow1 = input.bool(title = 'Show Lookback High & Low (Candle 1)', defval = true, group = 'Candle 1 Settings')
highLowColor1 = input.color(title = 'Lookback H/L Lines Color (Candle 1)', defval = color.rgb(0, 188, 212), group = 'Candle 1 Settings')
highLowStyle1 = input.string(title = 'Lookback H/L Lines Style (Candle 1)', defval = 'dotted', options = ['solid', 'dotted', 'dashed'], group = 'Candle 1 Settings')
//showLabel1 = input.bool(title = 'Show Label (Candle 1)', defval = true, group = 'Candle 1 Settings')
//labelColor1 = input.color(title = 'Label Color (Candle 1)', defval = color.rgb(0, 188, 212), group = 'Candle 1 Settings')
// Candle 2 Settings (1hr)
enableCandle2 = input.bool(title = 'Enable Candle 2', defval = true, group = 'Candle 2 Settings')
lookbackMinutes2 = input.int(title = 'Candle 2 Time Period (minutes)', defval = 30, minval = 1, maxval = 1440, group = 'Candle 2 Settings')
offsetBars2 = input.int(title = 'Offset (bars) for Candle 2', defval = 2, minval = 1, maxval = 500, group = 'Candle 2 Settings')
showLookbackLine2 = input.bool(title = 'Show Lookback Line (Candle 2)', defval = true, group = 'Candle 2 Settings')
lookbackLineWidth2 = input.int(title = 'Lookback Line Width (Candle 2)', defval = 1, minval = 1, maxval = 10, group = 'Candle 2 Settings')
lookbackLineColor2 = input.color(title = 'Lookback Line Color (Candle 2)', defval = color.rgb(0, 188, 212), group = 'Candle 2 Settings')
lookbackLineStyle2 = input.string(title = 'Lookback Line Style (Candle 2)', defval = 'dotted', options = ['solid', 'dotted', 'dashed'], group = 'Candle 2 Settings')
showHighLow2 = input.bool(title = 'Show Lookback High & Low (Candle 2)', defval = true, group = 'Candle 2 Settings')
highLowColor2 = input.color(title = 'Lookback H/L Lines Color (Candle 2)', defval = color.rgb(0, 188, 212), group = 'Candle 2 Settings')
highLowStyle2 = input.string(title = 'Lookback H/L Lines Style (Candle 2)', defval = 'dotted', options = ['solid', 'dotted', 'dashed'], group = 'Candle 2 Settings')
//showLabel2 = input.bool(title = 'Show Label (Candle 2)', defval = true, group = 'Candle 2 Settings')
//labelColor2 = input.color(title = 'Label Color (Candle 2)', defval = color.rgb(233, 30, 99), group = 'Candle 2 Settings')
// Candle 3 Settings (2hr)
enableCandle3 = input.bool(title = 'Enable Candle 3', defval = true, group = 'Candle 3 Settings')
lookbackMinutes3 = input.int(title = 'Candle 3 Time Period (minutes)', defval = 45, minval = 1, maxval = 1440, group = 'Candle 3 Settings')
offsetBars3 = input.int(title = 'Offset (bars) for Candle 3', defval = 2, minval = 1, maxval = 500, group = 'Candle 3 Settings')
showLookbackLine3 = input.bool(title = 'Show Lookback Line (Candle 3)', defval = true, group = 'Candle 3 Settings')
lookbackLineWidth3 = input.int(title = 'Lookback Line Width (Candle 3)', defval = 2, minval = 1, maxval = 10, group = 'Candle 3 Settings')
lookbackLineColor3 = input.color(title = 'Lookback Line Color (Candle 3)', defval = color.rgb(240, 239, 244), group = 'Candle 3 Settings')
lookbackLineStyle3 = input.string(title = 'Lookback Line Style (Candle 3)', defval = 'dotted', options = ['solid', 'dotted', 'dashed'], group = 'Candle 3 Settings')
showHighLow3 = input.bool(title = 'Show Lookback High & Low (Candle 3)', defval = true, group = 'Candle 3 Settings')
highLowColor3 = input.color(title = 'Lookback H/L Lines Color (Candle 3)', defval = color.rgb(240, 239, 244), group = 'Candle 3 Settings')
highLowStyle3 = input.string(title = 'Lookback H/L Lines Style (Candle 3)', defval = 'dotted', options = ['solid', 'dotted', 'dashed'], group = 'Candle 3 Settings')
//showLabel3 = input.bool(title = 'Show Label (Candle 3)', defval = true, group = 'Candle 3 Settings')
//labelColor3 = input.color(title = 'Label Color (Candle 3)', defval = color.rgb(132, 100, 247), group = 'Candle 3 Settings')
// Candle 4 Settings (4hr)
enableCandle4 = input.bool(title = 'Enable Candle 4', defval = true, group = 'Candle 4 Settings')
lookbackMinutes4 = input.int(title = 'Candle 4 Time Period (minutes)', defval = 60, minval = 1, maxval = 1440, group = 'Candle 4 Settings')
offsetBars4 = input.int(title = 'Offset (bars) for Candle 4', defval = 2, minval = 1, maxval = 500, group = 'Candle 4 Settings')
showLookbackLine4 = input.bool(title = 'Show Lookback Line (Candle 4)', defval = true, group = 'Candle 4 Settings')
lookbackLineWidth4 = input.int(title = 'Lookback Line Width (Candle 4)', defval = 1, minval = 1, maxval = 10, group = 'Candle 4 Settings')
lookbackLineColor4 = input.color(title = 'Lookback Line Color (Candle 4)', defval = color.rgb(255, 152, 0), group = 'Candle 4 Settings')
lookbackLineStyle4 = input.string(title = 'Lookback Line Style (Candle 4)', defval = 'dotted', options = ['solid', 'dotted', 'dashed'], group = 'Candle 4 Settings')
showHighLow4 = input.bool(title = 'Show Lookback High & Low (Candle 4)', defval = true, group = 'Candle 4 Settings')
highLowColor4 = input.color(title = 'Lookback H/L Lines Color (Candle 4)', defval = color.rgb(255, 152, 0), group = 'Candle 4 Settings')
highLowStyle4 = input.string(title = 'Lookback H/L Lines Style (Candle 4)', defval = 'dotted', options = ['solid', 'dotted', 'dashed'], group = 'Candle 4 Settings')
//showLabel4 = input.bool(title = 'Show Label (Candle 4)', defval = true, group = 'Candle 4 Settings')
//labelColor4 = input.color(title = 'Label Color (Candle 4)', defval = color.rgb(255, 152, 0), group = 'Candle 4 Settings')
// Candle 5 Settings (12hr)
enableCandle5 = input.bool(title = 'Enable Candle 5', defval = true, group = 'Candle 5 Settings')
lookbackMinutes5 = input.int(title = 'Candle 5 Time Period (minutes)', defval = 90, minval = 1, maxval = 1440, group = 'Candle 5 Settings')
offsetBars5 = input.int(title = 'Offset (bars) for Candle 5', defval = 2, minval = 1, maxval = 500, group = 'Candle 5 Settings')
showLookbackLine5 = input.bool(title = 'Show Lookback Line (Candle 5)', defval = true, group = 'Candle 5 Settings')
lookbackLineWidth5 = input.int(title = 'Lookback Line Width (Candle 5)', defval = 1, minval = 1, maxval = 10, group = 'Candle 5 Settings')
lookbackLineColor5 = input.color(title = 'Lookback Line Color (Candle 5)', defval = color.rgb(255, 152, 0), group = 'Candle 5 Settings')
lookbackLineStyle5 = input.string(title = 'Lookback Line Style (Candle 5)', defval = 'dotted', options = ['solid', 'dotted', 'dashed'], group = 'Candle 5 Settings')
showHighLow5 = input.bool(title = 'Show Lookback High & Low (Candle 5)', defval = true, group = 'Candle 5 Settings')
highLowColor5 = input.color(title = 'Lookback H/L Lines Color (Candle 5)', defval = color.rgb(255, 152, 0), group = 'Candle 5 Settings')
highLowStyle5 = input.string(title = 'Lookback H/L Lines Style (Candle 5)', defval = 'dotted', options = ['solid', 'dotted', 'dashed'], group = 'Candle 5 Settings')
//showLabel5 = input.bool(title = 'Show Label (Candle 5)', defval = true, group = 'Candle 5 Settings')
//labelColor5 = input.color(title = 'Label Color (Candle 5)', defval = color.rgb(255, 87, 34), group = 'Candle 5 Settings')
// Function to format time period for label
formatTimePeriod(minutes) =>
if minutes >= 60
hours = math.floor(minutes / 60)
str.tostring(hours) + ' hrs'
else
str.tostring(minutes) + ' mins'
// Function to calculate the candle's elements
f_getCandleData(_lookbackMinutes) =>
periodsForLookback = _lookbackMinutes / chartTimeframe
periodHigh = ta.highest(high, int(periodsForLookback))
periodLow = ta.lowest(low, int(periodsForLookback))
firstPrice = close[int(periodsForLookback)]
lastPrice = close
colorCandle = lastPrice > firstPrice ? color.green : color.red
[periodHigh, periodLow, firstPrice, lastPrice, colorCandle]
// Get data for each candle
[periodHigh1, periodLow1, firstPrice1, lastPrice1, colorCandle1] = f_getCandleData(lookbackMinutes1)
[periodHigh2, periodLow2, firstPrice2, lastPrice2, colorCandle2] = f_getCandleData(lookbackMinutes2)
[periodHigh3, periodLow3, firstPrice3, lastPrice3, colorCandle3] = f_getCandleData(lookbackMinutes3)
[periodHigh4, periodLow4, firstPrice4, lastPrice4, colorCandle4] = f_getCandleData(lookbackMinutes4)
[periodHigh5, periodLow5, firstPrice5, lastPrice5, colorCandle5] = f_getCandleData(lookbackMinutes5)
// Calculate the highest point among all lookback periods
maxHigh = math.max(periodHigh1, math.max(periodHigh2, math.max(periodHigh3, math.max(periodHigh4, periodHigh5))))
minLow = math.min(periodLow1, math.min(periodLow2, math.min(periodLow3, math.min(periodLow4, periodLow5))))
labelHeight = maxHigh + (maxHigh - minLow) * labelPosition
// Define variables with types and initialize with `na`
var line bodyLine1 = na
var line highWick1 = na
var line lookbackLine1 = na
var line highLine1 = na
var line lowLine1 = na
var label lookbackLabel1 = na
var line bodyLine2 = na
var line highWick2 = na
var line lookbackLine2 = na
var line highLine2 = na
var line lowLine2 = na
var label lookbackLabel2 = na
var line bodyLine3 = na
var line highWick3 = na
var line lookbackLine3 = na
var line highLine3 = na
var line lowLine3 = na
var label lookbackLabel3 = na
var line bodyLine4 = na
var line highWick4 = na
var line lookbackLine4 = na
var line highLine4 = na
var line lowLine4 = na
var label lookbackLabel4 = na
var line bodyLine5 = na
var line highWick5 = na
var line lookbackLine5 = na
var line highLine5 = na
var line lowLine5 = na
var label lookbackLabel5 = na
// Delete previous lines and labels if they exist
if not na(bodyLine1)
line.delete(bodyLine1)
if not na(highWick1)
line.delete(highWick1)
if not na(lookbackLine1)
line.delete(lookbackLine1)
if not na(highLine1)
line.delete(highLine1)
if not na(lowLine1)
line.delete(lowLine1)
if not na(lookbackLabel1)
label.delete(lookbackLabel1)
if not na(bodyLine2)
line.delete(bodyLine2)
if not na(highWick2)
line.delete(highWick2)
if not na(lookbackLine2)
line.delete(lookbackLine2)
if not na(highLine2)
line.delete(highLine2)
if not na(lowLine2)
line.delete(lowLine2)
if not na(lookbackLabel2)
label.delete(lookbackLabel2)
if not na(bodyLine3)
line.delete(bodyLine3)
if not na(highWick3)
line.delete(highWick3)
if not na(lookbackLine3)
line.delete(lookbackLine3)
if not na(highLine3)
line.delete(highLine3)
if not na(lowLine3)
line.delete(lowLine3)
if not na(lookbackLabel3)
label.delete(lookbackLabel3)
if not na(bodyLine4)
line.delete(bodyLine4)
if not na(highWick4)
line.delete(highWick4)
if not na(lookbackLine4)
line.delete(lookbackLine4)
if not na(highLine4)
line.delete(highLine4)
if not na(lowLine4)
line.delete(lowLine4)
if not na(lookbackLabel4)
label.delete(lookbackLabel4)
if not na(bodyLine5)
line.delete(bodyLine5)
if not na(highWick5)
line.delete(highWick5)
if not na(lookbackLine5)
line.delete(lookbackLine5)
if not na(highLine5)
line.delete(highLine5)
if not na(lowLine5)
line.delete(lowLine5)
if not na(lookbackLabel5)
label.delete(lookbackLabel5)
// Calculate the starting bar index for the lookback period for each candle
lookbackBars1 = int(lookbackMinutes1 / chartTimeframe)
lookbackBars2 = int(lookbackMinutes2 / chartTimeframe)
lookbackBars3 = int(lookbackMinutes3 / chartTimeframe)
lookbackBars4 = int(lookbackMinutes4 / chartTimeframe)
lookbackBars5 = int(lookbackMinutes5 / chartTimeframe)
// Draw the candle for each period
x1 = bar_index + offsetBars1
x2 = bar_index + offsetBars2
x3 = bar_index + offsetBars3
x4 = bar_index + offsetBars4
x5 = bar_index + offsetBars5
// Calculate minute changes outside of conditional statements
var bool minuteChanged = false
minuteChanged := ta.change(time('1')) != 0
// Calculate color changes for each candle
var bool colorChanged1 = false
var bool colorChanged2 = false
var bool colorChanged3 = false
var bool colorChanged4 = false
var bool colorChanged5 = false
colorChanged1 := colorCandle1 != colorCandle1[1]
colorChanged2 := colorCandle2 != colorCandle2[1]
colorChanged3 := colorCandle3 != colorCandle3[1]
colorChanged4 := colorCandle4 != colorCandle4[1]
colorChanged5 := colorCandle5 != colorCandle5[1]
// Calculate if all candles are the same color
allSameColor = colorCandle1 == colorCandle2 and colorCandle2 == colorCandle3 and colorCandle3 == colorCandle4 and colorCandle4 == colorCandle5
// Alert conditions
alertcondition(colorChanged1, title = 'Candle 1 Color Change', message = 'Candle 1 (30min) color changed')
alertcondition(colorChanged2, title = 'Candle 2 Color Change', message = 'Candle 2 (1hr) color changed')
alertcondition(colorChanged3, title = 'Candle 3 Color Change', message = 'Candle 3 (2hr) color changed')
alertcondition(colorChanged4, title = 'Candle 4 Color Change', message = 'Candle 4 (4hr) color changed')
alertcondition(colorChanged5, title = 'Candle 5 Color Change', message = 'Candle 5 (12hr) color changed')
alertcondition(allSameColor, title = 'All Candles Same Color', message = 'All candles are the same color')
// Alert handling
if colorChanged1
currentColor = colorCandle1 == color.green ? 'GREEN' : 'RED'
previousColor = colorCandle1[1] == color.green ? 'GREEN' : 'RED'
alert('Candle 1 (30min) changed from ' + previousColor + ' to ' + currentColor, alert.freq_once_per_bar_close)
if colorChanged2
currentColor = colorCandle2 == color.green ? 'GREEN' : 'RED'
previousColor = colorCandle2[1] == color.green ? 'GREEN' : 'RED'
alert('Candle 2 (1hr) changed from ' + previousColor + ' to ' + currentColor, alert.freq_once_per_bar_close)
if colorChanged3
currentColor = colorCandle3 == color.green ? 'GREEN' : 'RED'
previousColor = colorCandle3[1] == color.green ? 'GREEN' : 'RED'
alert('Candle 3 (2hr) changed from ' + previousColor + ' to ' + currentColor, alert.freq_once_per_bar_close)
if colorChanged4
currentColor = colorCandle4 == color.green ? 'GREEN' : 'RED'
previousColor = colorCandle4[1] == color.green ? 'GREEN' : 'RED'
alert('Candle 4 (4hr) changed from ' + previousColor + ' to ' + currentColor, alert.freq_once_per_bar_close)
if colorChanged5
currentColor = colorCandle5 == color.green ? 'GREEN' : 'RED'
previousColor = colorCandle5[1] == color.green ? 'GREEN' : 'RED'
alert('Candle 5 (12hr) changed from ' + previousColor + ' to ' + currentColor, alert.freq_once_per_bar_close)
if allSameColor
colorMsg = colorCandle1 == color.green ? 'All candles are GREEN - Strong Bullish Signal' : 'All candles are RED - Strong Bearish Signal'
alert(colorMsg, alert.freq_once_per_bar_close)
// For Candle 5 (Draw first - will be at bottom)
if enableCandle5
bodyLine5 := line.new(x5, firstPrice5, x5, lastPrice5, color = colorCandle5, width = 24)
highWick5 := line.new(x5, periodHigh5, x5, periodLow5, color = colorCandle5, width = 2)
if showLookbackLine5
lookbackLine5 := line.new(bar_index - lookbackBars5, periodLow5, bar_index - lookbackBars5, periodHigh5, color = lookbackLineColor5, width = lookbackLineWidth5, style = lookbackLineStyle5 == 'solid' ? line.style_solid : lookbackLineStyle5 == 'dotted' ? line.style_dotted : line.style_dashed)
lookbackLine5
if showHighLow5
highLine5 := line.new(bar_index - lookbackBars5, periodHigh5, bar_index, periodHigh5, color = highLowColor5, width = lookbackLineWidth5, style = highLowStyle5 == 'solid' ? line.style_solid : highLowStyle5 == 'dotted' ? line.style_dotted : line.style_dashed)
lowLine5 := line.new(bar_index - lookbackBars5, periodLow5, bar_index, periodLow5, color = highLowColor5, width = lookbackLineWidth5, style = highLowStyle5 == 'solid' ? line.style_solid : highLowStyle5 == 'dotted' ? line.style_dotted : line.style_dashed)
lowLine5
//if showLabel5
//lookbackLabel5 := label.new(x5, labelHeight, text = formatTimePeriod(lookbackMinutes5), color = labelColor5, textcolor = color.black, style = label.style_label_up, size = size.normal)
//lookbackLabel5
// For Candle 4
if enableCandle4
bodyLine4 := line.new(x4, firstPrice4, x4, lastPrice4, color = colorCandle4, width = 24)
highWick4 := line.new(x4, periodHigh4, x4, periodLow4, color = colorCandle4, width = 2)
if showLookbackLine4
lookbackLine4 := line.new(bar_index - lookbackBars4, periodLow4, bar_index - lookbackBars4, periodHigh4, color = lookbackLineColor4, width = lookbackLineWidth4, style = lookbackLineStyle4 == 'solid' ? line.style_solid : lookbackLineStyle4 == 'dotted' ? line.style_dotted : line.style_dashed)
lookbackLine4
if showHighLow4
highLine4 := line.new(bar_index - lookbackBars4, periodHigh4, bar_index, periodHigh4, color = highLowColor4, width = lookbackLineWidth4, style = highLowStyle4 == 'solid' ? line.style_solid : highLowStyle4 == 'dotted' ? line.style_dotted : line.style_dashed)
lowLine4 := line.new(bar_index - lookbackBars4, periodLow4, bar_index, periodLow4, color = highLowColor4, width = lookbackLineWidth4, style = highLowStyle4 == 'solid' ? line.style_solid : highLowStyle4 == 'dotted' ? line.style_dotted : line.style_dashed)
lowLine4
//if showLabel4
//lookbackLabel4 := label.new(x4, labelHeight, text = formatTimePeriod(lookbackMinutes4), color = labelColor4, textcolor = color.black, style = label.style_label_up, size = size.normal)
//lookbackLabel4
// For Candle 3
if enableCandle3
bodyLine3 := line.new(x3, firstPrice3, x3, lastPrice3, color = colorCandle3, width = 24)
highWick3 := line.new(x3, periodHigh3, x3, periodLow3, color = colorCandle3, width = 2)
if showLookbackLine3
lookbackLine3 := line.new(bar_index - lookbackBars3, periodLow3, bar_index - lookbackBars3, periodHigh3, color = lookbackLineColor3, width = lookbackLineWidth3, style = lookbackLineStyle3 == 'solid' ? line.style_solid : lookbackLineStyle3 == 'dotted' ? line.style_dotted : line.style_dashed)
lookbackLine3
if showHighLow3
highLine3 := line.new(bar_index - lookbackBars3, periodHigh3, bar_index, periodHigh3, color = highLowColor3, width = lookbackLineWidth3, style = highLowStyle3 == 'solid' ? line.style_solid : highLowStyle3 == 'dotted' ? line.style_dotted : line.style_dashed)
lowLine3 := line.new(bar_index - lookbackBars3, periodLow3, bar_index, periodLow3, color = highLowColor3, width = lookbackLineWidth3, style = highLowStyle3 == 'solid' ? line.style_solid : highLowStyle3 == 'dotted' ? line.style_dotted : line.style_dashed)
lowLine3
//if showLabel3
//lookbackLabel3 := label.new(x3, labelHeight, text = formatTimePeriod(lookbackMinutes3), color = labelColor3, textcolor = color.black, style = label.style_label_up, size = size.normal)
//lookbackLabel3
// For Candle 2
if enableCandle2
bodyLine2 := line.new(x2, firstPrice2, x2, lastPrice2, color = colorCandle2, width = 24)
highWick2 := line.new(x2, periodHigh2, x2, periodLow2, color = colorCandle2, width = 2)
if showLookbackLine2
lookbackLine2 := line.new(bar_index - lookbackBars2, periodLow2, bar_index - lookbackBars2, periodHigh2, color = lookbackLineColor2, width = lookbackLineWidth2, style = lookbackLineStyle2 == 'solid' ? line.style_solid : lookbackLineStyle2 == 'dotted' ? line.style_dotted : line.style_dashed)
lookbackLine2
if showHighLow2
highLine2 := line.new(bar_index - lookbackBars2, periodHigh2, bar_index, periodHigh2, color = highLowColor2, width = lookbackLineWidth2, style = highLowStyle2 == 'solid' ? line.style_solid : highLowStyle2 == 'dotted' ? line.style_dotted : line.style_dashed)
lowLine2 := line.new(bar_index - lookbackBars2, periodLow2, bar_index, periodLow2, color = highLowColor2, width = lookbackLineWidth2, style = highLowStyle2 == 'solid' ? line.style_solid : highLowStyle2 == 'dotted' ? line.style_dotted : line.style_dashed)
lowLine2
//if showLabel2
//lookbackLabel2 := label.new(x2, labelHeight, text = formatTimePeriod(lookbackMinutes2), color = labelColor2, textcolor = color.black, style = label.style_label_up, size = size.normal)
//lookbackLabel2
// For Candle 1 (Draw last - will be on top)
if enableCandle1
bodyLine1 := line.new(x1, firstPrice1, x1, lastPrice1, color = colorCandle1, width = 24)
highWick1 := line.new(x1, periodHigh1, x1, periodLow1, color = colorCandle1, width = 2)
if showLookbackLine1
lookbackLine1 := line.new(bar_index - lookbackBars1, periodLow1, bar_index - lookbackBars1, periodHigh1, color = lookbackLineColor1, width = lookbackLineWidth1, style = lookbackLineStyle1 == 'solid' ? line.style_solid : lookbackLineStyle1 == 'dotted' ? line.style_dotted : line.style_dashed)
lookbackLine1
if showHighLow1
highLine1 := line.new(bar_index - lookbackBars1, periodHigh1, bar_index, periodHigh1, color = highLowColor1, width = lookbackLineWidth1, style = highLowStyle1 == 'solid' ? line.style_solid : highLowStyle1 == 'dotted' ? line.style_dotted : line.style_dashed)
lowLine1 := line.new(bar_index - lookbackBars1, periodLow1, bar_index, periodLow1, color = highLowColor1, width = lookbackLineWidth1, style = highLowStyle1 == 'solid' ? line.style_solid : highLowStyle1 == 'dotted' ? line.style_dotted : line.style_dashed)
lowLine1
//if showLabel1
//lookbackLabel1 := label.new(x1, labelHeight, text = formatTimePeriod(lookbackMinutes1), color = labelColor1, textcolor = color.black, style = label.style_label_up, size = size.normal)
//lookbackLabel1
/////////@version=6
//note = input(defval = false, title = 'This Indicator Lags by twice your choice of timeframe.')
high_src = input(defval = high, title = 'High Source')
low_src = input(defval = low, title = 'Low Source')
timeframe = input(defval = '', title = 'ZigZag Timeframe:')
// || ZigZag
f_zigzag(_high, _low) =>
_is_up = _high > _high[1]
_is_down = _low < _low[1]
_trend = int(na)
_trend := nz(_trend[1], 0)
if _trend > 0 and _is_down
_trend := -1
_trend
if _trend < 0 and _is_up
_trend := +1
_trend
if _trend == 0
if _is_up
_trend := +1
_trend
else
_trend := -1
_trend
change_1 = ta.change(_trend)
_zigzag = ta.change(_trend) > 0 ? _low[1] : change_1 < 0 ? _high[1] : na
_zigzag
zigzag_src = request.security(syminfo.tickerid, timeframe, fixnan(f_zigzag(high_src, low_src)))
zigzag = ta.change(zigzag_src) != 0 ? zigzag_src : na
//plot(zigzag, color=black)
price_range = input(defval = 0.01, title = 'Price Range to use for GANN Box:')
time_range = input(defval = 24, title = 'Time Range in Bars to use for GANN Box:')
decay = price_range / time_range
f_bull_gann_line(_price_multiplier, _time_multiplier, _price_range, _time_range, _source) =>
_decay = _price_range * _price_multiplier / (_time_range * _time_multiplier)
_gann_line = float(na)
_gann_line := _gann_line[1] - _decay
if ta.change(_source) > 0
_gann_line := _source
_gann_line
_return = _gann_line
_return
f_bear_gann_line(_price_multiplier, _time_multiplier, _price_range, _time_range, _source) =>
_decay = _price_range * _price_multiplier / (_time_range * _time_multiplier)
_gann_line = float(na)
_gann_line := _gann_line[1] + _decay
if ta.change(_source) < 0
_gann_line := _source
_gann_line
_return = _gann_line
_return
//--------------------------------------------------
bull_gann_1_1 = f_bull_gann_line(1, 1, price_range, time_range, zigzag_src)
bull_gann_1_2 = f_bull_gann_line(1, 2, price_range, time_range, zigzag_src)
bull_gann_1_3 = f_bull_gann_line(1, 3, price_range, time_range, zigzag_src)
bull_gann_1_4 = f_bull_gann_line(1, 4, price_range, time_range, zigzag_src)
bull_gann_1_8 = f_bull_gann_line(1, 8, price_range, time_range, zigzag_src)
plot(series = ta.change(zigzag_src) > 0 ? na : bull_gann_1_1, title = 'FRC+', color = color.new(color.green, 100), linewidth = 1, style = plot.style_linebr)
//plot(series = ta.change(zigzag_src) > 0 ? na : bull_gann_1_2, title = '1/2', color = color.new(color.green, 0), linewidth = 2, style = plot.style_linebr)
//plot(series = ta.change(zigzag_src) > 0 ? na : bull_gann_1_3, title = '1/3', color = color.new(color.green, 0), linewidth = 3, style = plot.style_linebr)
//plot(series = ta.change(zigzag_src) > 0 ? na : bull_gann_1_4, title = '1/4', color = color.new(color.green, 0), linewidth = 2, style = plot.style_linebr)
//plot(series = ta.change(zigzag_src) > 0 ? na : bull_gann_1_8, title = '1/8', color = color.new(color.green, 0), linewidth = 1, style = plot.style_linebr)
bear_gann_1_1 = f_bear_gann_line(1, 1, price_range, time_range, zigzag_src)
bear_gann_1_2 = f_bear_gann_line(1, 2, price_range, time_range, zigzag_src)
bear_gann_1_3 = f_bear_gann_line(1, 3, price_range, time_range, zigzag_src)
bear_gann_1_4 = f_bear_gann_line(1, 4, price_range, time_range, zigzag_src)
bear_gann_1_8 = f_bear_gann_line(1, 8, price_range, time_range, zigzag_src)
plot(series = ta.change(zigzag_src) < 0 ? na : bear_gann_1_1, title = 'FRC-', color = color.new(color.maroon, 100), linewidth = 1, style = plot.style_linebr)
//plot(series = ta.change(zigzag_src) < 0 ? na : bear_gann_1_2, title = '1/2', color = color.new(color.maroon, 0), linewidth = 2, style = plot.style_linebr)
//plot(series = ta.change(zigzag_src) < 0 ? na : bear_gann_1_3, title = '1/3', color = color.new(color.maroon, 0), linewidth = 3, style = plot.style_linebr)
//plot(series = ta.change(zigzag_src) < 0 ? na : bear_gann_1_4, title = '1/4', color = color.new(color.maroon, 0), linewidth = 2, style = plot.style_linebr)
//plot(series = ta.change(zigzag_src) < 0 ? na : bear_gann_1_8, title = '1/8', color = color.new(color.maroon, 0), linewidth = 1, style = plot.style_linebr)
///////////////////
src777 = close
o777 = open
h777 = high
l777 = low
c777 = close
_indicator1 = (o777 - o777[1]) / o777[1]
_indicator2 = (h777 - h777[1]) / h777[1]
_indicator3 = (l777 - l777[1]) / l777[1]
_indicator4 = (c777 - c777[1]) / c777[1]
_indicator5 = (src777 - src777[1]) / src777[1]
// Inputs on Tangent Function :
tangentdiff(_src777) =>
nz((_src777 - _src777[1]) / _src777[1])
// Deep Learning Activation Function (Tanh) :
ActivationFunctionTanh(v) =>
(1 - math.exp(-2 * v)) / (1 + math.exp(-2 * v))
// DEEP LEARNING
// INPUTS :
input_1 = _indicator1
input_2 = _indicator2
input_3 = _indicator3
input_4 = _indicator4
// LAYERS :
// Input Layers
n_0 = ActivationFunctionTanh(input_1 + 0)
n_1 = ActivationFunctionTanh(input_2 + 0)
n_2 = ActivationFunctionTanh(input_3 + 0)
n_3 = ActivationFunctionTanh(input_4 + 0)
//
fun_open() =>
float _output = na
n_4 = ActivationFunctionTanh(0.030535 * n_0 + 5.113012 * n_1 + -26.085717 * n_2 + -5.320280 * n_3 + 7.354752)
n_5 = ActivationFunctionTanh(4.167948 * n_0 + 7.225875 * n_1 + -0.871215 * n_2 + -8.894535 * n_3 + -7.064751)
n_6 = ActivationFunctionTanh(-0.806293 * n_0 + -0.304470 * n_1 + -3.909741 * n_2 + -5.009985 * n_3 + 5.127558)
n_7 = ActivationFunctionTanh(-29.736063 * n_0 + 28.668433 * n_1 + 0.138417 * n_2 + -57.588543 * n_3 + 2.824914)
n_8 = ActivationFunctionTanh(-0.429393 * n_0 + 0.482744 * n_1 + -0.789797 * n_2 + -2.987460 * n_3 + -4.310747)
n_9 = ActivationFunctionTanh(1.758357 * n_0 + -0.618090 * n_1 + 2.449362 * n_2 + -1.583126 * n_3 + 1.165846)
_output := ActivationFunctionTanh(-0.653030 * n_4 + -4.646999 * n_5 + -1.678999 * n_6 + -17.077652 * n_7 + 0.875426 * n_8 + -6.672465 * n_9 + 6.940722)
_output
fun_high() =>
float _output = na
n_4 = ActivationFunctionTanh(10.186543 * n_0 + -30.964897 * n_1 + 21.672385 * n_2 + -40.895894 * n_3 + 7.957443)
n_5 = ActivationFunctionTanh(-15.252332 * n_0 + 14.845403 * n_1 + 10.621491 * n_2 + -23.817824 * n_3 + 2.947530)
n_6 = ActivationFunctionTanh(-15.179010 * n_0 + -30.011878 * n_1 + 35.650459 * n_2 + -61.480486 * n_3 + 3.898503)
n_7 = ActivationFunctionTanh(35.656454 * n_0 + -11.134354 * n_1 + -28.071578 * n_2 + 2.923959 * n_3 + -1.805703)
n_8 = ActivationFunctionTanh(3.462374 * n_0 + -13.644019 * n_1 + -30.226394 * n_2 + -1.083953 * n_3 + 23.032872)
n_9 = ActivationFunctionTanh(-47.265829 * n_0 + 19.021801 * n_1 + 10.565216 * n_2 + -27.520789 * n_3 + 6.947500)
_output := ActivationFunctionTanh(-0.696537 * n_4 + -1.349433 * n_5 + 27.262956 * n_6 + -1.042353 * n_7 + -0.540196 * n_8 + -10.735585 * n_9 + 1.303216)
_output
fun_low() =>
float _output = na
n_4 = ActivationFunctionTanh(4.363108 * n_0 + -18.301472 * n_1 + -15.376884 * n_2 + 21.208559 * n_3 + -0.458119)
n_5 = ActivationFunctionTanh(-2.651826 * n_0 + 5.205410 * n_1 + -5.920993 * n_2 + -4.847458 * n_3 + 8.315580)
n_6 = ActivationFunctionTanh(13.885322 * n_0 + -5.517922 * n_1 + -15.241118 * n_2 + -8.673229 * n_3 + -4.954015)
n_7 = ActivationFunctionTanh(10.490466 * n_0 + -25.201536 * n_1 + 10.262121 * n_2 + -1.116144 * n_3 + -5.254103)
n_8 = ActivationFunctionTanh(-14.687736 * n_0 + 9.030202 * n_1 + -17.332462 * n_2 + 8.068070 * n_3 + 0.755134)
n_9 = ActivationFunctionTanh(0.895168 * n_0 + -1.737740 * n_1 + 4.899143 * n_2 + -7.718495 * n_3 + 5.493688)
_output := ActivationFunctionTanh(4.132907 * n_4 + -17.501595 * n_5 + 4.617443 * n_6 + -28.476857 * n_7 + -5.888234 * n_8 + -24.434500 * n_9 + 41.318760)
_output
fun_close() =>
float _output = na
n_4 = ActivationFunctionTanh(22.427157 * n_0 + -26.691701 * n_1 + 4.937141 * n_2 + 9.034960 * n_3 + -10.692978)
n_5 = ActivationFunctionTanh(-38.288087 * n_0 + 10.050028 * n_1 + -44.706345 * n_2 + -17.816354 * n_3 + 30.566226)
n_6 = ActivationFunctionTanh(-33.995444 * n_0 + 14.501766 * n_1 + -43.286508 * n_2 + -13.387415 * n_3 + 24.708075)
n_7 = ActivationFunctionTanh(-14.392948 * n_0 + 28.483095 * n_1 + -22.979338 * n_2 + -7.658263 * n_3 + -5.650564)
n_8 = ActivationFunctionTanh(28.837901 * n_0 + -26.354494 * n_1 + 0.520683 * n_2 + 25.004913 * n_3 + -17.883236)
n_9 = ActivationFunctionTanh(-4.811354 * n_0 + -4.036420 * n_1 + -8.332775 * n_2 + -1.157164 * n_3 + 0.466793)
_output := ActivationFunctionTanh(-22.053311 * n_4 + 3.652552 * n_5 + -4.390465 * n_6 + 2.103060 * n_7 + 20.027285 * n_8 + 11.510129 * n_9 + -0.415015)
_output
// Current Open Values
_chg_open = tangentdiff(o777) * 100
_seed_open = (fun_open() - _chg_open) / 100
f_open = o777 * (1 - _seed_open)
// Current High Values
_chg_high = tangentdiff(h777) * 100
_seed_high = (fun_high() - _chg_high) / 100
f_high = h777 * (1 - _seed_high)
// Current Low Values
_chg_low = tangentdiff(l777) * 100
_seed_low = (fun_low() - _chg_low) / 100
f_low = l777 * (1 - _seed_low)
// Current Close Values
_chg_c = tangentdiff(c777) * 100
_seed_c = (fun_close() - _chg_c) / 100
f_close = c777 * (1 - _seed_c)
plotcandle(f_close, f_high, f_low, f_open, color = f_close > f_close[1] ? color.rgb(120, 123, 134, 85) : color.rgb(120, 123, 134, 85), wickcolor = #5d606b2d, title = "AI")
//////////////////////
// ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ INPUTS ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬
lenLR = input.int(4, 'Trend length (LR)', minval = 4, group = 'Trend & Volatility')
lenATR = input.int(14, 'ATR length', minval = 1, group = 'Trend & Volatility')
barsForward = input.int(5, 'Projection bars', minval = 3, maxval = 50, group = 'Trend & Volatility')
zoneMultQuiet = input.float(1.0, 'ATR-mult (quiet market)', minval = 0.1, group = 'Trend & Volatility')
zoneMultVol = input.float(2.0, 'ATR-mult (volatile market)', minval = 0.1, group = 'Trend & Volatility')
volThreshPc = input.float(1.5, 'High-vol threshold (% of price)', minval = 0.1, group = 'Trend & Volatility')
showInnerCone = input.bool(true, 'Show inner cone', group = 'Visuals')
showOuterCone = input.bool(true, 'Show outer cone (±2 ATR)', group = 'Visuals')
//showTrail = input.bool(true, 'Show trailing stop (mid-line end)', group = 'Visuals')
//bgRegime = input.bool(true, 'Paint background by regime', group = 'Visuals')
keepHistory = input.bool(false, 'Keep historical cones', group = 'Visuals')
slopeSens = input.float(1.0, 'Slope threshold for regime', minval = 0.01, group = 'Misc')
htf = input.timeframe('15', 'Source TF (blank = chart)', group = 'Misc')
// ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ HIGHER-TIMEFRAME SERIES ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬
tfUse = htf == '' ? timeframe.period : htf
price = request.security(syminfo.tickerid, tfUse, close, lookahead = barmerge.lookahead_on)
hiPrice = request.security(syminfo.tickerid, tfUse, high, lookahead = barmerge.lookahead_on)
atrSeries = request.security(syminfo.tickerid, tfUse, ta.atr(lenATR), lookahead = barmerge.lookahead_on)
// ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ CORE CALCULATION ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬
lrLine = ta.linreg(price, lenLR, 0)
slope = (lrLine - lrLine[lenLR]) / lenLR
atrPct = atrSeries / price
highVol = atrPct > volThreshPc / 100.0
zoneMult = highVol ? zoneMultVol : zoneMultQuiet
// Trend regime colouring
regime = slope > slopeSens ? 1 : slope < -slopeSens ? -1 : 0
regCol = regime == 1 ? color.lime : regime == -1 ? color.red : color.gray
// ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ CONE CO-ORDINATES ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬
upperBase = lrLine + zoneMult * atrSeries
lowerBase = lrLine - zoneMult * atrSeries
upperProj = upperBase + slope * barsForward
lowerProj = lowerBase + slope * barsForward
midProj = lrLine + slope * barsForward
// Optional outer (+/-2 ATR) cone
outerMult = 2.0
outUpBase = lrLine + outerMult * atrSeries
outLoBase = lrLine - outerMult * atrSeries
outUpProj = outUpBase + slope * barsForward
outLoProj = outLoBase + slope * barsForward
// ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ GRAPHIC HANDLES ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬
var line lUp = na
var line lLo = na
var line lMid = na
var linefill fInner = na
var line lOutUp = na
var line lOutLo = na
var label labStop = na
var int projStart = na
var float projLR = na
var float projSlope = na
var float projATR = na
var bool inCone = false
// ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ DRAW / UPDATE CONE ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬
if showInnerCone and (keepHistory or barstate.islast)
if not keepHistory and not na(lUp)
line.delete(lUp)
line.delete(lLo)
line.delete(lMid)
linefill.delete(fInner)
if showOuterCone
line.delete(lOutUp)
line.delete(lOutLo)
//if showTrail and not na(labStop)
//label.delete(labStop)
lUp := line.new(bar_index, upperBase, bar_index + barsForward, upperProj, color = color.lime, width = 1)
lLo := line.new(bar_index, lowerBase, bar_index + barsForward, lowerProj, color = color.red, width = 1)
lMid := line.new(bar_index, lrLine, bar_index + barsForward, midProj, color = color.yellow, style = line.style_dashed)
//fInner := linefill.new(lUp, lLo, color = color.new(color.blue, 85))
if showOuterCone
lOutUp := line.new(bar_index, outUpBase, bar_index + barsForward, outUpProj, color = color.new(color.lime, 00))
lOutLo := line.new(bar_index, outLoBase, bar_index + barsForward, outLoProj, color = color.new(color.red, 00))
lOutLo
// Store state for alert / in-cone test
projStart := bar_index
projLR := lrLine
projSlope := slope
projATR := atrSeries
// Trailing-stop marker
//if showTrail
// tPx = midProj
// tTxt = '@yörük @ ' + str.tostring(tPx, format.mintick)
//labStop := label.new(bar_index + barsForward, tPx, tTxt, style = label.style_label_left, color = regCol, textcolor = color.white, size = size.small)
//labStop
// ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ BACKGROUND SHADE ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬
//bgcolor(bgRegime ? color.new(regCol, 88) : na)
// ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ IN-CONE TEST & ALERTS ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬
if not na(projStart) and bar_index > projStart
steps = bar_index - projStart
if steps <= barsForward
upB = projLR + projSlope * steps + zoneMult * projATR
loB = projLR + projSlope * steps - zoneMult * projATR
inCone := price >= loB and price <= upB
inCone
else
inCone := false
inCone
else
inCone := false
inCone
alertcondition(inCone and not inCone[1], title = 'Entered cone', message = 'Price has entered the projection cone.')
alertcondition(regime != regime[1], title = 'Regime change', message = 'Trend regime has changed.')
// ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ DASHBOARD LABEL ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬
//if barstate.islast
//txt = 'Slope: ' + str.tostring(slope, '#.###') + '\nATR% : ' + str.tostring(atrPct * 100, '#.##') + '%\nRegime: ' + (regime == 1 ? 'Bull' : regime == -1 ? 'Bear' : 'Sideways')
//label.new(bar_index, hiPrice, txt, style = label.style_label_down, color = regCol, textcolor = color.white, size = size.small)
////////////////////
// Inputs for both projections
trial_count = input.int(100, title = 'Number of Trials', maxval = 1000, tooltip = 'Number of trials for both projections')
projection_length = input.int(5, title = 'Projection Length', minval = 1, maxval = 100, tooltip = 'Length of the projection lines for both projections')
// Inputs for first projection
lookback_period_1 = input.int(45, title = 'Lookback Period 1', maxval = 2000, tooltip = 'Lookback period for first projection')
color_projection_1 = input.color(color.blue, title = 'Color for Projection 1', tooltip = 'Set the color for the first projection')
direction_flip_1 = input.bool(false, title = 'Reverse Direction 1', tooltip = 'Invert the direction of movements for the first trials')
// Inputs for second projection
lookback_period_2 = input.int(90, title = 'Lookback Period 2', maxval = 2000, tooltip = 'Lookback period for second projection')
color_projection_2 = input.color(color.yellow, title = 'Color for Projection 2', tooltip = 'Set the color for the second projection')
direction_flip_2 = input.bool(false, title = 'Reverse Direction 2', tooltip = 'Invert the direction of movements for the second trials')
// Style settings for lookback areas
show_area = input(true, 'Show Lookback Areas', inline = 'area_style')
color_eval_area = input(color.new(color.red, 80), 'Lookback Period 1 Area Color', inline = 'area_style')
color_corr_area = input(color.new(color.blue, 80), 'Lookback Period 2 Area Color', inline = 'area_style')
// Function to reorder array for trials
reorder_array(data_array, seed) =>
rearranged_array = array.copy(data_array)
temp_array = array.copy(data_array)
for [idx, _] in rearranged_array
selected_index = math.abs((1664525 * seed + 1013904223) % temp_array.size())
rearranged_array.set(idx, array.get(temp_array, selected_index))
array.remove(temp_array, selected_index)
rearranged_array
// Variables for the first projection
var price_changes_1 = array.new_float(na) // Array to store price movements for first projection
price_variation_1 = close - open
array.push(price_changes_1, price_variation_1)
if array.size(price_changes_1) > lookback_period_1
array.shift(price_changes_1)
// Variables for the second projection
var price_changes_2 = array.new_float(na) // Array to store price movements for second projection
price_variation_2 = close - open
array.push(price_changes_2, price_variation_2)
if array.size(price_changes_2) > lookback_period_2
array.shift(price_changes_2)
// Define variables to store projection lines
var line projected_line_1 = na
var line projected_line_2 = na
// Draw lookback zones for projection 1 and projection 2 if show_area is enabled
if show_area
var box eval_area = na
var box corr_area = na
top = ta.highest(close, lookback_period_1 + lookback_period_2)
bottom = ta.lowest(close, lookback_period_1 + lookback_period_2)
// Lookback Period 1 Area
if na(eval_area) == false
box.delete(eval_area)
eval_area := box.new(bar_index - lookback_period_1, top, bar_index, bottom, bgcolor = color_eval_area)
// Lookback Period 2 Area
if na(corr_area) == false
box.delete(corr_area)
corr_area := box.new(bar_index - lookback_period_2, top, bar_index, bottom, bgcolor = color_corr_area)
corr_area
// Trial-based price projections for both projections
if barstate.islast
// First projection
trial_results_1 = array.new_float() // Array to store the results of the first trials
for i = 1 to trial_count by 1
rearranged_movements_1 = reorder_array(price_changes_1, i) // Reorder the price movements
future_price_1 = close
for price_variation_1 in rearranged_movements_1
future_price_1 := future_price_1 + (direction_flip_1 ? -price_variation_1 : price_variation_1) // Apply price movement
future_price_1
array.push(trial_results_1, future_price_1) // Store the final result of this trial
average_projection_1 = array.avg(trial_results_1) // Calculate the average projected price for first projection
// Remove previous line if exists
if na(projected_line_1) == false
line.delete(projected_line_1)
// Draw first projected path line
projected_line_1 := line.new(bar_index, close, bar_index + projection_length, average_projection_1, color = color_projection_1, width = 2)
// Second projection
trial_results_2 = array.new_float() // Array to store the results of the second trials
for i = 1 to trial_count by 1
rearranged_movements_2 = reorder_array(price_changes_2, i) // Reorder the price movements
future_price_2 = close
for price_variation_2 in rearranged_movements_2
future_price_2 := future_price_2 + (direction_flip_2 ? -price_variation_2 : price_variation_2) // Apply price movement
future_price_2
array.push(trial_results_2, future_price_2) // Store the final result of this trial
average_projection_2 = array.avg(trial_results_2) // Calculate the average projected price for second projection
// Remove previous line if exists
if na(projected_line_2) == false
line.delete(projected_line_2)
// Draw second projected path line
projected_line_2 := line.new(bar_index, close, bar_index + projection_length, average_projection_2, color = color_projection_2, width = 2)
// Fill the zone between the two projected lines
linefill.new(projected_line_1, projected_line_2, color = color.new(color.gray, 70)) // Create a filled zone with transparency between the two projection lines
/////////////////////
Yer İmleri