本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("GEX Flow + Absorption + FVG + ORB + MAs + Signals", "GEX-Absorb", overlay=true, max_boxes_count=300, max_lines_count=300, max_labels_count=500)
// ═════════════ INPUTS ═════════════
g1 = "Absorption Bubbles"
showBubbles = input.bool(true, "Show absorption bubbles", group=g1)
lowerTF = input.timeframe("1", "Lower TF used for delta (must be < chart TF)", group=g1)
volLen = input.int(50, "Volume average length", minval=1, group=g1)
volMult = input.float(2.0, "Min volume (x average)", step=0.1, group=g1)
deltaPct = input.float(25.0, "Min |delta| as % of volume", step=1.0, group=g1)
bullCol = input.color(color.new(#00c853, 45), "Bullish absorption color", group=g1)
bearCol = input.color(color.new(#ff1744, 45), "Bearish absorption color", group=g1)
g2 = "Fair Value Gaps"
showFvg = input.bool(true, "Show FVG", group=g2)
minFvg = input.float(8.0, "Minimum FVG size (points)", step=0.25, group=g2)
maxFvg = input.int(15, "Max active FVGs", minval=1, maxval=100, group=g2)
fvgBull = input.color(color.new(#00c853, 80), "Bullish FVG fill", group=g2)
fvgBear = input.color(color.new(#ff1744, 80), "Bearish FVG fill", group=g2)
fvgBullTxt = input.color(#00c853, "Bullish FVG label color", group=g2)
fvgBearTxt = input.color(#ff1744, "Bearish FVG label color", group=g2)
showFvgLbl = input.bool(true, "Show FVG labels", group=g2)
fvgLblSize = input.string("Small", "FVG label size", options=["Tiny", "Small", "Normal"], group=g2)
g3 = "9:30 Opening Range (ORB)"
showOrb = input.bool(true, "Show ORB", group=g3)
orbSess = input.session("0930-0945", "ORB window (New York)", group=g3)
orbCol = input.color(#2962ff, "ORB line color", group=g3)
orbWidth = input.int(2, "ORB line width", minval=1, maxval=5, group=g3)
orbFillTr = input.int(90, "ORB box transparency", minval=0, maxval=100, group=g3)
g4 = "HTF High / Low (previous completed candle)"
show1h = input.bool(true, "1H", inline="t1", group=g4)
c1h = input.color(#ffeb3b, "", inline="t1", group=g4)
show4h = input.bool(true, "4H", inline="t2", group=g4)
c4h = input.color(#ff9800, "", inline="t2", group=g4)
showD = input.bool(true, "Daily", inline="t3", group=g4)
cD = input.color(#e040fb, "", inline="t3", group=g4)
showW = input.bool(true, "Weekly", inline="t4", group=g4)
cW = input.color(#00e5ff, "", inline="t4", group=g4)
lineLen = input.int(25, "Line length (bars)", minval=3, group=g4)
lvlWidth = input.int(1, "Line width", minval=1, maxval=5, group=g4)
lvlStyleIn = input.string("Dashed", "Line style", options=["Solid", "Dashed", "Dotted"], group=g4)
lvlStyle = lvlStyleIn == "Solid" ? line.style_solid : lvlStyleIn == "Dotted" ? line.style_dotted : line.style_dashed
g5 = "GEX Levels (type in from FlashAlpha, 0 = off)"
callWall = input.float(0.0, "Call wall", group=g5)
callCol = input.color(#00c853, "Call wall color", group=g5)
putWall = input.float(0.0, "Put wall", group=g5)
putCol = input.color(#ff1744, "Put wall color", group=g5)
gammaFlip = input.float(0.0, "Gamma flip", group=g5)
flipCol = input.color(#ffffff, "Gamma flip color", group=g5)
gexWidth = input.int(2, "GEX line width", minval=1, maxval=5, group=g5)
g6 = "Moving Averages"
maType = input.string("EMA", "MA type (all lines)", options=["EMA", "SMA", "WMA", "RMA", "HMA"], group=g6)
ma1On = input.bool(false, "MA 1", inline="m1", group=g6)
ma1Len = input.int(9, "", minval=1, inline="m1", group=g6)
ma1Col = input.color(#ffeb3b, "", inline="m1", group=g6)
ma1W = input.int(1, "", minval=1, maxval=5, inline="m1", group=g6)
ma2On = input.bool(true, "MA 2", inline="m2", group=g6)
ma2Len = input.int(21, "", minval=1, inline="m2", group=g6)
ma2Col = input.color(#00e5ff, "", inline="m2", group=g6)
ma2W = input.int(1, "", minval=1, maxval=5, inline="m2", group=g6)
ma3On = input.bool(true, "MA 3", inline="m3", group=g6)
ma3Len = input.int(50, "", minval=1, inline="m3", group=g6)
ma3Col = input.color(#ff9800, "", inline="m3", group=g6)
ma3W = input.int(2, "", minval=1, maxval=5, inline="m3", group=g6)
ma4On = input.bool(true, "MA 4", inline="m4", group=g6)
ma4Len = input.int(200, "", minval=1, inline="m4", group=g6)
ma4Col = input.color(#ffffff, "", inline="m4", group=g6)
ma4W = input.int(2, "", minval=1, maxval=5, inline="m4", group=g6)
g7 = "Buy / Sell Signals"
enableSig = input.bool(true, "Enable signals", group=g7)
useMaTouch = input.bool(true, "Trigger: price touches signal MA", group=g7)
useFvgSig = input.bool(true, "Trigger: price retests an FVG", group=g7)
useAbsSig = input.bool(true, "Trigger: absorption bubble", group=g7)
sigMaSel = input.string("MA 4", "Signal MA", options=["MA 1", "MA 2", "MA 3", "MA 4"], group=g7)
trendFilter = input.bool(true, "Require MA slope in trade direction", group=g7)
slopeLen = input.int(10, "Slope lookback (bars)", minval=1, group=g7)
firstTouch = input.bool(true, "FVG: first retest only", group=g7)
minConf = input.int(1, "Min triggers that must agree (1 = any, 2 = confluence)", minval=1, maxval=3, group=g7)
cooldown = input.int(5, "Min bars between signals", minval=0, group=g7)
buyCol = input.color(#00c853, "BUY label color", group=g7)
sellCol = input.color(#ff1744, "SELL label color", group=g7)
// ═════════════ MOVING AVERAGES ═════════════
f_ma(float src, int len) =>
switch maType
"SMA" => ta.sma(src, len)
"WMA" => ta.wma(src, len)
"RMA" => ta.rma(src, len)
"HMA" => ta.hma(src, len)
=> ta.ema(src, len)
float ma1 = f_ma(close, ma1Len)
float ma2 = f_ma(close, ma2Len)
float ma3 = f_ma(close, ma3Len)
float ma4 = f_ma(close, ma4Len)
plot(ma1On ? ma1 : na, "MA 1", ma1Col, ma1W)
plot(ma2On ? ma2 : na, "MA 2", ma2Col, ma2W)
plot(ma3On ? ma3 : na, "MA 3", ma3Col, ma3W)
plot(ma4On ? ma4 : na, "MA 4", ma4Col, ma4W)
float sigMa = sigMaSel == "MA 1" ? ma1 : sigMaSel == "MA 2" ? ma2 : sigMaSel == "MA 3" ? ma3 : ma4
// ═════════════ ABSORPTION BUBBLES ═════════════
// TradingView has no bid/ask footprint data, so delta is approximated
// from lower-timeframe candles (up-candle volume minus down-candle volume).
array<float> dArr = request.security_lower_tf(syminfo.tickerid, lowerTF, close > open ? volume : close < open ? -volume : 0.0)
float delta = dArr.size() > 0 ? dArr.sum() : (close > open ? volume : -volume)
float deltaRatio = volume > 0 ? delta / volume * 100 : 0.0
float avgVol = ta.sma(volume, volLen)
bool bigVol = volume > avgVol * volMult
float mid = (high + low) / 2
// Sellers hit hard but price held the upper half -> buyers absorbed
bool bullAbs = bigVol and deltaRatio <= -deltaPct and close >= mid
// Buyers lifted hard but price sat in the lower half -> sellers absorbed
bool bearAbs = bigVol and deltaRatio >= deltaPct and close <= mid
if showBubbles and barstate.isconfirmed
if bullAbs
label.new(bar_index, low, str.tostring(volume, format.volume), style=label.style_circle, color=bullCol, textcolor=color.white, size=volume > avgVol * volMult * 2 ? size.normal : size.small)
if bearAbs
label.new(bar_index, high, str.tostring(volume, format.volume), style=label.style_circle, color=bearCol, textcolor=color.white, size=volume > avgVol * volMult * 2 ? size.normal : size.small)
// ═════════════ FAIR VALUE GAPS ═════════════
var array<box> fvgBoxes = array.new<box>()
var array<bool> fvgIsBull = array.new<bool>()
var array<bool> fvgTouched = array.new<bool>()
var array<label> fvgLbls = array.new<label>()
string lblSz = fvgLblSize == "Tiny" ? size.tiny : fvgLblSize == "Normal" ? size.normal : size.small
bool fvgBuy = false
bool fvgSell = false
if showFvg
if fvgBoxes.size() > 0
for i = fvgBoxes.size() - 1 to 0
box b = fvgBoxes.get(i)
bool isBull = fvgIsBull.get(i)
bool touched = fvgTouched.get(i)
if (isBull and close < b.get_bottom()) or (not isBull and close > b.get_top())
// gap fully taken out: stop drawing it
b.set_right(bar_index)
b.set_extend(extend.none)
fvgBoxes.remove(i)
fvgIsBull.remove(i)
fvgTouched.remove(i)
label.delete(fvgLbls.remove(i))
else
bool hit = isBull ? low <= b.get_top() : high >= b.get_bottom()
if hit and (not firstTouch or not touched)
if isBull
fvgBuy := true
else
fvgSell := true
if hit
fvgTouched.set(i, true)
if barstate.isconfirmed
if low > high[2] and (low - high[2]) >= minFvg
float sz = low - high[2]
fvgBoxes.push(box.new(bar_index - 2, low, bar_index, high[2], border_color=na, bgcolor=fvgBull, extend=extend.right))
fvgIsBull.push(true)
fvgTouched.push(false)
fvgLbls.push(showFvgLbl ? label.new(bar_index + 3, (low + high[2]) / 2, "Bull FVG " + str.tostring(sz, "#.##"), style=label.style_none, textcolor=fvgBullTxt, size=lblSz) : na)
if high < low[2] and (low[2] - high) >= minFvg
float sz = low[2] - high
fvgBoxes.push(box.new(bar_index - 2, low[2], bar_index, high, border_color=na, bgcolor=fvgBear, extend=extend.right))
fvgIsBull.push(false)
fvgTouched.push(false)
fvgLbls.push(showFvgLbl ? label.new(bar_index + 3, (low[2] + high) / 2, "Bear FVG " + str.tostring(sz, "#.##"), style=label.style_none, textcolor=fvgBearTxt, size=lblSz) : na)
while fvgBoxes.size() > maxFvg
box.delete(fvgBoxes.shift())
fvgIsBull.shift()
fvgTouched.shift()
label.delete(fvgLbls.shift())
// ═════════════ 9:30 ORB ═════════════
tz = "America/New_York"
bool inOrb = not na(time(timeframe.period, orbSess, tz))
bool inRth = not na(time(timeframe.period, "0930-1600", tz))
bool newOrb = inOrb and not inOrb[1]
var float orbH = na
var float orbL = na
var line orbHiLn = na
var line orbLoLn = na
var box orbBox = na
if showOrb
if newOrb
orbH := high
orbL := low
orbBox := box.new(bar_index, high, bar_index, low, border_color=orbCol, bgcolor=color.new(orbCol, orbFillTr))
orbHiLn := line.new(bar_index, high, bar_index, high, color=orbCol, width=orbWidth)
orbLoLn := line.new(bar_index, low, bar_index, low, color=orbCol, width=orbWidth)
else if inOrb
orbH := math.max(orbH, high)
orbL := math.min(orbL, low)
orbBox.set_top(orbH)
orbBox.set_bottom(orbL)
orbBox.set_right(bar_index)
orbHiLn.set_y1(orbH)
orbHiLn.set_y2(orbH)
orbHiLn.set_x2(bar_index)
orbLoLn.set_y1(orbL)
orbLoLn.set_y2(orbL)
orbLoLn.set_x2(bar_index)
else if inRth and not na(orbHiLn)
orbHiLn.set_x2(bar_index)
orbLoLn.set_x2(bar_index)
// ═════════════ HTF HIGH / LOW ═════════════
f_prev(tf) =>
request.security(syminfo.tickerid, tf, [high[1], low[1]], lookahead=barmerge.lookahead_on)
[h1h, l1h] = f_prev("60")
[h4h, l4h] = f_prev("240")
[hD, lD] = f_prev("D")
[hW, lW] = f_prev("W")
var array<line> lvlLines = array.new<line>()
var array<label> lvlLabels = array.new<label>()
f_level(float price, string txt, color col, bool show) =>
if show and not na(price)
lvlLines.push(line.new(bar_index - lineLen, price, bar_index + 2, price, color=col, width=lvlWidth, style=lvlStyle))
lvlLabels.push(label.new(bar_index + 2, price, txt, style=label.style_label_left, color=color.new(color.black, 100), textcolor=col, size=size.tiny))
if barstate.islast
for l in lvlLines
l.delete()
for lb in lvlLabels
lb.delete()
lvlLines.clear()
lvlLabels.clear()
f_level(h1h, "1H H", c1h, show1h)
f_level(l1h, "1H L", c1h, show1h)
f_level(h4h, "4H H", c4h, show4h)
f_level(l4h, "4H L", c4h, show4h)
f_level(hD, "D H", cD, showD)
f_level(lD, "D L", cD, showD)
f_level(hW, "W H", cW, showW)
f_level(lW, "W L", cW, showW)
// ═════════════ GEX LEVELS (manual) ═════════════
plot(callWall > 0 ? callWall : na, "Call wall", callCol, gexWidth, plot.style_linebr)
plot(putWall > 0 ? putWall : na, "Put wall", putCol, gexWidth, plot.style_linebr)
plot(gammaFlip > 0 ? gammaFlip : na, "Gamma flip", flipCol, gexWidth, plot.style_linebr)
// ═════════════ BUY / SELL SIGNALS ═════════════
bool slopeUp = sigMa > sigMa[slopeLen]
bool slopeDn = sigMa < sigMa[slopeLen]
bool maBuy = low <= sigMa and close > sigMa and (not trendFilter or slopeUp)
bool maSell = high >= sigMa and close < sigMa and (not trendFilter or slopeDn)
int buyScore = (useMaTouch and maBuy ? 1 : 0) + (useFvgSig and fvgBuy ? 1 : 0) + (useAbsSig and bullAbs ? 1 : 0)
int sellScore = (useMaTouch and maSell ? 1 : 0) + (useFvgSig and fvgSell ? 1 : 0) + (useAbsSig and bearAbs ? 1 : 0)
var int lastSigBar = -1000
bool buySig = false
bool sellSig = false
if enableSig and barstate.isconfirmed and (bar_index - lastSigBar) > cooldown
if buyScore >= minConf and buyScore > sellScore
buySig := true
lastSigBar := bar_index
else if sellScore >= minConf and sellScore > buyScore
sellSig := true
lastSigBar := bar_index
if buySig
string why = (useMaTouch and maBuy ? "MA " : "") + (useFvgSig and fvgBuy ? "FVG " : "") + (useAbsSig and bullAbs ? "ABS" : "")
label.new(bar_index, low, "BUY\n" + why, style=label.style_label_up, color=buyCol, textcolor=color.white, size=size.small)
if sellSig
string why = (useMaTouch and maSell ? "MA " : "") + (useFvgSig and fvgSell ? "FVG " : "") + (useAbsSig and bearAbs ? "ABS" : "")
label.new(bar_index, high, "SELL\n" + why, style=label.style_label_down, color=sellCol, textcolor=color.white, size=size.small)
alertcondition(buySig, "Buy signal", "GEX-Absorb: BUY on {{ticker}} @ {{close}}")
alertcondition(sellSig, "Sell signal", "GEX-Absorb: SELL on {{ticker}} @ {{close}}")