OPEN-SOURCE SCRIPT
Fair Value Gap (FVG) Detector

//version=5
indicator("Fair Value Gap (FVG) Detector", overlay=true, max_boxes_count=500)
// === USER INPUTS ===
showBullish = input.bool(true, "Show Bullish FVG")
showBearish = input.bool(true, "Show Bearish FVG")
removeFilled = input.bool(true, "Remove Filled Gaps")
extendBars = input.int(20, "Extend Boxes (Bars)", minval=1)
// === STORAGE ARRAYS ===
var box[] bullishBoxes = array.new_box()
var box[] bearishBoxes = array.new_box()
// === BULLISH FVG CONDITION ===
// Candle structure: low of current > high of 2 candles ago
bullishFVG = low > high[2]
// === BEARISH FVG CONDITION ===
// Candle structure: high of current < low of 2 candles ago
bearishFVG = high < low[2]
// === DRAW BULLISH FVG ===
if showBullish and bullishFVG
top = low
bottom = high[2]
newBox = box.new(left=bar_index[2], right=bar_index + extendBars,
top=top, bottom=bottom,
border_color=color.green,
bgcolor=color.new(color.green, 85))
array.push(bullishBoxes, newBox)
// === DRAW BEARISH FVG ===
if showBearish and bearishFVG
top = low[2]
bottom = high
newBox = box.new(left=bar_index[2], right=bar_index + extendBars,
top=top, bottom=bottom,
border_color=color.red,
bgcolor=color.new(color.red, 85))
array.push(bearishBoxes, newBox)
// === REMOVE FILLED GAPS ===
if removeFilled
// Check Bullish
for i = array.size(bullishBoxes) - 1 to 0
b = array.get(bullishBoxes, i)
if close <= box.get_bottom(b)
box.delete(b)
array.remove(bullishBoxes, i)
// Check Bearish
for i = array.size(bearishBoxes) - 1 to 0
b = array.get(bearishBoxes, i)
if close >= box.get_top(b)
box.delete(b)
array.remove(bearishBoxes, i)
indicator("Fair Value Gap (FVG) Detector", overlay=true, max_boxes_count=500)
// === USER INPUTS ===
showBullish = input.bool(true, "Show Bullish FVG")
showBearish = input.bool(true, "Show Bearish FVG")
removeFilled = input.bool(true, "Remove Filled Gaps")
extendBars = input.int(20, "Extend Boxes (Bars)", minval=1)
// === STORAGE ARRAYS ===
var box[] bullishBoxes = array.new_box()
var box[] bearishBoxes = array.new_box()
// === BULLISH FVG CONDITION ===
// Candle structure: low of current > high of 2 candles ago
bullishFVG = low > high[2]
// === BEARISH FVG CONDITION ===
// Candle structure: high of current < low of 2 candles ago
bearishFVG = high < low[2]
// === DRAW BULLISH FVG ===
if showBullish and bullishFVG
top = low
bottom = high[2]
newBox = box.new(left=bar_index[2], right=bar_index + extendBars,
top=top, bottom=bottom,
border_color=color.green,
bgcolor=color.new(color.green, 85))
array.push(bullishBoxes, newBox)
// === DRAW BEARISH FVG ===
if showBearish and bearishFVG
top = low[2]
bottom = high
newBox = box.new(left=bar_index[2], right=bar_index + extendBars,
top=top, bottom=bottom,
border_color=color.red,
bgcolor=color.new(color.red, 85))
array.push(bearishBoxes, newBox)
// === REMOVE FILLED GAPS ===
if removeFilled
// Check Bullish
for i = array.size(bullishBoxes) - 1 to 0
b = array.get(bullishBoxes, i)
if close <= box.get_bottom(b)
box.delete(b)
array.remove(bullishBoxes, i)
// Check Bearish
for i = array.size(bearishBoxes) - 1 to 0
b = array.get(bearishBoxes, i)
if close >= box.get_top(b)
box.delete(b)
array.remove(bearishBoxes, i)
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.