PHP Code:
//@version=6
indicator('.', overlay = true, max_lines_count = 500, max_boxes_count = 500)
// --- 1. VISUAL SETTINGS ---
i_boxColor = input.color(color.new(#787b86, 92), 'Range Background', group = 'Visuals')
i_gpBullishColor = input.color(color.new(#4caf50, 60), 'Bullish GP Color', group = 'Visuals')
i_gpBearishColor = input.color(color.new(#f44336, 60), 'Bearish GP Color', group = 'Visuals')
i_liqColor = input.color(color.new(#ffeb3b, 85), 'Liquidity Zones Color', group = 'Visuals')
i_lineColor = input.color(color.white, 'Boundary Line Color', group = 'Visuals')
i_whiteText = color.white
// Range Settings
i_autoFit = input.bool(true, 'Auto-Fit Box to last high and low', group = 'Range Settings')
i_lookback = input.int(100, 'Lookback Period', minval = 2, group = 'Range Settings')
i_offsetR = input.int(10, 'Box Offset Right', minval = 0, group = 'Range Settings')
// FVG Settings
i_showFVG = input.bool(true, 'Show Fair Value Gaps (FVG)', group = 'FVG Settings')
i_fvgLen = input.int(10, 'FVG Extension (Bars)', minval = 1, group = 'FVG Settings')
i_bullFVGColor = input.color(color.new(#4caf4f, 100), 'Bullish FVG Color', group = 'FVG Settings')
i_bearFVGColor = input.color(color.new(#f44336, 100), 'Bearish FVG Color', group = 'FVG Settings')
i_showLabels = input.bool(true, 'Show Price Lines & Labels', group = 'Visuals')
// --- 2. CORE CALCULATIONS ---
int hOff = ta.highestbars(high, i_lookback)
int lOff = ta.lowestbars(low, i_lookback)
float rHigh = high[-hOff]
float rLow = low[-lOff]
float rDiff = rHigh - rLow
// KORREKTUR: anchorBar nutzt nun die korrekten Identifier lOff und hOff
int anchorBar = i_autoFit ? bar_index + math.min(hOff, lOff) : bar_index - i_lookback
float bUp = rLow + rDiff * 0.382
float bLo = rLow + rDiff * 0.35
float sUp = rHigh - rDiff * 0.35
float sLo = rHigh - rDiff * 0.382
// --- 3. FVG LOGIC ---
if i_showFVG
if low > high[2]
box.new(bar_index[1], low, bar_index + i_fvgLen, high[2], bgcolor = i_bullFVGColor, border_color = na)
if high < low[2]
box.new(bar_index[1], high, bar_index + i_fvgLen, low[2], bgcolor = i_bearFVGColor, border_color = na)
// --- 4. VISUALS (BOXES) ---
var box b_Range = box.new(na, na, na, na, xloc = xloc.bar_index, bgcolor = i_boxColor, border_color = color.gray)
var box b_Bullish = box.new(na, na, na, na, xloc = xloc.bar_index, bgcolor = i_gpBullishColor, border_color = na, text = 'LONG GİR', text_color = color.white, text_size = size.small)
var box b_Bearish = box.new(na, na, na, na, xloc = xloc.bar_index, bgcolor = i_gpBearishColor, border_color = na, text = 'SHORT GİR', text_color = color.white, text_size = size.small)
var box b_LiqTop = box.new(na, na, na, na, xloc = xloc.bar_index, bgcolor = i_liqColor, border_color = na, text = ' LONG KAPAT SHORT GİR', text_color = i_whiteText, text_size = size.small)
var box b_LiqBot = box.new(na, na, na, na, xloc = xloc.bar_index, bgcolor = i_liqColor, border_color = na, text = 'SHORT KAPAT LONG GİR', text_color = i_whiteText, text_size = size.small)
var array<line> l_levels = array.new_line()
var array<label> lb_prices = array.new_label()
if barstate.isfirst
for i = 0 to 7 by 1
array.push(l_levels, line.new(na, na, na, na, xloc = xloc.bar_index, color = i_lineColor))
array.push(lb_prices, label.new(na, na, '', xloc = xloc.bar_index, color = color.new(color.black, 100), textcolor = i_lineColor, size = size.normal, style = label.style_label_left))
if barstate.islast
int rightBar = bar_index + i_offsetR
box.set_lefttop(b_Range, anchorBar, rHigh)
box.set_rightbottom(b_Range, rightBar, rLow)
box.set_lefttop(b_Bullish, anchorBar, bUp)
box.set_rightbottom(b_Bullish, rightBar, bLo)
box.set_lefttop(b_Bearish, anchorBar, sUp)
box.set_rightbottom(b_Bearish, rightBar, sLo)
box.set_lefttop(b_LiqTop, anchorBar, rHigh)
box.set_rightbottom(b_LiqTop, rightBar, rHigh - rDiff * 0.05)
box.set_lefttop(b_LiqBot, anchorBar, rLow + rDiff * 0.05)
box.set_rightbottom(b_LiqBot, rightBar, rLow)
if i_showLabels
array<float> p_vals = array.from(rHigh, rHigh - rDiff * 0.05, sUp, sLo, bUp, bLo, rLow + rDiff * 0.05, rLow)
for i = 0 to 7 by 1
float v = array.get(p_vals, i)
line.set_xy1(array.get(l_levels, i), anchorBar, v)
line.set_xy2(array.get(l_levels, i), rightBar, v)
label.set_xy(array.get(lb_prices, i), rightBar, v)
label.set_text(array.get(lb_prices, i), ' ' + str.tostring(v, format.mintick))
// --- 5. SIGNAL LOGIC ---
bool sfpShort = high > rHigh and close < rHigh
bool sfpLong = low < rLow and close > rLow
var bool tBear = false
var bool tBull = false
if high >= sLo and low <= sUp
tBear := true
tBear
if low <= bUp and high >= bLo
tBull := true
tBull
bool pL = close[2] < open[2] and close[1] > open[1] and close > high[1]
bool pS = close[2] > open[2] and close[1] < open[1] and close < low[1]
bool signalLongOnly = tBull and pL
bool signalShortOnly = tBear and pS
if signalShortOnly or tBear and high > rHigh
tBear := false
tBear
if signalLongOnly or tBull and low < rLow
tBull := false
tBull
// RANGE ALANINI BELİRLEMEK İÇİN KULLLANILIR./////////////////////
grp_sett = "General Settings"
len = input.int(5, "Short-Term Sensitivity", minval=2, group=grp_sett)
color_up = input.color(#089981, "Historical Wave Color", group=grp_sett)
grp_cast = "Short-Term Forecast"
show_ext_bull = input.bool(true, "Show Bullish Extension (Up)", group=grp_cast)
show_ext_bear = input.bool(true, "Show Bearish Extension (Down)", group=grp_cast)
color_cont = input.color(#ff9800, "Extension Color", group=grp_cast)
link_scenarios = input.bool(false, "Start Reversal after Extension?", group=grp_cast)
show_reversal = input.bool(true, "Show Reversal", group=grp_cast)
color_rev = input.color(#f9ed03, "Reversal Color", group=grp_cast)
grp_vis = "Dashboard & Visuals"
show_table = input.bool(true, "Show Target Table", group=grp_vis)
show_labels = input.bool(true, "Show Chart Labels", group=grp_vis)
show_grid = input.bool(true, "Show Horizontal Fib Levels", group=grp_vis)
show_inv = input.bool(true, "Show Invalidation Line", group=grp_vis)
show_div = input.bool(true, "Show RSI Divergence (DİKKAT RSI DÖNÜŞ)", group=grp_vis, tooltip="Highlights setups where Price and RSI disagree (Divergence), indicating a stronger reversal signal.")
// -----------------------------------------------------------------------------
// STORAGE
// -----------------------------------------------------------------------------
var float[] pPrices = array.new_float()
var int[] pBars = array.new_int()
var bool[] pDirs = array.new_bool()
var float[] pRSI = array.new_float() // NEW: Store RSI values
var float[] pPricesM = array.new_float()
var int[] pBarsM = array.new_int()
var bool[] pDirsM = array.new_bool()
var line[] ghostLines = array.new_line()
var label[] ghostLabels = array.new_label()
//var table infoTable = table.new(position.top_right, 4, 20, border_width = 1)
// -----------------------------------------------------------------------------
// FUNCTIONS
// -----------------------------------------------------------------------------
// Updated to store RSI
addPivot(float p, int b, bool d, float r, float[] prices, int[] bars, bool[] dirs, float[] rsis) =>
array.unshift(prices, p)
array.unshift(bars, b)
array.unshift(dirs, d)
array.unshift(rsis, r) // Store RSI
if array.size(prices) > 20
array.pop(prices)
array.pop(bars)
array.pop(dirs)
array.pop(rsis)
// Overload for Macro (no RSI tracking needed yet)
addPivotMacro(float p, int b, bool d, float[] prices, int[] bars, bool[] dirs) =>
array.unshift(prices, p)
array.unshift(bars, b)
array.unshift(dirs, d)
if array.size(prices) > 20
array.pop(prices)
array.pop(bars)
array.pop(dirs)
drawPred(int t1, float p1, int t2, float p2, string txt, string fib, color col, int width) =>
l = line.new(t1, p1, t2, p2, color=col, style=line.style_dashed, width=width)
array.push(ghostLines, l)
//if show_grid
//l_hor = line.new(t2, p2, t2 + 10, p2, color=color.new(col, 50), style=line.style_dotted, width=1)
//array.push(ghostLines, l_hor)
if show_labels
lbl_text = txt + "\n" + str.tostring(p2, format.mintick)
lb = label.new(t2, p2, text=lbl_text, color=color.new(color.white, 100), textcolor=col, style=label.style_label_left, size=size.small)
array.push(ghostLabels, lb)
fillRow(int r, string t, string f, float p, color c) =>
pct_diff = (p - close) / close * 100
pct_str = (pct_diff > 0 ? "+" : "") + str.tostring(pct_diff, "#.##") + "%"
pct_col = pct_diff >= 0 ? #089981 : #f23645
//table.cell(infoTable, 0, r, t, text_color=color.white, bgcolor=c, text_size=size.small)
//table.cell(infoTable, 1, r, f, text_color=color.white, bgcolor=color.new(c, 20), text_size=size.small)
//table.cell(infoTable, 2, r, str.tostring(p, format.mintick), text_color=color.white, bgcolor=color.new(color.black, 20), text_size=size.small)
//table.cell(infoTable, 3, r, pct_str, text_color=pct_col, bgcolor=color.new(color.black, 20), text_size=size.small)
// -----------------------------------------------------------------------------
// MAIN LOGIC
// -----------------------------------------------------------------------------
// Calculate RSI for Divergence Checks
my_rsi = ta.rsi(close, 14)
ph77 = ta.pivothigh(high, len, len)
pl77 = ta.pivotlow(low, len, len)
if not na(ph77)
// Pass RSI at the time of the pivot (offset by len)
addPivot(ph77, bar_index[len], true, my_rsi[len], pPrices, pBars, pDirs, pRSI)
if not na(pl77)
addPivot(pl77, bar_index[len], false, my_rsi[len], pPrices, pBars, pDirs, pRSI)
//phM = ta.pivothigh(high, len_macro, len_macro)
//plM = ta.pivotlow(low, len_macro, len_macro)
//if not na(phM)
//addPivotMacro(phM, bar_index[len_macro], true, pPricesM, pBarsM, pDirsM)
//if not na(plM)
//addPivotMacro(plM, bar_index[len_macro], false, pPricesM, pBarsM, pDirsM)
//if (not na(ph77) or not na(pl77)) and array.size(pPrices) > 1
//p1_val = array.get(pPrices, 0)
//p1_bar = array.get(pBars, 0)
//p2_val = array.get(pPrices, 1)
//p2_bar = array.get(pBars, 1)
//line.new(p2_bar, p2_val, p1_bar, p1_val, color=color_up, width=1)
// 3. PREDICTIVE LOGIC & TABLE
if barstate.islast
for l in ghostLines
line.delete(l)
for lb in ghostLabels
label.delete(lb)
array.clear(ghostLines)
array.clear(ghostLabels)
//table.clear(infoTable, 0, 0, 3, 19)
//if show_table
//table.cell(infoTable, 0, 0, "DALGA", bgcolor=color.gray, text_color=color.white)
//table.cell(infoTable, 1, 0, "FİBO", bgcolor=color.gray, text_color=color.white)
///table.cell(infoTable, 2, 0, "HEDEF", bgcolor=color.gray, text_color=color.white)
//table.cell(infoTable, 3, 0, "% +/-", bgcolor=color.gray, text_color=color.white)
int tbl_row = 1
if array.size(pPrices) > 0
last_conf_val = array.get(pPrices, 0)
last_conf_bar = array.get(pBars, 0)
last_conf_dir = array.get(pDirs, 0)
int bars_elapsed = bar_index - last_conf_bar
float live_pivot_val = 0.0
int live_pivot_bar = 0
bool live_pivot_dir = bool(na)
float live_pivot_rsi = 50.0 // Default
if last_conf_dir
lowest_val = 1000000.0
lowest_idx = 0
for i = 0 to bars_elapsed
if low[i] < lowest_val
lowest_val := low[i]
lowest_idx := bar_index[i]
live_pivot_rsi := my_rsi[i] // Capture RSI at lowest point
live_pivot_val := lowest_val
live_pivot_bar := lowest_idx
live_pivot_dir := false
else
highest_val = 0.0
highest_idx = 0
for i = 0 to bars_elapsed
if high[i] > highest_val
highest_val := high[i]
highest_idx := bar_index[i]
live_pivot_rsi := my_rsi[i] // Capture RSI at highest point
live_pivot_val := highest_val
live_pivot_bar := highest_idx
live_pivot_dir := true
float vol = math.abs(last_conf_val - live_pivot_val)
if vol == 0
vol := syminfo.mintick * 100
float rev_start_price = live_pivot_val
int rev_start_bar = live_pivot_bar
// =========================================================
// SCENARIO 1: EXTENSION
// =========================================================
float pExt = na
int tExt = bar_index + 10
bool drawing_ext = false
if not live_pivot_dir
if show_ext_bear
calc_price = live_pivot_val - (vol * 0.5)
pExt := math.max(0.01, calc_price)
drawPred(live_pivot_bar, live_pivot_val, tExt, pExt, "(KAPAT)", "0.5", color_cont, 2)
if show_table
fillRow(tbl_row, "SHORT KAPAT", "0.5 Vol", pExt, color_cont)
tbl_row += 1
drawing_ext := true
else
if show_ext_bull
pExt := live_pivot_val + (vol * 0.5)
drawPred(live_pivot_bar, live_pivot_val, tExt, pExt, "(KAPAT)", "0.5", color_cont, 2)
if show_table
fillRow(tbl_row, "LONG KAPAT", "0.5 Vol", pExt, color_cont)
tbl_row += 1
drawing_ext := true
if link_scenarios and drawing_ext
rev_start_price := pExt
rev_start_bar := tExt
// =========================================================
// SCENARIO 2: REVERSAL + RSI DIVERGENCE CHECK
// =========================================================
if show_reversal
int t_step = 5
// --- RSI DIVERGENCE LOGIC ---
bool has_div = false
// Check if we have history
if array.size(pPrices) > 1
// If Live is Low, compare to Previous Low (index 1)
if not live_pivot_dir
prev_low_val = array.get(pPrices, 1)
prev_low_rsi = array.get(pRSI, 1)
// BULLISH DIV: Lower Price + Higher RSI
if live_pivot_val < prev_low_val and live_pivot_rsi > prev_low_rsi
has_div := true
// If Live is High, compare to Previous High (index 1)
else
prev_high_val = array.get(pPrices, 1)
prev_high_rsi = array.get(pRSI, 1)
// BEARISH DIV: Higher Price + Lower RSI
if live_pivot_val > prev_high_val and live_pivot_rsi < prev_high_rsi
has_div := true
// Invalidation Line
if show_inv
inv_col = color.red
inv_y = rev_start_price
l_inv = line.new(rev_start_bar, inv_y, rev_start_bar + 25, inv_y, color=inv_col, width=1, style=line.style_solid)
array.push(ghostLines, l_inv)
// Add Lightning Bolt if Divergence Detected
inv_txt = "DENGE" + (has_div and show_div ? " DİKKAT RSI DÖNÜŞ" : "")
inv_txt_col = has_div and show_div ? color.yellow : inv_col
if show_labels
lb_inv = label.new(rev_start_bar + 30, inv_y, text=inv_txt, color=color.new(color.white, 100), textcolor=inv_txt_col, style=label.style_label_left, size=size.small)
array.push(ghostLabels, lb_inv)
//if show_table
//fillRow(tbl_row, "GEÇERSİZ", (has_div and show_div ? "RSI âÅ¡¡" : "DİKKAT"), inv_y, color.red)
//tbl_row += 1
if not live_pivot_dir
p1 = math.max(0.01, rev_start_price + (vol * 0.382))
t1 = rev_start_bar + 5
drawPred(rev_start_bar, rev_start_price, t1, p1, "(1)", "0.382", color_rev, 2)
if show_table
fillRow(tbl_row, "1", "0.382", p1, color_rev)
tbl_row += 1
p2 = math.max(0.01, p1 - ((p1 - rev_start_price) * 0.618))
t2 = t1 + t_step
drawPred(t1, p1, t2, p2, "(2)", "0.618", color_rev, 2)
if show_table
fillRow(tbl_row, "2", "0.618", p2, color_rev)
tbl_row += 1
p3 = math.max(0.01, p2 + ((p1 - rev_start_price) * 1.618))
t3 = t2 + t_step
drawPred(t2, p2, t3, p3, "(3)", "1.618", color_rev, 2)
if show_table
fillRow(tbl_row, "3", "1.618", p3, color_rev)
tbl_row += 1
p4 = math.max(0.01, p3 - ((p3 - p2) * 0.382))
t4 = t3 + t_step
drawPred(t3, p3, t4, p4, "(4)", "0.382", color_rev, 2)
if show_table
fillRow(tbl_row, "4", "0.382", p4, color_rev)
tbl_row += 1
p5 = math.max(0.01, p4 + (p1 - rev_start_price))
t5 = t4 + t_step
drawPred(t4, p4, t5, p5, "(5)", "1.0", color_rev, 2)
if show_table
fillRow(tbl_row, "5", "1.0", p5, color_rev)
tbl_row += 1
else
pA = math.max(0.01, rev_start_price - (vol * 0.382))
tA = rev_start_bar + 5
drawPred(rev_start_bar, rev_start_price, tA, pA, "(A)", "0.382", color_rev, 2)
if show_table
fillRow(tbl_row, "A", "0.382", pA, color_rev)
tbl_row += 1
pB = math.max(0.01, pA + ((rev_start_price - pA) * 0.618))
tB = tA + t_step
drawPred(tA, pA, tB, pB, "(B)", "0.618", color_rev, 2)
if show_table
fillRow(tbl_row, "B", "0.618", pB, color_rev)
tbl_row += 1
pC = math.max(0.01, pB - ((rev_start_price - pA) * 1.272))
tC = tB + t_step
drawPred(tB, pB, tC, pC, "(C)", "1.272", color_rev, 2)
if show_table
fillRow(tbl_row, "C", "1.272", pC, color_rev)
tbl_row += 1
// ==============ELİOT HESAPLAMASIDIR.===========================================
// ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ INPUTS ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬
var GRP1 = "Core Settings"
//i_lookback = input.int(50, "Lookback Period", minval=20, maxval=100, group=GRP1, tooltip="How far back to look for S/R levels.")
i_pivotStrength = input.int(5, "Pivot Strength", minval=2, maxval=8, group=GRP1, tooltip="Bars needed to confirm a pivot. Higher = fewer but stronger levels.")
i_maxLevels = input.int(2, "Max Levels Each Side", minval=1, maxval=5, group=GRP1)
i_zoneWidth = input.float(0.25, "Zone Width %", minval=0.05, maxval=0.5, step=0.05, group=GRP1)
i_minDistance = input.float(1.0, "Min Distance Between Levels %", minval=0.2, maxval=3.0, step=0.1, group=GRP1, tooltip="Lower values allow more levels to appear")
var GRP2 = "Visual Settings"
i_supportColor = input.color(#00ff88, "Support Color", group=GRP2)
i_resistColor = input.color(#ff3366, "Resistance Color", group=GRP2)
// ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ PERSISTENT DRAWING ARRAYS ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬
var array<line> supportLines = array.new_line(0)
var array<line> resistLines = array.new_line(0)
var array<box> supportBoxes = array.new_box(0)
var array<box> resistBoxes = array.new_box(0)
var array<label> supportLabels = array.new_label(0)
var array<label> resistLabels = array.new_label(0)
// ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ FUNCTIONS ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬
// Clear all drawings
clearDrawings() =>
for ln in supportLines
line.delete(ln)
array.clear(supportLines)
for ln in resistLines
line.delete(ln)
array.clear(resistLines)
for bx in supportBoxes
box.delete(bx)
array.clear(supportBoxes)
for bx in resistBoxes
box.delete(bx)
array.clear(resistBoxes)
for lb in supportLabels
label.delete(lb)
array.clear(supportLabels)
for lb in resistLabels
label.delete(lb)
array.clear(resistLabels)
// Find pivot levels - with safe bounds checking to prevent historical buffer errors
findPivots(int lookback, int strength, bool isSupport) =>
array<float> levels = array.new_float(0)
// Safe bounds that work for all TradingView plans and replay mode
int safeStrength = math.min(strength, 8)
// Calculate safe maximum based on available bars
// Use bar_index to ensure we never exceed what's available
int availableBars = math.max(0, bar_index - safeStrength - 1)
int safeMaxLookback = math.min(lookback, availableBars, 50) // Cap at 50 for performance
// Only proceed if we have enough bars
if bar_index >= safeStrength * 2 + 5 and safeMaxLookback >= safeStrength
for i = safeStrength to safeMaxLookback
// Safety check: ensure we won't exceed available bars
int maxAccess = i + safeStrength
if maxAccess >= bar_index
break
bool isPivot = true
float price = isSupport ? low[i] : high[i]
for j = 1 to safeStrength
int leftIdx = i - j
int rightIdx = i + j
// Bounds check
if leftIdx < 0 or rightIdx >= bar_index
isPivot := false
break
if isSupport
if low[i] >= low[leftIdx] or low[i] >= low[rightIdx]
isPivot := false
break
else
if high[i] <= high[leftIdx] or high[i] <= high[rightIdx]
isPivot := false
break
if isPivot
array.push(levels, price)
levels
// Filter levels to prevent overlap
filterLevels(array<float> levels, float minDistPct, int maxCount, float currentPrice, bool isSupport) =>
array<float> result = array.new_float(0)
int sz = array.size(levels)
if sz == 0
result
else
// Sort: support descending (closest first), resist ascending (closest first)
array.sort(levels, isSupport ? order.descending : order.ascending)
for i = 0 to sz - 1
if array.size(result) >= maxCount
break
float lvl = array.get(levels, i)
// Skip if wrong side of price
if isSupport and lvl >= currentPrice
continue
if not isSupport and lvl <= currentPrice
continue
// Check distance from existing levels in result
bool tooClose = false
int resultSize = array.size(result)
if resultSize > 0
for j = 0 to resultSize - 1
float existing = array.get(result, j)
if math.abs(lvl - existing) / existing * 100 < minDistPct
tooClose := true
break
if not tooClose
array.push(result, lvl)
result
// ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ MAIN LOGIC ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬
// Only calculate and draw on last bar
if barstate.islast
// Clear previous drawings
clearDrawings()
// Find pivot levels
array<float> rawSupport = findPivots(i_lookback, i_pivotStrength, true)
array<float> rawResist = findPivots(i_lookback, i_pivotStrength, false)
// Filter to get clean, non-overlapping levels
array<float> supportLevels = filterLevels(rawSupport, i_minDistance, i_maxLevels, close, true)
array<float> resistLevels = filterLevels(rawResist, i_minDistance, i_maxLevels, close, false)
float zoneSize = close * (i_zoneWidth / 100)
int startBar = bar_index - i_lookback
int endBar = bar_index + 15
// Draw support levels
if array.size(supportLevels) > 0
for i = 0 to array.size(supportLevels) - 1
float level = array.get(supportLevels, i)
// Line
line ln = line.new(startBar, level, endBar, level,
color=i_supportColor, width=1, style=line.style_dashed)
array.push(supportLines, ln)
// Label (only nearest)
if i == 0
label lb = label.new(endBar + 2, level, "S: " + str.tostring(level, format.mintick),
style=label.style_label_left, color=color.new(i_supportColor, 50),
textcolor=color.white, size=size.small)
array.push(supportLabels, lb)
// Draw resistance levels
if array.size(resistLevels) > 0
for i = 0 to array.size(resistLevels) - 1
float level = array.get(resistLevels, i)
// Line
line ln = line.new(startBar, level, endBar, level,
color=i_resistColor, width=1, style=line.style_dashed)
array.push(resistLines, ln)
// Label (only nearest)
if i == 0
label lb = label.new(endBar + 2, level, "R: " + str.tostring(level, format.mintick),
style=label.style_label_left, color=color.new(i_resistColor, 50),
textcolor=color.white, size=size.small)
array.push(resistLabels, lb)
// ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ TEK PİVOT ARAR Kİ RANGE İÇİNDEKİ YÖNÜ KIYAS İÇİN KULLANILIR. ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬
//////------------------------------------------------------------------------------
length744 = input(100)
extend = input(true, 'Extend To Last Bar')
//show_labels = input(true, 'Show Labels')
//Style
upcol = input.color(#0004ff, 'Upper Extremity Color', group = 'Style')
midcol = input.color(#ff5d00, 'Zig Zag Color', group = 'Style')
dncol = input.color(color.rgb(222, 246, 6), 'Lower Extremity Color', group = 'Style')
//------------------------------------------------------------------------------
os = 0
src = close
n = bar_index
var float valtop = na
var float valbtm = na
//------------------------------------------------------------------------------
upper = ta.highest(src, length744)
lower = ta.lowest(src, length744)
os := src[length744] > upper ? 0 : src[length744] < lower ? 1 : os[1]
btm = os == 1 and os[1] != 1
top = os == 0 and os[1] != 0
//------------------------------------------------------------------------------
btm_n = ta.valuewhen(btm, n, 0)
top_n = ta.valuewhen(top, n, 0)
len88 = math.abs(btm_n - top_n)
if btm
max_diff_up = 0.
max_diff_dn = 0.
valbtm := low[length744]
for i = 0 to len88 - 1 by 1
point = low[length744] + i / (len88 - 1) * (valtop - low[length744])
max_diff_up := math.max(math.max(src[length744 + i], open[length744 + i]) - point, max_diff_up)
max_diff_dn := math.max(point - math.min(src[length744 + i], open[length744 + i]), max_diff_dn)
max_diff_dn
//line.new(n[len + length744], valtop, n[length744], low[length744], color = midcol)
//if show_ext
//line.new(n[len + length744], valtop + max_diff_up, n[length744], low[length744] + max_diff_up, color = upcol, style = line.style_dotted)
//line.new(n[len + length744], valtop - max_diff_dn, n[length744], low[length744] - max_diff_dn, color = dncol, style = line.style_dotted)
if show_labels
label.new(n[length744], low[length744], str.tostring(low[length744], '#.####'), color = #00000000, style = label.style_label_up, textcolor = dncol, textalign = text.align_left, size = size.large)
if top
max_diff_up = 0.
max_diff_dn = 0.
valtop := high[length744]
for i = 0 to len88 - 1 by 1
point = high[length744] + i / (len88 - 1) * (valbtm - high[length744])
max_diff_up := math.max(math.max(src[length744 + i], open[length744 + i]) - point, max_diff_up)
max_diff_dn := math.max(point - math.min(src[length744 + i], open[length744 + i]), max_diff_dn)
max_diff_dn
//line.new(n[len + length744], valbtm, n[length744], high[length744], color = midcol)
//if show_ext
// line.new(n[len + length744], valbtm + max_diff_up, n[length744], high[length744] + max_diff_up, color = upcol, style = line.style_dotted)
//line.new(n[len + length744], valbtm - max_diff_dn, n[length744], high[length744] - max_diff_dn, color = dncol, style = line.style_dotted)
if show_labels
label.new(n[length744], high[length744], str.tostring(high[length744], '#.####'), color = #00000000, style = label.style_label_down, textcolor = upcol, textalign = text.align_left, size = size.large)
if barstate.islast and extend
max_diff_up = 0.
max_diff_dn = 0.
x1 = 0
y1 = 0.
if os == 1
x1 := btm_n - length744
y1 := valbtm
for i = 0 to n - btm_n + length744 - 1 by 1
point = src + i / (n - btm_n + length744 - 1) * (valbtm - src)
max_diff_up := math.max(math.max(src[i], open[i]) - point, max_diff_up)
max_diff_dn := math.max(point - math.min(src[i], open[i]), max_diff_dn)
max_diff_dn
else
x1 := top_n - length744
y1 := valtop
for i = 0 to n - top_n + length744 - 1 by 1
point = src + i / (n - top_n + length744 - 1) * (valtop - src)
max_diff_up := math.max(math.max(src[i], open[i]) - point, max_diff_up)
max_diff_dn := math.max(point - math.min(src[i], open[i]), max_diff_dn)
max_diff_dn
//line.delete(line.new(x1, y1, n, src, color = midcol, extend = extend.right)[1])
//if show_ext
//line.delete(line.new(x1, y1 + max_diff_up, n, src + max_diff_up, color = upcol, style = line.style_dotted, extend = extend.right)[1])
//line.delete(line.new(x1, y1 - max_diff_dn, n, src - max_diff_dn, color = dncol, style = line.style_dotted, extend = extend.right)[1])
//------------------------------------------------------------------------------
plot(btm ? low[length744] : top ? high[length744] : na, 'ANA', color = btm ? dncol : upcol, style = plot.style_circles, offset = -length744)
///////////////EN SON TEPE V E DİP PERİYOTA GÖRE ANA TREND OLARAK BELİRLENİR.///////////////
// �������� ������������
int left_bars = input(1, 'Left Bars', group = 'Pivot Settings')
int right_bars = input(2, 'Right Bars', group = 'Pivot Settings')
float Offset = input.float(0.1, step = 0.01)
// ������������������ ����������������������
var float phy = na
var float ply = na
atr = ta.atr(200)
p_high = ta.pivothigh(high + atr * Offset, left_bars, right_bars)
p_low = ta.pivotlow(low - atr * Offset, left_bars, right_bars)
if bool(p_high)
phy := p_high
phy
if bool(p_low)
ply := p_low
ply
// Trend
upperBand = phy
lowerBand = ply
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])
int trend = na
float Trend = na
prevTrend = Trend[1]
if prevTrend == prevUpperBand
trend := close > upperBand ? 1 : -1
trend
else
trend := close < lowerBand ? -1 : 1
trend
Trend := trend == 1 ? lowerBand : trend == -1 ? upperBand : na
// ��������������������������
//@ Signals
color = trend == 1 ? color.blue : trend == -1 ? color.red : na
plotchar(ta.crossover(trend, 0) ? Trend : na, 'Buy', '��', location.absolute, color.blue, size = size.small)
plotchar(ta.crossunder(trend, 0) ? Trend : na, 'Sell', '��', location.absolute, color.red, size = size.small)
// PİVOT TREND SİNYALLERİDİR.////////////
mt = input.timeframe('', title = 'S/R timeframe')
sh = input.int(2, title = 'Shift S/R Forward/Backward')
start = input.float(title = 'Start', step = 0.01, defval = 0.)
increment = input.float(title = 'Increment', step = 0.01, defval = 0.09)
maximum = input.float(title = 'Maximum', step = 0.01, defval = 0.2)
sar = request.security(syminfo.tickerid, mt, ta.sar(start, increment, maximum))
plot(sar, style = plot.style_circles, linewidth = 1, color = color.yellow)
dir = sar < close ? 1 : -1
buy = dir == 1 and dir[1] == -1
sell = dir == -1 and dir[1] == 1
//alertcondition(buy, title = 'SAR BUY', message = 'PSAR/Buy Signal')
//alertcondition(sell, title = 'SAR SELL', message = 'PSAR/Sell Signal')
//alertcondition(buy or sell, title = 'SAR BUY/SELL', message = 'PSAR/Buy/Sell Signal')
h = ta.valuewhen(buy, close, 0)
l = ta.valuewhen(sell, close, 0)
buyalert = open > h and close > h and open[1] < h
sellalert = open < l and close < l and open[1] > h
y = ta.valuewhen(buy, close[0], 0)
u = plot(y, color = color.rgb(10, 187, 196, 100), linewidth = 1, title = 'High', offset = sh)
z = ta.valuewhen(sell, close[0], 0)
d = plot(z, color = color.rgb(240, 6, 127, 100), linewidth = 1, title = 'Low', offset = sh)
//fill(u, d, color = y > z ? color.rgb(255, 82, 82, 77) : color.rgb(76, 175, 79, 78))
plotshape(buy ? sar : na, title = 'Buy', text = 'A', location = location.absolute, style = shape.labelup, size = size.tiny, color = #06b5e5, textcolor = color.white)
plotshape(sell ? sar : na, title = 'Sell', text = 'S', location = location.absolute, style = shape.labeldown, size = size.tiny, color = color.rgb(249, 11, 106), textcolor = color.white)
/////////////////SAR İLE BULUTLAMADIR.///////////
Yer İmleri