PHP Code:
//@version=6
indicator('.', overlay = false, max_lines_count = 500, max_boxes_count = 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), 'Bearish Trend', group = 'Colors')
color color_bullish_price_state = input.color(#f1f6f7, 'Bullish Trend', group = 'Colors')
color color_bullish_resistance_state = input.color(color.rgb(243, 3, 3, 52), 'Bullish Resistance', group = 'Colors')
color color_bearish_support_state = input.color(color.rgb(226, 247, 2, 52), '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 = 'MUM')
/////////güzel 8-9//////
// // TURN TD 8's & 9's ON / OFF ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
showBuyTDs = input(true, title = 'Show TD Buy')
showSellTDs = input(true, title = 'Show TD Sell')
// // TD CALCS /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
buySignals = 0
buySignals := close < close[4] ? buySignals[1] == 9 ? 1 : buySignals[1] + 1 : 0
sellSignals = 0
sellSignals := close > close[4] ? sellSignals[1] == 9 ? 1 : sellSignals[1] + 1 : 0
BuyOrSell = buySignals > sellSignals ? buySignals : sellSignals
TD8buy = showBuyTDs and bool(buySignals) and BuyOrSell == 8
TD9buy = showBuyTDs and bool(buySignals) and BuyOrSell == 9
TD8sell = showSellTDs and bool(sellSignals) and BuyOrSell == 8
TD9sell = showSellTDs and bool(sellSignals) and BuyOrSell == 9
// TD LABELS /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
plotshape(TD8buy, style = shape.labelup, text = '8', color = color.new(#05f30d, 0), textcolor = color.rgb(4, 4, 4), size = size.tiny, location = location.belowbar)
plotshape(TD9buy, style = shape.labelup, text = '9', color = color.new(#05f30d, 0), textcolor = color.rgb(4, 4, 4), size = size.tiny, location = location.belowbar)
plotshape(TD8sell, style = shape.labeldown, text = '8', color = color.new(#e600ff, 0), textcolor = color.rgb(4, 4, 4), size = size.tiny, location = location.abovebar)
plotshape(TD9sell, style = shape.labeldown, text = '9', color = color.new(#e600ff, 0), textcolor = color.rgb(4, 4, 4), size = size.tiny, location = location.abovebar)
/////////////////////
// --- 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(5, '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./////////////////////
// ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ââ€â‚¬ 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, "BOĞA DENGE: " + str.tostring(level, format.mintick),
style=label.style_label_left, color=color.new(i_supportColor, 50),
textcolor=color.white, size=size.normal)
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, "AYI DENGE: " + str.tostring(level, format.mintick),
style=label.style_label_left, color=color.new(i_resistColor, 50),
textcolor=color.white, size=size.normal)
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.///////////////
// Only act after candle closes
isClosed = barstate.isconfirmed
// Your raw retracement rules
bullRaw = isClosed and close[1] < open[1] and close < open and close < low[1]
bearRaw = isClosed and close[1] > open[1] and close > open and close > high[1]
// Small wick-based spacing
spaceUp = (high - close) * 0.65
spaceDown = (open - low) * 0.65
// Colors
brightRed = color.rgb(255, 0, 0)
brightGreen = color.rgb(0, 255, 0)
// Wave locks
var bool bullWaveLocked = false
var bool bearWaveLocked = false
// Reset locks when opposite candle prints
if isClosed and close > open
bullWaveLocked := false
bullWaveLocked
if isClosed and close < open
bearWaveLocked := false
bearWaveLocked
// BEARISH WAVE (Red)
if bullRaw and not bullWaveLocked
label.new(bar_index - 1, high[1] + (high[1] - close[1]) * 0.65, 'L', style = label.style_none, textcolor = brightRed, size = size.large)
label.new(bar_index, high + spaceUp, 'Lo', style = label.style_none, textcolor = brightRed, size = size.large)
bullWaveLocked := true
bullWaveLocked
// BULLISH WAVE (Green)
if bearRaw and not bearWaveLocked
label.new(bar_index - 1, low[1] - (open[1] - low[1]) * 0.65, 'L', style = label.style_none, textcolor = brightGreen, size = size.large)
label.new(bar_index, low - spaceDown, 'Lo', style = label.style_none, textcolor = brightGreen, size = size.large)
bearWaveLocked := true
bearWaveLocked
/////////////////////bar tarama///////////
örnek görüntüler.....
Yer İmleri