OPEN-SOURCE SCRIPT
Мой скрипт

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at mozilla.org/MPL/2.0/
// © Mistab1009
//version=6
indicator("MistaB SMC Navigation Toolkit", overlay=true, max_boxes_count=200)
// === USER INPUTS ===
extendBars = input.int(250, "Box Extension", group="Order Blocks")
opacity = input.int(75, "Box Opacity", group="Order Blocks")
showMidLine = input.bool(true, "Show Midline", group="Order Blocks")
bullColor = input.color(color.green, "Bullish OB Color", group="Order Blocks")
bearColor = input.color(color.red, "Bearish OB Color", group="Order Blocks")
useFractalSwings = input.bool(true, "Use Fractal Swings for OBs", group="Order Blocks")
useDisplacement = input.bool(true, "Require Displacement Candle", group="Order Blocks")
useHighVol = input.bool(true, "Require High Volume", group="Order Blocks")
obBuffer = input.float(0.0, "OB Buffer (points)", step=0.05, group="Order Blocks")
volLength = input.int(21, "Volume MA Length", group="Order Blocks")
volMultiplier = input.float(1.01, "Volume Multiplier", step=0.01, group="Order Blocks")
displacementMultiplier = input.float(1.0, "Displacement Multiplier", minval=0.5, maxval=1.0, step=0.05, group="Order Blocks")
lineExtendLength = input.int(20, "Structure Line Length", group="Structure")
showOB = input.bool(true, "Show Order Blocks", group="Order Blocks")
showFVG = input.bool(true, "Show Fair Value Gaps", group="FVG")
cleanupDelay = input.int(20, "Cleanup Delay (bars)", minval=1, group="Cleanup Settings")
fastCleanup = input.bool(false, "Fast Cleanup Mode", group="Cleanup Settings")
brokenColor = input.color(color.gray, "Broken OB/FVG Color", group="Cleanup Settings")
// Market Structure dimming
msDimOpacity = input.int(70, "Dimmed Structure/FVG Opacity (HTF mismatch)", minval=0, maxval=100, group="Structure")
// Premium/Discount Zones
showZones = input.bool(true, "Show Premium/Discount Zones", group="Premium/Discount Zones")
premiumColor = input.color(color.red, "Premium Zone Color", group="Premium/Discount Zones")
discountColor = input.color(color.green, "Discount Zone Color", group="Premium/Discount Zones")
// FVG Colors
bullish_fvg_color = input.color(color.new(color.green, 70), "Bullish FVG Color", group="FVG")
bearish_fvg_color = input.color(color.new(color.red, 70), "Bearish FVG Color", group="FVG")
// HTF Confirmation
confirmationTF = input.timeframe("60", "HTF Confirmation TF", group="HTF Confirmation")
requireHTF = input.bool(true, "Require HTF Alignment", group="HTF Confirmation")
// === ARRAYS ===
var box[] bullOBs = array.new_box()
var box[] bearOBs = array.new_box()
var line[] bullLines = array.new_line()
var line[] bearLines = array.new_line()
var int[] brokenTimestampsBull = array.new_int()
var int[] brokenTimestampsBear = array.new_int()
// === FRACTAL LOGIC ===
useFractal = input.string("5", "Fractal Type", options=["None", "3", "5"], group="Structure")
fractalOffset = useFractal == "5" ? 2 : useFractal == "3" ? 1 : na
isSwingHigh = useFractal != "None" and not na(fractalOffset) and high[fractalOffset] > high[fractalOffset + 1] and high[fractalOffset] > high[fractalOffset - 1] and (useFractal != "5" or (high[fractalOffset] > high[fractalOffset + 2] and high[fractalOffset] > high[fractalOffset - 2]))
isSwingLow = useFractal != "None" and not na(fractalOffset) and low[fractalOffset] < low[fractalOffset + 1] and low[fractalOffset] < low[fractalOffset - 1] and (useFractal != "5" or (low[fractalOffset] < low[fractalOffset + 2] and low[fractalOffset] < low[fractalOffset - 2]))
// === OPPOSITE CANDLE FINDER ===
f_findOppositeCandle(_bull) =>
int retIndex = na
float retHigh = na
float retLow = na
for i = 1 to 50
bool isOpp = _bull ? (open > close) : (close > open)
if isOpp
retIndex := bar_index - i
retHigh := high
retLow := low
break
[retIndex, retHigh, retLow]
// === HTF STRUCTURE DETECTION ===
htfTrendUp = request.security(syminfo.tickerid, confirmationTF, close > ta.sma(close, 20))
htfBullOB = request.security(syminfo.tickerid, confirmationTF, isSwingLow)
htfBearOB = request.security(syminfo.tickerid, confirmationTF, isSwingHigh)
// === HTF STATUS LABEL ===
var label htfLabel = na
var string htfTxt = ""
var color htfCol = color.gray
if barstate.islast
if not requireHTF
htfTxt := "HTF: Not Required"
htfCol := color.gray
else
if htfTrendUp
htfTxt := "HTF: Bullish ✅"
htfCol := color.green
else
htfTxt := "HTF: Bearish ✅"
htfCol := color.red
if na(htfLabel)
htfLabel := label.new(bar_index, high, text=htfTxt, style=label.style_label_left, textcolor=color.white, color=htfCol)
else
label.set_xy(htfLabel, bar_index, high)
label.set_text(htfLabel, htfTxt)
label.set_color(htfLabel, htfCol)
// === CLEANUP FUNCTION ===
f_cleanOB(_boxes, _lines, _timestamps, _isBull) =>
sz = array.size(_boxes)
if sz > 0
for i = sz - 1 to 0
b = array.get(_boxes, i)
l = array.get(_lines, i)
top = box.get_top(b)
bottom = box.get_bottom(b)
_broken = _isBull ? (close < bottom) : (close > top)
expired = bar_index - box.get_left(b) > extendBars
if _broken
if fastCleanup
box.delete(b)
if not na(l)
line.delete(l)
array.remove(_boxes, i)
array.remove(_lines, i)
if array.size(_timestamps) > i
array.remove(_timestamps, i)
continue
else
if array.size(_timestamps) <= i
array.push(_timestamps, bar_index)
else
array.set(_timestamps, i, bar_index)
box.set_bgcolor(b, color.new(brokenColor, opacity))
if not na(l)
line.set_color(l, brokenColor)
if expired or (array.size(_timestamps) > i and bar_index - array.get(_timestamps, i) >= cleanupDelay)
box.delete(b)
if not na(l)
line.delete(l)
array.remove(_boxes, i)
array.remove(_lines, i)
if array.size(_timestamps) > i
array.remove(_timestamps, i)
// === OB DETECTION ===
isDisplacementBull = close - open > ta.atr(14) * displacementMultiplier
isDisplacementBear = open - close > ta.atr(14) * displacementMultiplier
isHighVolume = volume > ta.sma(volume, volLength) * volMultiplier
if showOB and isSwingLow and bar_index > fractalOffset + 2
ok = (not useDisplacement or isDisplacementBull) and (not useHighVol or isHighVolume)
htfOK = not requireHTF or (htfTrendUp and htfBullOB)
[idxB, hiB, loB] = f_findOppositeCandle(true)
if ok and htfOK and not na(idxB)
hiB += obBuffer
loB -= obBuffer
array.push(bullOBs, box.new(left=idxB, top=hiB, right=bar_index + extendBars, bottom=loB, bgcolor=color.new(bullColor, opacity), border_color=bullColor, xloc=xloc.bar_index))
array.push(bullLines, showMidLine ? line.new(x1=idxB, y1=(hiB+loB)/2, x2=bar_index + extendBars, y2=(hiB+loB)/2, color=bullColor, style=line.style_dashed, xloc=xloc.bar_index) : na)
if showOB and isSwingHigh and bar_index > fractalOffset + 2
ok = (not useDisplacement or isDisplacementBear) and (not useHighVol or isHighVolume)
htfOK = not requireHTF or (not htfTrendUp and htfBearOB)
[idxS, hiS, loS] = f_findOppositeCandle(false)
if ok and htfOK and not na(idxS)
hiS += obBuffer
loS -= obBuffer
array.push(bearOBs, box.new(left=idxS, top=hiS, right=bar_index + extendBars, bottom=loS, bgcolor=color.new(bearColor, opacity), border_color=bearColor, xloc=xloc.bar_index))
array.push(bearLines, showMidLine ? line.new(x1=idxS, y1=(hiS+loS)/2, x2=bar_index + extendBars, y2=(hiS+loS)/2, color=bearColor, style=line.style_dashed, xloc=xloc.bar_index) : na)
f_cleanOB(bullOBs, bullLines, brokenTimestampsBull, true)
f_cleanOB(bearOBs, bearLines, brokenTimestampsBear, false)
// === MARKET STRUCTURE ===
var float lastHigh = na
var float lastLow = na
var bool trendUp = false
var bool prevTrendUp = false
if useFractal != "None" and bar_index > fractalOffset + 2
if isSwingHigh[1]
swingHigh = high[fractalOffset + 1]
if not na(lastHigh)
prevTrendUp := trendUp
trendUp := swingHigh > lastHigh
colorLine = trendUp ? color.green : color.red
structIsBull = trendUp
htfMatches = not requireHTF or (structIsBull and htfTrendUp) or (not structIsBull and not htfTrendUp)
colorUsed = htfMatches ? colorLine : color.new(colorLine, msDimOpacity)
txt = trendUp ? (prevTrendUp ? "HH BoS" : "HH CHoCH") : (prevTrendUp ? "LH CHoCH" : "LH BoS")
label.new(bar_index - fractalOffset - 1, swingHigh, text=txt, style=label.style_label_down, color=colorUsed, textcolor=color.white, size=size.small)
line.new(x1=bar_index - fractalOffset - 1, y1=swingHigh, x2=bar_index - fractalOffset - 1 + lineExtendLength, y2=swingHigh, color=colorUsed, width=1, xloc=xloc.bar_index)
lastHigh := swingHigh
if isSwingLow[1]
swingLow = low[fractalOffset + 1]
if not na(lastLow)
prevTrendUp := trendUp
trendUp := swingLow > lastLow
colorLine = trendUp ? color.green : color.red
structIsBull = trendUp
htfMatches = not requireHTF or (structIsBull and htfTrendUp) or (not structIsBull and not htfTrendUp)
colorUsed = htfMatches ? colorLine : color.new(colorLine, msDimOpacity)
txt = trendUp ? (prevTrendUp ? "HL BoS" : "HL CHoCH") : (prevTrendUp ? "LL CHoCH" : "LL BoS")
label.new(bar_index - fractalOffset - 1, swingLow, text=txt, style=label.style_label_up, color=colorUsed, textcolor=color.white, size=size.small)
line.new(x1=bar_index - fractalOffset - 1, y1=swingLow, x2=bar_index - fractalOffset - 1 + lineExtendLength, y2=swingLow, color=colorUsed, width=1, xloc=xloc.bar_index)
lastLow := swingLow
// === FVG LOGIC ===
var box[] bullish_fvg_boxes = array.new_box()
var label[] bullish_labels = array.new_label()
var box[] bearish_fvg_boxes = array.new_box()
var label[] bearish_labels = array.new_label()
var int[] bullFvgTimestamps = array.new_int()
var int[] bearFvgTimestamps = array.new_int()
if showFVG and bar_index >= 2
if low > high[2] // Bullish FVG
htfMatches = not requireHTF or htfTrendUp
colorUsed = htfMatches ? bullish_fvg_color : color.new(bullish_fvg_color, msDimOpacity)
b = box.new(left=bar_index - 2, top=low, right=bar_index, bottom=high[2], bgcolor=colorUsed, border_color=na, extend=extend.right, xloc=xloc.bar_index)
array.push(bullish_fvg_boxes, b)
l = label.new(x=bar_index + 20, y=(low + high[2]) / 2, text="FVG", style=label.style_label_left, color=na, textcolor=color.green, xloc=xloc.bar_index)
array.push(bullish_labels, l)
if high < low[2] // Bearish FVG
htfMatches = not requireHTF or not htfTrendUp
colorUsed = htfMatches ? bearish_fvg_color : color.new(bearish_fvg_color, msDimOpacity)
b = box.new(left=bar_index - 2, top=low[2], right=bar_index, bottom=high, bgcolor=colorUsed, border_color=na, extend=extend.right, xloc=xloc.bar_index)
array.push(bearish_fvg_boxes, b)
l = label.new(x=bar_index + 20, y=(low[2] + high) / 2, text="FVG", style=label.style_label_left, color=na, textcolor=color.red, xloc=xloc.bar_index)
array.push(bearish_labels, l)
// === FVG Cleanup ===
f_cleanFVG(_boxes, _labels, _timestamps, _isBull) =>
sz = array.size(_boxes)
if sz > 0
for j = sz - 1 to 0
b = array.get(_boxes, j)
l = array.get(_labels, j)
bool filled = _isBull ? (bar_index > (box.get_left(b) + 1) and close < box.get_bottom(b)) : (bar_index > (box.get_left(b) + 1) and close > box.get_top(b))
if filled
if fastCleanup
box.delete(b)
label.delete(l)
array.remove(_boxes, j)
array.remove(_labels, j)
if array.size(_timestamps) > j
array.remove(_timestamps, j)
continue
if array.size(_timestamps) <= j
array.push(_timestamps, bar_index)
box.set_bgcolor(b, color.new(brokenColor, opacity))
label.set_textcolor(l, brokenColor)
if array.size(_timestamps) > j and bar_index - array.get(_timestamps, j) >= cleanupDelay
box.delete(b)
label.delete(l)
array.remove(_boxes, j)
array.remove(_labels, j)
array.remove(_timestamps, j)
f_cleanFVG(bullish_fvg_boxes, bullish_labels, bullFvgTimestamps, true)
f_cleanFVG(bearish_fvg_boxes, bearish_labels, bearFvgTimestamps, false)
// === PREMIUM / DISCOUNT ZONES ===
var box premBox = na
var box discBox = na
mid = (lastHigh + lastLow) / 2
if showZones and not na(mid) and not na(lastHigh) and not na(lastLow)
if not na(premBox)
box.delete(premBox)
if not na(discBox)
box.delete(discBox)
premBox := box.new(left=bar_index - 10, right=bar_index, top=lastHigh, bottom=mid, bgcolor=color.new(premiumColor, 85), border_color=na, xloc=xloc.bar_index)
discBox := box.new(left=bar_index - 10, right=bar_index, top=mid, bottom=lastLow, bgcolor=color.new(discountColor, 85), border_color=na, xloc=xloc.bar_index)
// © Mistab1009
//version=6
indicator("MistaB SMC Navigation Toolkit", overlay=true, max_boxes_count=200)
// === USER INPUTS ===
extendBars = input.int(250, "Box Extension", group="Order Blocks")
opacity = input.int(75, "Box Opacity", group="Order Blocks")
showMidLine = input.bool(true, "Show Midline", group="Order Blocks")
bullColor = input.color(color.green, "Bullish OB Color", group="Order Blocks")
bearColor = input.color(color.red, "Bearish OB Color", group="Order Blocks")
useFractalSwings = input.bool(true, "Use Fractal Swings for OBs", group="Order Blocks")
useDisplacement = input.bool(true, "Require Displacement Candle", group="Order Blocks")
useHighVol = input.bool(true, "Require High Volume", group="Order Blocks")
obBuffer = input.float(0.0, "OB Buffer (points)", step=0.05, group="Order Blocks")
volLength = input.int(21, "Volume MA Length", group="Order Blocks")
volMultiplier = input.float(1.01, "Volume Multiplier", step=0.01, group="Order Blocks")
displacementMultiplier = input.float(1.0, "Displacement Multiplier", minval=0.5, maxval=1.0, step=0.05, group="Order Blocks")
lineExtendLength = input.int(20, "Structure Line Length", group="Structure")
showOB = input.bool(true, "Show Order Blocks", group="Order Blocks")
showFVG = input.bool(true, "Show Fair Value Gaps", group="FVG")
cleanupDelay = input.int(20, "Cleanup Delay (bars)", minval=1, group="Cleanup Settings")
fastCleanup = input.bool(false, "Fast Cleanup Mode", group="Cleanup Settings")
brokenColor = input.color(color.gray, "Broken OB/FVG Color", group="Cleanup Settings")
// Market Structure dimming
msDimOpacity = input.int(70, "Dimmed Structure/FVG Opacity (HTF mismatch)", minval=0, maxval=100, group="Structure")
// Premium/Discount Zones
showZones = input.bool(true, "Show Premium/Discount Zones", group="Premium/Discount Zones")
premiumColor = input.color(color.red, "Premium Zone Color", group="Premium/Discount Zones")
discountColor = input.color(color.green, "Discount Zone Color", group="Premium/Discount Zones")
// FVG Colors
bullish_fvg_color = input.color(color.new(color.green, 70), "Bullish FVG Color", group="FVG")
bearish_fvg_color = input.color(color.new(color.red, 70), "Bearish FVG Color", group="FVG")
// HTF Confirmation
confirmationTF = input.timeframe("60", "HTF Confirmation TF", group="HTF Confirmation")
requireHTF = input.bool(true, "Require HTF Alignment", group="HTF Confirmation")
// === ARRAYS ===
var box[] bullOBs = array.new_box()
var box[] bearOBs = array.new_box()
var line[] bullLines = array.new_line()
var line[] bearLines = array.new_line()
var int[] brokenTimestampsBull = array.new_int()
var int[] brokenTimestampsBear = array.new_int()
// === FRACTAL LOGIC ===
useFractal = input.string("5", "Fractal Type", options=["None", "3", "5"], group="Structure")
fractalOffset = useFractal == "5" ? 2 : useFractal == "3" ? 1 : na
isSwingHigh = useFractal != "None" and not na(fractalOffset) and high[fractalOffset] > high[fractalOffset + 1] and high[fractalOffset] > high[fractalOffset - 1] and (useFractal != "5" or (high[fractalOffset] > high[fractalOffset + 2] and high[fractalOffset] > high[fractalOffset - 2]))
isSwingLow = useFractal != "None" and not na(fractalOffset) and low[fractalOffset] < low[fractalOffset + 1] and low[fractalOffset] < low[fractalOffset - 1] and (useFractal != "5" or (low[fractalOffset] < low[fractalOffset + 2] and low[fractalOffset] < low[fractalOffset - 2]))
// === OPPOSITE CANDLE FINDER ===
f_findOppositeCandle(_bull) =>
int retIndex = na
float retHigh = na
float retLow = na
for i = 1 to 50
bool isOpp = _bull ? (open > close) : (close > open)
if isOpp
retIndex := bar_index - i
retHigh := high
retLow := low
break
[retIndex, retHigh, retLow]
// === HTF STRUCTURE DETECTION ===
htfTrendUp = request.security(syminfo.tickerid, confirmationTF, close > ta.sma(close, 20))
htfBullOB = request.security(syminfo.tickerid, confirmationTF, isSwingLow)
htfBearOB = request.security(syminfo.tickerid, confirmationTF, isSwingHigh)
// === HTF STATUS LABEL ===
var label htfLabel = na
var string htfTxt = ""
var color htfCol = color.gray
if barstate.islast
if not requireHTF
htfTxt := "HTF: Not Required"
htfCol := color.gray
else
if htfTrendUp
htfTxt := "HTF: Bullish ✅"
htfCol := color.green
else
htfTxt := "HTF: Bearish ✅"
htfCol := color.red
if na(htfLabel)
htfLabel := label.new(bar_index, high, text=htfTxt, style=label.style_label_left, textcolor=color.white, color=htfCol)
else
label.set_xy(htfLabel, bar_index, high)
label.set_text(htfLabel, htfTxt)
label.set_color(htfLabel, htfCol)
// === CLEANUP FUNCTION ===
f_cleanOB(_boxes, _lines, _timestamps, _isBull) =>
sz = array.size(_boxes)
if sz > 0
for i = sz - 1 to 0
b = array.get(_boxes, i)
l = array.get(_lines, i)
top = box.get_top(b)
bottom = box.get_bottom(b)
_broken = _isBull ? (close < bottom) : (close > top)
expired = bar_index - box.get_left(b) > extendBars
if _broken
if fastCleanup
box.delete(b)
if not na(l)
line.delete(l)
array.remove(_boxes, i)
array.remove(_lines, i)
if array.size(_timestamps) > i
array.remove(_timestamps, i)
continue
else
if array.size(_timestamps) <= i
array.push(_timestamps, bar_index)
else
array.set(_timestamps, i, bar_index)
box.set_bgcolor(b, color.new(brokenColor, opacity))
if not na(l)
line.set_color(l, brokenColor)
if expired or (array.size(_timestamps) > i and bar_index - array.get(_timestamps, i) >= cleanupDelay)
box.delete(b)
if not na(l)
line.delete(l)
array.remove(_boxes, i)
array.remove(_lines, i)
if array.size(_timestamps) > i
array.remove(_timestamps, i)
// === OB DETECTION ===
isDisplacementBull = close - open > ta.atr(14) * displacementMultiplier
isDisplacementBear = open - close > ta.atr(14) * displacementMultiplier
isHighVolume = volume > ta.sma(volume, volLength) * volMultiplier
if showOB and isSwingLow and bar_index > fractalOffset + 2
ok = (not useDisplacement or isDisplacementBull) and (not useHighVol or isHighVolume)
htfOK = not requireHTF or (htfTrendUp and htfBullOB)
[idxB, hiB, loB] = f_findOppositeCandle(true)
if ok and htfOK and not na(idxB)
hiB += obBuffer
loB -= obBuffer
array.push(bullOBs, box.new(left=idxB, top=hiB, right=bar_index + extendBars, bottom=loB, bgcolor=color.new(bullColor, opacity), border_color=bullColor, xloc=xloc.bar_index))
array.push(bullLines, showMidLine ? line.new(x1=idxB, y1=(hiB+loB)/2, x2=bar_index + extendBars, y2=(hiB+loB)/2, color=bullColor, style=line.style_dashed, xloc=xloc.bar_index) : na)
if showOB and isSwingHigh and bar_index > fractalOffset + 2
ok = (not useDisplacement or isDisplacementBear) and (not useHighVol or isHighVolume)
htfOK = not requireHTF or (not htfTrendUp and htfBearOB)
[idxS, hiS, loS] = f_findOppositeCandle(false)
if ok and htfOK and not na(idxS)
hiS += obBuffer
loS -= obBuffer
array.push(bearOBs, box.new(left=idxS, top=hiS, right=bar_index + extendBars, bottom=loS, bgcolor=color.new(bearColor, opacity), border_color=bearColor, xloc=xloc.bar_index))
array.push(bearLines, showMidLine ? line.new(x1=idxS, y1=(hiS+loS)/2, x2=bar_index + extendBars, y2=(hiS+loS)/2, color=bearColor, style=line.style_dashed, xloc=xloc.bar_index) : na)
f_cleanOB(bullOBs, bullLines, brokenTimestampsBull, true)
f_cleanOB(bearOBs, bearLines, brokenTimestampsBear, false)
// === MARKET STRUCTURE ===
var float lastHigh = na
var float lastLow = na
var bool trendUp = false
var bool prevTrendUp = false
if useFractal != "None" and bar_index > fractalOffset + 2
if isSwingHigh[1]
swingHigh = high[fractalOffset + 1]
if not na(lastHigh)
prevTrendUp := trendUp
trendUp := swingHigh > lastHigh
colorLine = trendUp ? color.green : color.red
structIsBull = trendUp
htfMatches = not requireHTF or (structIsBull and htfTrendUp) or (not structIsBull and not htfTrendUp)
colorUsed = htfMatches ? colorLine : color.new(colorLine, msDimOpacity)
txt = trendUp ? (prevTrendUp ? "HH BoS" : "HH CHoCH") : (prevTrendUp ? "LH CHoCH" : "LH BoS")
label.new(bar_index - fractalOffset - 1, swingHigh, text=txt, style=label.style_label_down, color=colorUsed, textcolor=color.white, size=size.small)
line.new(x1=bar_index - fractalOffset - 1, y1=swingHigh, x2=bar_index - fractalOffset - 1 + lineExtendLength, y2=swingHigh, color=colorUsed, width=1, xloc=xloc.bar_index)
lastHigh := swingHigh
if isSwingLow[1]
swingLow = low[fractalOffset + 1]
if not na(lastLow)
prevTrendUp := trendUp
trendUp := swingLow > lastLow
colorLine = trendUp ? color.green : color.red
structIsBull = trendUp
htfMatches = not requireHTF or (structIsBull and htfTrendUp) or (not structIsBull and not htfTrendUp)
colorUsed = htfMatches ? colorLine : color.new(colorLine, msDimOpacity)
txt = trendUp ? (prevTrendUp ? "HL BoS" : "HL CHoCH") : (prevTrendUp ? "LL CHoCH" : "LL BoS")
label.new(bar_index - fractalOffset - 1, swingLow, text=txt, style=label.style_label_up, color=colorUsed, textcolor=color.white, size=size.small)
line.new(x1=bar_index - fractalOffset - 1, y1=swingLow, x2=bar_index - fractalOffset - 1 + lineExtendLength, y2=swingLow, color=colorUsed, width=1, xloc=xloc.bar_index)
lastLow := swingLow
// === FVG LOGIC ===
var box[] bullish_fvg_boxes = array.new_box()
var label[] bullish_labels = array.new_label()
var box[] bearish_fvg_boxes = array.new_box()
var label[] bearish_labels = array.new_label()
var int[] bullFvgTimestamps = array.new_int()
var int[] bearFvgTimestamps = array.new_int()
if showFVG and bar_index >= 2
if low > high[2] // Bullish FVG
htfMatches = not requireHTF or htfTrendUp
colorUsed = htfMatches ? bullish_fvg_color : color.new(bullish_fvg_color, msDimOpacity)
b = box.new(left=bar_index - 2, top=low, right=bar_index, bottom=high[2], bgcolor=colorUsed, border_color=na, extend=extend.right, xloc=xloc.bar_index)
array.push(bullish_fvg_boxes, b)
l = label.new(x=bar_index + 20, y=(low + high[2]) / 2, text="FVG", style=label.style_label_left, color=na, textcolor=color.green, xloc=xloc.bar_index)
array.push(bullish_labels, l)
if high < low[2] // Bearish FVG
htfMatches = not requireHTF or not htfTrendUp
colorUsed = htfMatches ? bearish_fvg_color : color.new(bearish_fvg_color, msDimOpacity)
b = box.new(left=bar_index - 2, top=low[2], right=bar_index, bottom=high, bgcolor=colorUsed, border_color=na, extend=extend.right, xloc=xloc.bar_index)
array.push(bearish_fvg_boxes, b)
l = label.new(x=bar_index + 20, y=(low[2] + high) / 2, text="FVG", style=label.style_label_left, color=na, textcolor=color.red, xloc=xloc.bar_index)
array.push(bearish_labels, l)
// === FVG Cleanup ===
f_cleanFVG(_boxes, _labels, _timestamps, _isBull) =>
sz = array.size(_boxes)
if sz > 0
for j = sz - 1 to 0
b = array.get(_boxes, j)
l = array.get(_labels, j)
bool filled = _isBull ? (bar_index > (box.get_left(b) + 1) and close < box.get_bottom(b)) : (bar_index > (box.get_left(b) + 1) and close > box.get_top(b))
if filled
if fastCleanup
box.delete(b)
label.delete(l)
array.remove(_boxes, j)
array.remove(_labels, j)
if array.size(_timestamps) > j
array.remove(_timestamps, j)
continue
if array.size(_timestamps) <= j
array.push(_timestamps, bar_index)
box.set_bgcolor(b, color.new(brokenColor, opacity))
label.set_textcolor(l, brokenColor)
if array.size(_timestamps) > j and bar_index - array.get(_timestamps, j) >= cleanupDelay
box.delete(b)
label.delete(l)
array.remove(_boxes, j)
array.remove(_labels, j)
array.remove(_timestamps, j)
f_cleanFVG(bullish_fvg_boxes, bullish_labels, bullFvgTimestamps, true)
f_cleanFVG(bearish_fvg_boxes, bearish_labels, bearFvgTimestamps, false)
// === PREMIUM / DISCOUNT ZONES ===
var box premBox = na
var box discBox = na
mid = (lastHigh + lastLow) / 2
if showZones and not na(mid) and not na(lastHigh) and not na(lastLow)
if not na(premBox)
box.delete(premBox)
if not na(discBox)
box.delete(discBox)
premBox := box.new(left=bar_index - 10, right=bar_index, top=lastHigh, bottom=mid, bgcolor=color.new(premiumColor, 85), border_color=na, xloc=xloc.bar_index)
discBox := box.new(left=bar_index - 10, right=bar_index, top=mid, bottom=lastLow, bgcolor=color.new(discountColor, 85), border_color=na, xloc=xloc.bar_index)
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuna uygun olarak, bu komut dosyasının oluşturucusu bunu açık kaynaklı hale getirmiştir, böylece yatırımcılar betiğin işlevselliğini inceleyip doğrulayabilir. Yazara saygı! Ücretsiz olarak kullanabilirsiniz, ancak kodu yeniden yayınlamanın Site Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuna uygun olarak, bu komut dosyasının oluşturucusu bunu açık kaynaklı hale getirmiştir, böylece yatırımcılar betiğin işlevselliğini inceleyip doğrulayabilir. Yazara saygı! Ücretsiz olarak kullanabilirsiniz, ancak kodu yeniden yayınlamanın Site Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.