本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// Simple FVGs — by Allen Tri
// Draws unmitigated FVGs as squares/boxes, alerts ONCE on first tap.
// Tap = price first enters the zone. No close needed (warning shot).
// Label: TF + direction, middle vertically, right-hand end of the box.
// Stack: this tap indicator + COBRA CISD only. Barbarian nixed.
// TF pairs: W->H4, D->H1, H4->M15, H1->M5, M15->M1 (M30 dropped 2026-10-27 20:46 PT — capture only W, D, H4, H1, M15)
indicator("Simple FVGs", overlay = true, max_boxes_count = 500, max_labels_count = 500, max_lines_count = 0)
showW = input.bool(true, "Weekly FVG")
showD = input.bool(true, "Daily FVG")
showH4 = input.bool(true, "H4 FVG")
showH1 = input.bool(true, "H1 FVG")
showM15 = input.bool(true, "M15 FVG")
showM5 = input.bool(true, "M5 FVG (display only, no alert)")
bullColor = input.color(color.new(color.teal, 80), "Bullish box")
bearColor = input.color(color.new(color.red, 80), "Bearish box")
type FVG
box b
label l
float top
float bottom
bool bull
bool tapped
string tf
string cisdTf
fvgDetect(float h, float l) =>
bullGap = l[2] > h[0]
bearGap = h[2] < l[0]
top = bullGap ? l[2] : bearGap ? l[0] : na
bot = bullGap ? h[0] : bearGap ? h[2] : na
isNew = bullGap or bearGap
[top, bot, bullGap, isNew]
[wh, wl] = request.security(syminfo.tickerid, "W", [high, low], lookahead = barmerge.lookahead_off)
[dh, dl] = request.security(syminfo.tickerid, "D", [high, low], lookahead = barmerge.lookahead_off)
[h4h, h4l] = request.security(syminfo.tickerid, "240", [high, low], lookahead = barmerge.lookahead_off)
[h1h, h1l] = request.security(syminfo.tickerid, "60", [high, low], lookahead = barmerge.lookahead_off)
[m15h, m15l] = request.security(syminfo.tickerid, "15", [high, low], lookahead = barmerge.lookahead_off)
[m5h, m5l] = request.security(syminfo.tickerid, "5", [high, low], lookahead = barmerge.lookahead_off)
wc = request.security(syminfo.tickerid, "W", close, lookahead = barmerge.lookahead_off)
dc = request.security(syminfo.tickerid, "D", close, lookahead = barmerge.lookahead_off)
h4c = request.security(syminfo.tickerid, "240", close, lookahead = barmerge.lookahead_off)
h1c = request.security(syminfo.tickerid, "60", close, lookahead = barmerge.lookahead_off)
m15c = request.security(syminfo.tickerid, "15", close, lookahead = barmerge.lookahead_off)
m5c = request.security(syminfo.tickerid, "5", close, lookahead = barmerge.lookahead_off)
var FVG zW = na, var FVG zD = na, var FVG zH4 = na, var FVG zH1 = na, var FVG zM15 = na, var FVG zM5 = na
checkZone(FVG z, float top, float bot, bool bull, bool isNew, float htfClose, bool show, string tf, string cisdTf, bool doAlert = true) =>
FVG result = z
if show and isNew
if not na(result)
box.delete(result.b)
label.delete(result.l)
col = bull ? bullColor : bearColor
b = box.new(bar_index - 1, top, bar_index, bot, bgcolor = col, border_color = col)
mid = (top + bot) / 2.0
lab = label.new(bar_index, mid, tf + " FVG", style = label.style_label_left, color = color.new(color.black, 100), textcolor = color.new(color.gray, 0), size = size.small)
result := FVG.new(b, lab, top, bot, bull, false, tf, cisdTf)
if not na(result)
mitigated = result.bull ? htfClose < result.bottom : htfClose > result.top
if mitigated
box.delete(result.b)
label.delete(result.l)
result := na
else
box.set_right(result.b, bar_index)
label.set_xy(result.l, bar_index, (result.top + result.bottom) / 2.0)
touched = result.bull ? low <= result.top and high >= result.bottom : high >= result.bottom and low <= result.top
if touched and not result.tapped and doAlert
result.tapped := true
dir = result.bull ? "BULLISH" : "BEARISH"
msg = "FVG TAP | " + result.tf + " | " + dir + " | top " + str.tostring(result.top) + " | bottom " + str.tostring(result.bottom) + " | CISD TF " + result.cisdTf + " | WAIT for matching CISD — NOT an entry yet"
alert(msg, alert.freq_once_per_bar)
result
[wTop, wBot, wBull, wNew] = fvgDetect(wh, wl)
[dTop, dBot, dBull, dNew] = fvgDetect(dh, dl)
[h4Top, h4Bot, h4Bull, h4New] = fvgDetect(h4h, h4l)
[h1Top, h1Bot, h1Bull, h1New] = fvgDetect(h1h, h1l)
[m15Top, m15Bot, m15Bull, m15New] = fvgDetect(m15h, m15l)
[m5Top, m5Bot, m5Bull, m5New] = fvgDetect(m5h, m5l)
zW := checkZone(zW, wTop, wBot, wBull, wNew, wc, showW, "W", "H4")
zD := checkZone(zD, dTop, dBot, dBull, dNew, dc, showD, "D", "H1")
zH4 := checkZone(zH4, h4Top, h4Bot, h4Bull, h4New, h4c, showH4, "H4", "M15")
zH1 := checkZone(zH1, h1Top, h1Bot, h1Bull, h1New, h1c, showH1, "H1", "M5")
zM15 := checkZone(zM15, m15Top, m15Bot, m15Bull, m15New, m15c, showM15, "M15", "M1")
zM5 := checkZone(zM5, m5Top, m5Bot, m5Bull, m5New, m5c, showM5, "M5", "M1", false)