本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Sniper Trading | Execution Assistant V1", overlay=true, max_boxes_count=10, max_labels_count=100)
// 1. PLACE THESE FOUR LEVELS ON THE CHART WHEN ADDING THE INDICATOR.
// Afterward, select the indicator to drag its price markers.
gZones = "1 | Drag your zone boundaries"
supplyTop = input.price(0.0, "Supply TOP", group=gZones, confirm=true)
supplyBottom = input.price(0.0, "Supply BOTTOM", group=gZones, confirm=true)
demandTop = input.price(0.0, "Demand TOP", group=gZones, confirm=true)
demandBottom = input.price(0.0, "Demand BOTTOM", group=gZones, confirm=true)
gLogic = "2 | Confirmation rules"
swingLength = input.int(2, "Confirmed swing length", minval=1, maxval=20, group=gLogic)
gOpen = "3 | Opening range (exchange time)"
openingSession = input.session("0930-1000", "Opening range session", group=gOpen)
showOpeningRange = input.bool(true, "Show opening range high/low", group=gOpen)
gDisplay = "4 | Display and optional targets"
showMidpoints = input.bool(true, "Show white zone midpoints", group=gDisplay)
showEquilibrium = input.bool(true, "Show midpoint between zones", group=gDisplay)
showDashboard = input.bool(true, "Show dashboard", group=gDisplay)
showReactions = input.bool(true, "Show zone reaction markers", group=gDisplay)
showSetups = input.bool(true, "Show Sniper watch markers", group=gDisplay)
customBullTarget = input.float(0.0, "Bull target (0 = supply bottom)", minval=0.0, group=gDisplay)
customBearTarget = input.float(0.0, "Bear target (0 = demand top)", minval=0.0, group=gDisplay)
showTargets = input.bool(false, "Show target lines", group=gDisplay)
// 2. VALIDATE ZONES AND CALCULATE MIDPOINTS.
valid = supplyTop > supplyBottom and supplyBottom > demandTop and demandTop > demandBottom
supplyMid = (supplyTop + supplyBottom) / 2.0
demandMid = (demandTop + demandBottom) / 2.0
equilibrium = (supplyBottom + demandTop) / 2.0
bullTarget = customBullTarget > 0 ? customBullTarget : supplyBottom
bearTarget = customBearTarget > 0 ? customBearTarget : demandTop
// 3. DRAW TWO COLORED ZONE BOXES THAT EXTEND RIGHT.
var box supplyBox = na
var box demandBox = na
if barstate.islast
if valid
leftEdge = math.max(0, bar_index - 100)
if na(supplyBox)
supplyBox := box.new(left=leftEdge, top=supplyTop, right=bar_index + 10, bottom=supplyBottom, border_color=color.red, border_width=2, extend=extend.right, bgcolor=color.new(color.red, 88))
demandBox := box.new(left=leftEdge, top=demandTop, right=bar_index + 10, bottom=demandBottom, border_color=color.lime, border_width=2, extend=extend.right, bgcolor=color.new(color.lime, 88))
else
box.set_lefttop(supplyBox, leftEdge, supplyTop)
box.set_rightbottom(supplyBox, bar_index + 10, supplyBottom)
box.set_lefttop(demandBox, leftEdge, demandTop)
box.set_rightbottom(demandBox, bar_index + 10, demandBottom)
else
if not na(supplyBox)
box.delete(supplyBox)
box.delete(demandBox)
supplyBox := na
demandBox := na
plot(valid and showMidpoints ? supplyMid : na, "Supply midpoint", color=color.white, linewidth=1)
plot(valid and showMidpoints ? demandMid : na, "Demand midpoint", color=color.white, linewidth=1)
plot(valid and showEquilibrium ? equilibrium : na, "Between-zones midpoint", color=color.yellow, linewidth=1)
plot(valid and showTargets ? bullTarget : na, "Bull target", color=color.teal, linewidth=1)
plot(valid and showTargets ? bearTarget : na, "Bear target", color=color.orange, linewidth=1)
// 4. TRACK THE OPENING RANGE ON INTRADAY CHARTS.
isMorning = timeframe.isintraday and not na(time(timeframe.period, openingSession))
newDay = timeframe.change("D")
var float openingHigh = na
var float openingLow = na
var float lockedHigh = na
var float lockedLow = na
if newDay
openingHigh := na
openingLow := na
lockedHigh := na
lockedLow := na
if isMorning
openingHigh := na(openingHigh) ? high : math.max(openingHigh, high)
openingLow := na(openingLow) ? low : math.min(openingLow, low)
if not isMorning and isMorning[1]
lockedHigh := openingHigh
lockedLow := openingLow
plot(showOpeningRange ? lockedHigh : na, "Opening range high", color=color.aqua, linewidth=1, style=plot.style_linebr)
plot(showOpeningRange ? lockedLow : na, "Opening range low", color=color.orange, linewidth=1, style=plot.style_linebr)
openingHighCross = ta.crossover(close, lockedHigh)
openingLowCross = ta.crossunder(close, lockedLow)
openingHighBreak = timeframe.isintraday and barstate.isconfirmed and not na(lockedHigh) and openingHighCross
openingLowBreak = timeframe.isintraday and barstate.isconfirmed and not na(lockedLow) and openingLowCross
// 5. MEASURE STRUCTURE USING CONFIRMED SWING HIGHS/LOWS.
// The pivot is confirmed only after 'swingLength' bars to the right.
pivotHigh = ta.pivothigh(high, swingLength, swingLength)
pivotLow = ta.pivotlow(low, swingLength, swingLength)
var float recentHigh = na
var float previousHigh = na
var float recentLow = na
var float previousLow = na
if not na(pivotHigh)
previousHigh := recentHigh
recentHigh := pivotHigh
if not na(pivotLow)
previousLow := recentLow
recentLow := pivotLow
upStructure = not na(previousHigh) and not na(previousLow) and recentHigh > previousHigh and recentLow > previousLow
downStructure = not na(previousHigh) and not na(previousLow) and recentHigh < previousHigh and recentLow < previousLow
structureText = upStructure ? "Bullish HH / HL" : downStructure ? "Bearish LH / LL" : "Mixed / waiting"
// 6. REACTIONS AND CLOSE-CONFIRMED SETUP WATCHES.
// A demand bounce requires a green candle touching demand and closing above demand midpoint.
// A supply rejection requires a red candle touching supply and closing below supply midpoint.
demandBounce = valid and barstate.isconfirmed and low <= demandTop and high >= demandBottom and close > demandMid and close > open
supplyRejection = valid and barstate.isconfirmed and high >= supplyBottom and low <= supplyTop and close < supplyMid and close < open
breakAboveSupply = ta.crossover(close, supplyTop)
breakBelowDemand = ta.crossunder(close, demandBottom)
supplyBreakout = valid and barstate.isconfirmed and breakAboveSupply
demandBreakdown = valid and barstate.isconfirmed and breakBelowDemand
enteredDemand = valid and barstate.isconfirmed and close <= demandTop and close >= demandBottom and close[1] > demandTop
enteredSupply = valid and barstate.isconfirmed and close >= supplyBottom and close <= supplyTop and close[1] < supplyBottom
longWatch = demandBounce and upStructure
shortWatch = supplyRejection and downStructure
plotshape(showReactions and demandBounce and not longWatch, title="Demand bounce", style=shape.triangleup, location=location.belowbar, color=color.lime, size=size.tiny, text="DB")
plotshape(showReactions and supplyRejection and not shortWatch, title="Supply rejection", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.tiny, text="SR")
plotshape(showSetups and longWatch, title="Sniper long watch", style=shape.labelup, location=location.belowbar, color=color.green, textcolor=color.white, text="LONG\nWATCH", size=size.tiny)
plotshape(showSetups and shortWatch, title="Sniper short watch", style=shape.labeldown, location=location.abovebar, color=color.maroon, textcolor=color.white, text="SHORT\nWATCH", size=size.tiny)
// 7. DASHBOARD: LOCATION > STRUCTURE > CONFIRMATION > EXECUTION.
locationText = not valid ? "SET FOUR ZONE EDGES" : close > supplyTop ? "Above supply" : close >= supplyBottom ? "Inside supply" : close > demandTop ? "Between zones" : close >= demandBottom ? "Inside demand" : "Below demand"
confirmationText = demandBounce ? "Demand bounce" : supplyRejection ? "Supply rejected" : supplyBreakout ? "Supply breakout" : demandBreakdown ? "Demand breakdown" : "Waiting for a close"
setupText = longWatch ? "LONG WATCH" : shortWatch ? "SHORT WATCH" : "NO SETUP"
var table dash = table.new(position.top_right, 2, 10, border_width=1)
if barstate.islast and showDashboard
table.cell(dash, 0, 0, "SNIPER TRADING", text_color=color.white, bgcolor=color.black, text_size=size.small)
table.cell(dash, 1, 0, syminfo.ticker, text_color=color.aqua, bgcolor=color.black, text_size=size.small)
table.cell(dash, 0, 1, "LOCATION", text_color=color.white, bgcolor=color.black, text_size=size.small)
table.cell(dash, 1, 1, locationText, text_color=color.white, bgcolor=color.black, text_size=size.small)
table.cell(dash, 0, 2, "STRUCTURE", text_color=color.white, bgcolor=color.black, text_size=size.small)
table.cell(dash, 1, 2, structureText, text_color=upStructure ? color.lime : downStructure ? color.red : color.yellow, bgcolor=color.black, text_size=size.small)
table.cell(dash, 0, 3, "CONFIRMATION", text_color=color.white, bgcolor=color.black, text_size=size.small)
table.cell(dash, 1, 3, confirmationText, text_color=color.white, bgcolor=color.black, text_size=size.small)
table.cell(dash, 0, 4, "EXECUTION", text_color=color.white, bgcolor=color.black, text_size=size.small)
table.cell(dash, 1, 4, setupText, text_color=longWatch ? color.lime : shortWatch ? color.red : color.yellow, bgcolor=color.black, text_size=size.small)
table.cell(dash, 0, 5, "SUPPLY MID", text_color=color.white, bgcolor=color.black, text_size=size.small)
table.cell(dash, 1, 5, valid ? str.tostring(supplyMid, format.mintick) : "-", text_color=color.white, bgcolor=color.black, text_size=size.small)
table.cell(dash, 0, 6, "DEMAND MID", text_color=color.white, bgcolor=color.black, text_size=size.small)
table.cell(dash, 1, 6, valid ? str.tostring(demandMid, format.mintick) : "-", text_color=color.white, bgcolor=color.black, text_size=size.small)
table.cell(dash, 0, 7, "EQUILIBRIUM", text_color=color.white, bgcolor=color.black, text_size=size.small)
table.cell(dash, 1, 7, valid ? str.tostring(equilibrium, format.mintick) : "-", text_color=color.yellow, bgcolor=color.black, text_size=size.small)
table.cell(dash, 0, 8, "BULL TARGET", text_color=color.white, bgcolor=color.black, text_size=size.small)
table.cell(dash, 1, 8, valid ? str.tostring(bullTarget, format.mintick) : "-", text_color=color.lime, bgcolor=color.black, text_size=size.small)
table.cell(dash, 0, 9, "BEAR TARGET", text_color=color.white, bgcolor=color.black, text_size=size.small)
table.cell(dash, 1, 9, valid ? str.tostring(bearTarget, format.mintick) : "-", text_color=color.red, bgcolor=color.black, text_size=size.small)
// 8. CREATE ALERTS FROM THE TRADINGVIEW ALERT DIALOG.
alertcondition(demandBounce, "Demand bounce", "{{ticker}}: bullish reaction from demand on confirmed candle.")
alertcondition(supplyRejection, "Supply rejection", "{{ticker}}: bearish reaction from supply on confirmed candle.")
alertcondition(demandBreakdown, "Demand breakdown", "{{ticker}}: candle closed below demand.")
alertcondition(supplyBreakout, "Supply breakout", "{{ticker}}: candle closed above supply.")
alertcondition(longWatch, "Sniper long watch", "{{ticker}}: bullish swing structure and demand reaction. Watch for your entry rules.")
alertcondition(shortWatch, "Sniper short watch", "{{ticker}}: bearish swing structure and supply rejection. Watch for your entry rules.")
alertcondition(enteredDemand, "Entered demand", "{{ticker}}: candle closed inside demand after trading above it.")
alertcondition(enteredSupply, "Entered supply", "{{ticker}}: candle closed inside supply after trading below it.")
alertcondition(openingHighBreak, "Opening range high break", "{{ticker}}: closed above the completed opening range high.")
alertcondition(openingLowBreak, "Opening range low break", "{{ticker}}: closed below the completed opening range low.")