OPEN-SOURCE SCRIPT
FVG & Market Structure

//version=5
indicator("FVG & Market Structure", overlay=true)
// Inputs
fvg_lookback = input.int(100, "FVG Lookback Period")
fvg_strength = input.int(1, "FVG Minimum Strength")
show_fvg = input.bool(true, "Show FVG")
show_liquidity = input.bool(true, "Show Liquidity Zones")
show_bos = input.bool(true, "Show BOS")
// Calculate swing highs and lows
swing_high = ta.pivothigh(high, 2, 2)
swing_low = ta.pivotlow(low, 2, 2)
// Detect Fair Value Gaps (FVG)
detect_fvg() =>
// Bullish FVG (current low > previous high + threshold)
bullish_fvg = low > high[1] and show_fvg
// Bearish FVG (current high < previous low - threshold)
bearish_fvg = high < low[1] and show_fvg
[bullish_fvg, bearish_fvg]
[bullish_fvg, bearish_fvg] = detect_fvg()
// Plot FVG areas
bgcolor(bullish_fvg ? color.new(color.green, 95) : na, title="Bullish FVG")
bgcolor(bearish_fvg ? color.new(color.red, 95) : na, title="Bearish FVG")
// Breach of Structure (BOS) detection
detect_bos() =>
var bool bull_bos = false
var bool bear_bos = false
// Bullish BOS - price breaks above previous swing high
if high > ta.valuewhen(swing_high, high, 1) and not na(swing_high)
bull_bos := true
bear_bos := false
// Bearish BOS - price breaks below previous swing low
if low < ta.valuewhen(swing_low, low, 1) and not na(swing_low)
bear_bos := true
bull_bos := false
[bull_bos, bear_bos]
[bull_bos, bear_bos] = detect_bos()
// Plot BOS signals
plotshape(bull_bos and show_bos, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Bullish BOS")
plotshape(bear_bos and show_bos, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Bearish BOS")
// Liquidity Zones (Recent Highs/Lows)
liquidity_range = input.int(20, "Liquidity Lookback")
buy_side_liquidity = ta.highest(high, liquidity_range)
sell_side_liquidity = ta.lowest(low, liquidity_range)
// Plot Liquidity Zones
plot(show_liquidity ? buy_side_liquidity : na, color=color.red, linewidth=1, title="Sell Side Liquidity")
plot(show_liquidity ? sell_side_liquidity : na, color=color.green, linewidth=1, title="Buy Side Liquidity")
// Order Block Detection (Simplified)
detect_order_blocks() =>
// Bullish Order Block - strong bullish candle followed by pullback
bullish_ob = close > open and (close - open) > (high - low) * 0.7 and show_fvg
// Bearish Order Block - strong bearish candle followed by pullback
bearish_ob = close < open and (open - close) > (high - low) * 0.7 and show_fvg
[bullish_ob, bearish_ob]
[bullish_ob, bearish_ob] = detect_order_blocks()
// Plot Order Blocks
bgcolor(bullish_ob ? color.new(color.lime, 90) : na, title="Bullish Order Block")
bgcolor(bearish_ob ? color.new(color.maroon, 90) : na, title="Bearish Order Block")
// Alerts for key events
alertcondition(bull_bos, "Bullish BOS Detected", "Bullish Breach of Structure")
alertcondition(bear_bos, "Bearish BOS Detected", "Bearish Breach of Structure")
// Table for current market structure
var table info_table = table.new(position.top_right, 2, 4, bgcolor=color.white, border_width=1)
if barstate.islast
table.cell(info_table, 0, 0, "Market Structure", bgcolor=color.gray)
table.cell(info_table, 1, 0, "Status", bgcolor=color.gray)
table.cell(info_table, 0, 1, "Bullish BOS", bgcolor=bull_bos ? color.green : color.red)
table.cell(info_table, 1, 1, bull_bos ? "ACTIVE" : "INACTIVE")
table.cell(info_table, 0, 2, "Bearish BOS", bgcolor=bear_bos ? color.red : color.green)
table.cell(info_table, 1, 2, bear_bos ? "ACTIVE" : "INACTIVE")
table.cell(info_table, 0, 3, "FVG Count", bgcolor=color.blue)
table.cell(info_table, 1, 3, str.tostring(bar_index))
indicator("FVG & Market Structure", overlay=true)
// Inputs
fvg_lookback = input.int(100, "FVG Lookback Period")
fvg_strength = input.int(1, "FVG Minimum Strength")
show_fvg = input.bool(true, "Show FVG")
show_liquidity = input.bool(true, "Show Liquidity Zones")
show_bos = input.bool(true, "Show BOS")
// Calculate swing highs and lows
swing_high = ta.pivothigh(high, 2, 2)
swing_low = ta.pivotlow(low, 2, 2)
// Detect Fair Value Gaps (FVG)
detect_fvg() =>
// Bullish FVG (current low > previous high + threshold)
bullish_fvg = low > high[1] and show_fvg
// Bearish FVG (current high < previous low - threshold)
bearish_fvg = high < low[1] and show_fvg
[bullish_fvg, bearish_fvg]
[bullish_fvg, bearish_fvg] = detect_fvg()
// Plot FVG areas
bgcolor(bullish_fvg ? color.new(color.green, 95) : na, title="Bullish FVG")
bgcolor(bearish_fvg ? color.new(color.red, 95) : na, title="Bearish FVG")
// Breach of Structure (BOS) detection
detect_bos() =>
var bool bull_bos = false
var bool bear_bos = false
// Bullish BOS - price breaks above previous swing high
if high > ta.valuewhen(swing_high, high, 1) and not na(swing_high)
bull_bos := true
bear_bos := false
// Bearish BOS - price breaks below previous swing low
if low < ta.valuewhen(swing_low, low, 1) and not na(swing_low)
bear_bos := true
bull_bos := false
[bull_bos, bear_bos]
[bull_bos, bear_bos] = detect_bos()
// Plot BOS signals
plotshape(bull_bos and show_bos, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Bullish BOS")
plotshape(bear_bos and show_bos, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Bearish BOS")
// Liquidity Zones (Recent Highs/Lows)
liquidity_range = input.int(20, "Liquidity Lookback")
buy_side_liquidity = ta.highest(high, liquidity_range)
sell_side_liquidity = ta.lowest(low, liquidity_range)
// Plot Liquidity Zones
plot(show_liquidity ? buy_side_liquidity : na, color=color.red, linewidth=1, title="Sell Side Liquidity")
plot(show_liquidity ? sell_side_liquidity : na, color=color.green, linewidth=1, title="Buy Side Liquidity")
// Order Block Detection (Simplified)
detect_order_blocks() =>
// Bullish Order Block - strong bullish candle followed by pullback
bullish_ob = close > open and (close - open) > (high - low) * 0.7 and show_fvg
// Bearish Order Block - strong bearish candle followed by pullback
bearish_ob = close < open and (open - close) > (high - low) * 0.7 and show_fvg
[bullish_ob, bearish_ob]
[bullish_ob, bearish_ob] = detect_order_blocks()
// Plot Order Blocks
bgcolor(bullish_ob ? color.new(color.lime, 90) : na, title="Bullish Order Block")
bgcolor(bearish_ob ? color.new(color.maroon, 90) : na, title="Bearish Order Block")
// Alerts for key events
alertcondition(bull_bos, "Bullish BOS Detected", "Bullish Breach of Structure")
alertcondition(bear_bos, "Bearish BOS Detected", "Bearish Breach of Structure")
// Table for current market structure
var table info_table = table.new(position.top_right, 2, 4, bgcolor=color.white, border_width=1)
if barstate.islast
table.cell(info_table, 0, 0, "Market Structure", bgcolor=color.gray)
table.cell(info_table, 1, 0, "Status", bgcolor=color.gray)
table.cell(info_table, 0, 1, "Bullish BOS", bgcolor=bull_bos ? color.green : color.red)
table.cell(info_table, 1, 1, bull_bos ? "ACTIVE" : "INACTIVE")
table.cell(info_table, 0, 2, "Bearish BOS", bgcolor=bear_bos ? color.red : color.green)
table.cell(info_table, 1, 2, bear_bos ? "ACTIVE" : "INACTIVE")
table.cell(info_table, 0, 3, "FVG Count", bgcolor=color.blue)
table.cell(info_table, 1, 3, str.tostring(bar_index))
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.