本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("ICT Fair Value Gaps", "ICT FVG Pro", overlay=true, max_boxes_count=100)
// --- INPUTS ---
grp_vis = "Visual Settings"
bullColor = input.color(color.new(#00ff88, 80), "Bullish FVG", group=grp_vis)
bearColor = input.color(color.new(#ff5252, 80), "Bearish FVG", group=grp_vis)
showLabels = input.bool(true, "Show 'FVG' Labels", group=grp_vis)
grp_logic = "Mitigation Logic"
hideFilled = input.bool(true, "Remove Gaps Once Filled?", group=grp_logic)
// --- ARRAYS TO TRACK OPEN GAPS ---
var box[] bullBoxes = array.new_box()
var box[] bearBoxes = array.new_box()
// --- DETECTION ---
isBullishFVG = low[0] > high[2]
isBearishFVG = high[0] < low[2]
// --- RENDER & ALERTS ---
if isBullishFVG
newBox = box.new(bar_index[2], low[0], bar_index, high[2],
bgcolor=bullColor, border_color=color.new(bullColor, 50),
text = showLabels ? "FVG" : "", text_size=size.tiny, text_color=color.white)
array.push(bullBoxes, newBox)
alert("New Bullish FVG Detected on " + syminfo.ticker, alert.freq_once_per_bar)
if isBearishFVG
newBox = box.new(bar_index[2], high[0], bar_index, low[2],
bgcolor=bearColor, border_color=color.new(bearColor, 50),
text = showLabels ? "FVG" : "", text_color=color.white, text_size=size.tiny)
array.push(bearBoxes, newBox)
alert("New Bearish FVG Detected on " + syminfo.ticker, alert.freq_once_per_bar)
// --- MITIGATION ENGINE ---
// Handle Bullish Gaps
if array.size(bullBoxes) > 0
for i = array.size(bullBoxes) - 1 to 0
box_id = array.get(bullBoxes, i)
bottom = box.get_bottom(box_id)
if low <= bottom
if hideFilled
box.delete(box_id)
array.remove(bullBoxes, i)
else
box.set_right(box_id, bar_index + 2)
// Handle Bearish Gaps
if array.size(bearBoxes) > 0
for i = array.size(bearBoxes) - 1 to 0
box_id = array.get(bearBoxes, i)
top = box.get_top(box_id)
if high >= top
if hideFilled
box.delete(box_id)
array.remove(bearBoxes, i)
else
box.set_right(box_id, bar_index + 2)