Ultimate ORB & Momentum Dashboard v7.5

glenn1corbett · study · 417 行 · 点赞 6 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
indicator("Ultimate ORB & Momentum Dashboard v7.5", shorttitle="Ultimate ORB v7.5", overlay=true, max_lines_count=500, max_labels_count=300)
// Designed for 1-minute time-based charts. All times in New York time.
string TZ = "America/New_York"
orbChoice = input.string("5", "Active ORB for signals", options=["2", "5", "15"], group="Signal Rules")
confirmTF = input.string("1", "Confirmation candle timeframe (minutes)", options=["1", "2"], group="Signal Rules")
rangeBasis = input.string("Wicks", "ORB boundaries from", options=["Wicks", "Bodies"], group="Signal Rules")
callRsiLevel = input.float(60, "Chart RSI CALL minimum", minval=0, maxval=100, group="Signal Rules")
putRsiLevel = input.float(40, "Chart RSI PUT maximum", minval=0, maxval=100, group="Signal Rules")
rsiLen = input.int(14, "RSI length", minval=2, group="Signal Rules")
macdFast = input.int(12, "MACD fast", minval=1, group="Signal Rules")
macdSlow = input.int(26, "MACD slow", minval=2, group="Signal Rules")
macdSignal = input.int(9, "MACD signal", minval=1, group="Signal Rules")
showEarly = input.bool(true, "Show EARLY signals", group="Signals & Dashboard")
showConfirmed = input.bool(true, "Show CONFIRMED signals", group="Signals & Dashboard")
showAux = input.bool(true, "Show price/EMA 9 crossover dots", group="Signals & Dashboard")
showEma920Arrows = input.bool(true, "Show EMA 9/20 crossover arrows", group="Signals & Dashboard")
showDash = input.bool(true, "Show dashboard", group="Signals & Dashboard")
dashPosition = input.string("Top Right", "Dashboard position", options=["Top Right", "Top Left", "Bottom Right", "Bottom Left", "Middle Right", "Middle Left"], group="Dashboard Appearance")
dashSize = input.string("Small", "Dashboard text size", options=["Tiny", "Small", "Normal", "Large"], group="Dashboard Appearance")
dashHeader = input.color(color.black, "Header background", group="Dashboard Appearance")
dashLabelBg = input.color(color.new(color.black, 15), "Label background", group="Dashboard Appearance")
dashNeutral = input.color(color.gray, "Neutral status background", group="Dashboard Appearance")
dashCall = input.color(color.green, "CALL status background", group="Dashboard Appearance")
dashPut = input.color(color.red, "PUT status background", group="Dashboard Appearance")
dashText = input.color(color.white, "Dashboard text color", group="Dashboard Appearance")
 
showLabels = input.bool(true, "Show right-edge ORB labels", group="Signals & Dashboard")
showPMH = input.bool(true, "Premarket High", group="Reference Levels")
showPML = input.bool(true, "Premarket Low", group="Reference Levels")
showPDH = input.bool(true, "Previous Day High", group="Reference Levels")
showPDL = input.bool(true, "Previous Day Low", group="Reference Levels")
showPWH = input.bool(true, "Previous Week High", group="Reference Levels")
showPWL = input.bool(true, "Previous Week Low", group="Reference Levels")
pmHC = input.color(color.yellow, "Premarket High Color", group="Reference Levels")
pmLC = input.color(color.yellow, "Premarket Low Color", group="Reference Levels")
pdHC = input.color(color.lime, "Previous Day High Color", group="Reference Levels")
pdLC = input.color(color.red, "Previous Day Low Color", group="Reference Levels")
pwHC = input.color(color.lime, "Previous Week High Color", group="Reference Levels")
pwLC = input.color(color.red, "Previous Week Low Color", group="Reference Levels")
refWidth = input.int(1, "Reference Line Width", minval=1, maxval=5, group="Reference Levels")
pmHStyle = input.string("Dashed", "Premarket High Style", options=["Solid", "Dashed", "Dotted"], group="Reference Levels")
pmLStyle = input.string("Dashed", "Premarket Low Style", options=["Solid", "Dashed", "Dotted"], group="Reference Levels")
pdHStyle = input.string("Dashed", "Previous Day High Style", options=["Solid", "Dashed", "Dotted"], group="Reference Levels")
pdLStyle = input.string("Dashed", "Previous Day Low Style", options=["Solid", "Dashed", "Dotted"], group="Reference Levels")
pwHStyle = input.string("Dotted", "Previous Week High Style", options=["Solid", "Dashed", "Dotted"], group="Reference Levels")
pwLStyle = input.string("Dotted", "Previous Week Low Style", options=["Solid", "Dashed", "Dotted"], group="Reference Levels")
show2H = input.bool(true, "2m ORB High", group="Opening Ranges")
show2L = input.bool(true, "2m ORB Low", group="Opening Ranges")
show5H = input.bool(true, "5m ORB High", group="Opening Ranges")
show5L = input.bool(true, "5m ORB Low", group="Opening Ranges")
show15H = input.bool(true, "15m ORB High", group="Opening Ranges")
show15L = input.bool(true, "15m ORB Low", group="Opening Ranges")
c2h = input.color(color.blue, "2m High Color", group="Opening Ranges")
c2l = input.color(color.blue, "2m Low Color", group="Opening Ranges")
c5h = input.color(color.fuchsia, "5m High Color", group="Opening Ranges")
c5l = input.color(color.fuchsia, "5m Low Color", group="Opening Ranges")
c15h = input.color(color.red, "15m High Color", group="Opening Ranges")
c15l = input.color(color.red, "15m Low Color", group="Opening Ranges")
orb2Width = input.int(1, "2m ORB Width", minval=1, maxval=5, group="Opening Ranges")
orb5Width = input.int(2, "5m ORB Width", minval=1, maxval=5, group="Opening Ranges")
orb15Width = input.int(2, "15m ORB Width", minval=1, maxval=5, group="Opening Ranges")
orb2Style = input.string("Solid", "2m ORB Style", options=["Solid", "Dashed", "Dotted"], group="Opening Ranges")
orb5Style = input.string("Solid", "5m ORB Style", options=["Solid", "Dashed", "Dotted"], group="Opening Ranges")
orb15Style = input.string("Solid", "15m ORB Style", options=["Solid", "Dashed", "Dotted"], group="Opening Ranges")
showE5 = input.bool(true, "Show EMA 5", group="Moving Averages")
showE9 = input.bool(true, "Show EMA 9", group="Moving Averages")
showE20 = input.bool(true, "Show EMA 20", group="Moving Averages")
showE200 = input.bool(true, "Show EMA 200", group="Moving Averages")
showVwap = input.bool(true, "Show VWAP", group="Moving Averages")
e5c = input.color(color.orange, "EMA 5 Color", group="Moving Averages")
e9c = input.color(color.lime, "EMA 9 Color", group="Moving Averages")
e20c = input.color(color.blue, "EMA 20 Color", group="Moving Averages")
e200c = input.color(color.red, "EMA 200 Color", group="Moving Averages")
vwapc = input.color(color.white, "VWAP Color", group="Moving Averages")
e5w = input.int(1, "EMA 5 Width", minval=1, maxval=5, group="Moving Averages")
e9w = input.int(1, "EMA 9 Width", minval=1, maxval=5, group="Moving Averages")
e20w = input.int(1, "EMA 20 Width", minval=1, maxval=5, group="Moving Averages")
e200w = input.int(1, "EMA 200 Width", minval=1, maxval=5, group="Moving Averages")
vwapw = input.int(1, "VWAP Width", minval=1, maxval=5, group="Moving Averages")
 
// Two independently configurable trade-management exits. They do not affect entry confirmation.
stopGroup = "Stop Loss Settings"
showAtrStop = input.bool(true, "Show ATR Trailing Stop", group=stopGroup)
atrLength = input.int(14, "ATR Length", minval=1, group=stopGroup)
atrMultiplier = input.float(1.0, "ATR Multiplier", minval=0.1, step=0.1, group=stopGroup)
atrTF = input.timeframe("", "ATR Timeframe (blank = chart)", group=stopGroup)
atrStopColor = input.color(color.red, "ATR Stop Color", group=stopGroup)
atrStopStyle = input.string("Dashed", "ATR Stop Line Style", options=["Solid", "Dashed", "Dotted"], group=stopGroup)
atrStopWidth = input.int(2, "ATR Stop Line Width", minval=1, maxval=5, group=stopGroup)
atrStopAlerts = input.bool(true, "Enable ATR STOP Alerts", group=stopGroup)
showEma7Stop = input.bool(true, "Show 7 EMA Stop Loss", group=stopGroup)
emaStopLength = input.int(7, "EMA Stop Length", minval=1, group=stopGroup)
emaStopColor = input.color(color.red, "7 EMA Stop Color", group=stopGroup)
emaStopStyle = input.string("Dashed", "7 EMA Stop Line Style", options=["Solid", "Dashed", "Dotted"], group=stopGroup)
emaStopWidth = input.int(2, "7 EMA Stop Line Width", minval=1, maxval=5, group=stopGroup)
emaStopAlerts = input.bool(true, "Enable 7 EMA EXIT Alerts", group=stopGroup)
showStopLabels = input.bool(true, "Show STOP / EXIT Labels", group=stopGroup)
 
lineStyle(s) => s == "Dotted" ? line.style_dotted : s == "Dashed" ? line.style_dashed : line.style_solid
// Return the current line handle; update only the latest session's line.
levelLine(line existing, float price, bool visible, color clr, int width, string sty, bool fresh) =>
    line result = existing
    if fresh
        if not na(result)
            line.delete(result)
        result := na
    if visible and not na(price)
        if na(result)
            result := line.new(bar_index, price, bar_index + 1, price, extend=extend.right, color=clr, width=width, style=lineStyle(sty))
        else
            line.set_y1(result, price)
            line.set_y2(result, price)
            line.set_color(result, clr)
            line.set_width(result, width)
            line.set_style(result, lineStyle(sty))
    result
 
// NY date and session timestamps; chart should be 1-minute for precise ORBs.
yy = year(time, TZ)
mm = month(time, TZ)
dd = dayofmonth(time, TZ)
startPM = timestamp(TZ, yy, mm, dd, 4, 0)
openNY = timestamp(TZ, yy, mm, dd, 9, 30)
end2 = timestamp(TZ, yy, mm, dd, 9, 32)
end5 = timestamp(TZ, yy, mm, dd, 9, 35)
end15 = timestamp(TZ, yy, mm, dd, 9, 45)
closeNY = timestamp(TZ, yy, mm, dd, 16, 0)
newDay = na(time[1]) or yy != year(time[1], TZ) or mm != month(time[1], TZ) or dd != dayofmonth(time[1], TZ)
inPM = time >= startPM and time < openNY
inRTH = time >= openNY and time < closeNY
srcH = rangeBasis == "Bodies" ? math.max(open, close) : high
srcL = rangeBasis == "Bodies" ? math.min(open, close) : low
var float pmH = na
var float pmL = na
var float o2H = na
var float o2L = na
var float o5H = na
var float o5L = na
var float o15H = na
var float o15L = na
if newDay
    pmH := na
    pmL := na
    o2H := na
    o2L := na
    o5H := na
    o5L := na
    o15H := na
    o15L := na
if inPM
    pmH := na(pmH) ? high : math.max(pmH, high)
    pmL := na(pmL) ? low : math.min(pmL, low)
if time >= openNY and time < end2
    o2H := na(o2H) ? srcH : math.max(o2H, srcH)
    o2L := na(o2L) ? srcL : math.min(o2L, srcL)
if time >= openNY and time < end5
    o5H := na(o5H) ? srcH : math.max(o5H, srcH)
    o5L := na(o5L) ? srcL : math.min(o5L, srcL)
if time >= openNY and time < end15
    o15H := na(o15H) ? srcH : math.max(o15H, srcH)
    o15L := na(o15L) ? srcL : math.min(o15L, srcL)
 
pdh = request.security(syminfo.tickerid, "D", high[1], lookahead=barmerge.lookahead_on)
pdl = request.security(syminfo.tickerid, "D", low[1], lookahead=barmerge.lookahead_on)
pwh = request.security(syminfo.tickerid, "W", high[1], lookahead=barmerge.lookahead_on)
pwl = request.security(syminfo.tickerid, "W", low[1], lookahead=barmerge.lookahead_on)
var line lPMH = na
var line lPML = na
var line lPDH = na
var line lPDL = na
var line lPWH = na
var line lPWL = na
var line l2H = na
var line l2L = na
var line l5H = na
var line l5L = na
var line l15H = na
var line l15L = na
lPMH := levelLine(lPMH, pmH, showPMH and time >= startPM, pmHC, refWidth, pmHStyle, newDay)
lPML := levelLine(lPML, pmL, showPML and time >= startPM, pmLC, refWidth, pmLStyle, newDay)
lPDH := levelLine(lPDH, pdh, showPDH, pdHC, refWidth, pdHStyle, newDay)
lPDL := levelLine(lPDL, pdl, showPDL, pdLC, refWidth, pdLStyle, newDay)
lPWH := levelLine(lPWH, pwh, showPWH, pwHC, refWidth, pwHStyle, newDay)
lPWL := levelLine(lPWL, pwl, showPWL, pwLC, refWidth, pwLStyle, newDay)
l2H := levelLine(l2H, time >= end2 ? o2H : na, show2H, c2h, orb2Width, orb2Style, newDay)
l2L := levelLine(l2L, time >= end2 ? o2L : na, show2L, c2l, orb2Width, orb2Style, newDay)
l5H := levelLine(l5H, time >= end5 ? o5H : na, show5H, c5h, orb5Width, orb5Style, newDay)
l5L := levelLine(l5L, time >= end5 ? o5L : na, show5L, c5l, orb5Width, orb5Style, newDay)
l15H := levelLine(l15H, time >= end15 ? o15H : na, show15H, c15h, orb15Width, orb15Style, newDay)
l15L := levelLine(l15L, time >= end15 ? o15L : na, show15L, c15l, orb15Width, orb15Style, newDay)
 
// Right-edge labels: recreated on last chart bar only.
var label[] edgeLabels = array.new<label>()
if barstate.islast
    for lab in edgeLabels
        label.delete(lab)
    array.clear(edgeLabels)
    if showLabels
        if show2H and not na(o2H) and time >= end2
            array.push(edgeLabels, label.new(bar_index + 2, o2H, "2min ORB High", style=label.style_label_left, color=c2h, textcolor=color.black, size=size.tiny))
        if show2L and not na(o2L) and time >= end2
            array.push(edgeLabels, label.new(bar_index + 2, o2L, "2min ORB Low", style=label.style_label_left, color=c2l, textcolor=color.black, size=size.tiny))
        if show5H and not na(o5H) and time >= end5
            array.push(edgeLabels, label.new(bar_index + 2, o5H, "5min ORB High", style=label.style_label_left, color=c5h, textcolor=color.white, size=size.tiny))
        if show5L and not na(o5L) and time >= end5
            array.push(edgeLabels, label.new(bar_index + 2, o5L, "5min ORB Low", style=label.style_label_left, color=c5l, textcolor=color.white, size=size.tiny))
        if show15H and not na(o15H) and time >= end15
            array.push(edgeLabels, label.new(bar_index + 2, o15H, "15min ORB High", style=label.style_label_left, color=c15h, textcolor=color.black, size=size.tiny))
        if show15L and not na(o15L) and time >= end15
            array.push(edgeLabels, label.new(bar_index + 2, o15L, "15min ORB Low", style=label.style_label_left, color=c15l, textcolor=color.black, size=size.tiny))
 
e5 = ta.ema(close, 5)
e9 = ta.ema(close, 9)
e20 = ta.ema(close, 20)
e200 = ta.ema(close, 200)
vwap = ta.vwap(hlc3)
plot(showE5 ? e5 : na, "EMA 5", color=e5c, linewidth=e5w)
plot(showE9 ? e9 : na, "EMA 9", color=e9c, linewidth=e9w)
plot(showE20 ? e20 : na, "EMA 20", color=e20c, linewidth=e20w)
plot(showE200 ? e200 : na, "EMA 200", color=e200c, linewidth=e200w)
plot(showVwap ? vwap : na, "Session VWAP", color=vwapc, linewidth=vwapw)
[macd, macdSig, macdHist] = ta.macd(close, macdFast, macdSlow, macdSignal)
// RSI follows the active chart timeframe (not a fixed 2-minute request).
chartRsi = ta.rsi(close, rsiLen)
activeHigh = orbChoice == "2" ? o2H : orbChoice == "5" ? o5H : o15H
activeLow = orbChoice == "2" ? o2L : orbChoice == "5" ? o5L : o15L
activeEnd = orbChoice == "2" ? end2 : orbChoice == "5" ? end5 : end15
orbReady = inRTH and time >= activeEnd and not na(activeHigh) and not na(activeLow)
// For 2m mode, two distinct *completed* 2-minute bars must each begin after ORB end.
// A 9:35 end means a 9:34-9:36 candle is not eligible.
twoMClose1 = request.security(syminfo.tickerid, "2", close[1], lookahead=barmerge.lookahead_on)
twoMClose2 = request.security(syminfo.tickerid, "2", close[2], lookahead=barmerge.lookahead_on)
twoMStart1 = request.security(syminfo.tickerid, "2", time[1], lookahead=barmerge.lookahead_on)
twoMStart2 = request.security(syminfo.tickerid, "2", time[2], lookahead=barmerge.lookahead_on)
confirmUp1 = orbReady and time[1] >= activeEnd and close > activeHigh and close[1] > activeHigh
confirmDn1 = orbReady and time[1] >= activeEnd and close < activeLow and close[1] < activeLow
confirmUp2 = orbReady and twoMStart2 >= activeEnd and twoMClose1 > activeHigh and twoMClose2 > activeHigh
confirmDn2 = orbReady and twoMStart2 >= activeEnd and twoMClose1 < activeLow and twoMClose2 < activeLow
orbUp = confirmTF == "1" ? confirmUp1 : confirmUp2
orbDn = confirmTF == "1" ? confirmDn1 : confirmDn2
// The four required confirmations are ORB, two chart candles relative to EMA 9,
// VWAP agreement, and RSI on the chart's current timeframe.
ema9TwoUp = barstate.isconfirmed and close > e9 and close[1] > e9
ema9TwoDown = barstate.isconfirmed and close < e9 and close[1] < e9
vwapUp = not na(vwap) and close > vwap
vwapDown = not na(vwap) and close < vwap
rsiCall = chartRsi >= callRsiLevel
rsiPut = chartRsi <= putRsiLevel
callReady = barstate.isconfirmed and orbUp and ema9TwoUp and vwapUp and rsiCall
putReady = barstate.isconfirmed and orbDn and ema9TwoDown and vwapDown and rsiPut
callEvent = callReady and (not callReady[1] or newDay)
putEvent = putReady and (not putReady[1] or newDay)
// Unconfirmed / early = after selected ORB forms, inside its boundaries;
// MACD, RSI and current price/EMA 9 agreement; no VWAP or breakout requirement.
insideORB = orbReady and close < activeHigh and close > activeLow
earlyCall = barstate.isconfirmed and insideORB and macd > macdSig and rsiCall and close > e9
earlyPut = barstate.isconfirmed and insideORB and macd < macdSig and rsiPut and close < e9
earlyCallEvent = earlyCall and (not earlyCall[1] or newDay)
earlyPutEvent = earlyPut and (not earlyPut[1] or newDay)
plotshape(showEarly and earlyCallEvent, title="EARLY CALL", style=shape.triangleup, location=location.belowbar, color=color.new(color.lime, 20), size=size.tiny, text="EARLY")
plotshape(showEarly and earlyPutEvent, title="EARLY PUT", style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 20), size=size.tiny, text="EARLY")
plotshape(showConfirmed and callEvent, title="CALL CONFIRMED", style=shape.labelup, location=location.belowbar, color=color.green, textcolor=color.white, text="CALL", size=size.small)
plotshape(showConfirmed and putEvent, title="PUT CONFIRMED", style=shape.labeldown, location=location.abovebar, color=color.red, textcolor=color.white, text="PUT", size=size.small)
 
// --- Stop-loss tracking (independent of entry confirmation) ---
// Fixed higher-timeframe ATR uses the last fully completed HTF candle to avoid lookahead.
// Choose a timeframe equal to or above the chart timeframe for predictable results.
chartAtr = ta.atr(atrLength)
fixedAtr = request.security(syminfo.tickerid, atrTF == "" ? timeframe.period : atrTF, ta.atr(atrLength)[1], lookahead=barmerge.lookahead_on)
atrValue = atrTF == "" ? chartAtr : fixedAtr
ema7Stop = ta.ema(close, emaStopLength)
 
// Stop calculations begin only after a new CONFIRMED entry. Each method can exit
// independently; the other method remains active for visual comparison.
var int stopDirection = 0  // +1 CALL, -1 PUT
var int stopEntryBar = na
var bool atrTracking = false
var bool emaTracking = false
var float atrTrail = na
var float favorableExtreme = na
var float priorAtrPlot = na
var float priorEmaPlot = na
var line[] atrSegments = array.new<line>()
var line[] emaSegments = array.new<line>()
 
// Only keep the most recent segments to stay within TradingView's object limit.
maxSegments = 190
newEntryCall = callEvent
newEntryPut = putEvent
if newDay
    stopDirection := 0
    stopEntryBar := na
    atrTracking := false
    emaTracking := false
    atrTrail := na
    favorableExtreme := na
    priorAtrPlot := na
    priorEmaPlot := na
if newEntryCall or newEntryPut
    stopDirection := newEntryCall ? 1 : -1
    stopEntryBar := bar_index
    atrTracking := showAtrStop
    emaTracking := showEma7Stop
    favorableExtreme := newEntryCall ? high : low
    atrTrail := na(atrValue) ? na : newEntryCall ? high - atrMultiplier * atrValue : low + atrMultiplier * atrValue
    priorAtrPlot := na
    priorEmaPlot := na
 
bool atrExitCall = false
bool atrExitPut = false
bool emaExitCall = false
bool emaExitPut = false
bool canCheckStops = barstate.isconfirmed and stopDirection != 0 and not na(stopEntryBar) and bar_index > stopEntryBar
if canCheckStops
    if atrTracking and not na(atrTrail)
        // Check the *previously established* stop first, then advance it for the next bar.
        // This prevents a bar's own high/low from retroactively raising its stop.
        bool atrTouched = stopDirection == 1 ? low <= atrTrail : high >= atrTrail
        if atrTouched
            atrExitCall := stopDirection == 1
            atrExitPut := stopDirection == -1
            atrTracking := false
        else
            favorableExtreme := stopDirection == 1 ? math.max(favorableExtreme, high) : math.min(favorableExtreme, low)
            if not na(atrValue)
                float candidate = stopDirection == 1 ? favorableExtreme - atrMultiplier * atrValue : favorableExtreme + atrMultiplier * atrValue
                atrTrail := stopDirection == 1 ? math.max(atrTrail, candidate) : math.min(atrTrail, candidate)
    if emaTracking
        bool emaCrossed = stopDirection == 1 ? close < ema7Stop : close > ema7Stop
        if emaCrossed
            emaExitCall := stopDirection == 1
            emaExitPut := stopDirection == -1
            emaTracking := false
 
// Dashed lines are drawn with line objects (plot() does not reliably support
// dashed historical traces across Pine versions). Each stop is separate.
float currentAtrPlot = showAtrStop and atrTracking and stopDirection != 0 ? atrTrail : na
float currentEmaPlot = showEma7Stop and emaTracking and stopDirection != 0 ? ema7Stop : na
if barstate.isconfirmed
    if not na(currentAtrPlot) and not na(priorAtrPlot)
        line seg = line.new(bar_index - 1, priorAtrPlot, bar_index, currentAtrPlot, color=atrStopColor, width=atrStopWidth, style=lineStyle(atrStopStyle))
        array.push(atrSegments, seg)
        if array.size(atrSegments) > maxSegments
            line.delete(array.shift(atrSegments))
    if not na(currentEmaPlot) and not na(priorEmaPlot)
        line seg = line.new(bar_index - 1, priorEmaPlot, bar_index, currentEmaPlot, color=emaStopColor, width=emaStopWidth, style=lineStyle(emaStopStyle))
        array.push(emaSegments, seg)
        if array.size(emaSegments) > maxSegments
            line.delete(array.shift(emaSegments))
    priorAtrPlot := currentAtrPlot
    priorEmaPlot := currentEmaPlot
 
plotshape(showStopLabels and atrExitCall, title="ATR STOP CALL", style=shape.labeldown, location=location.abovebar, color=color.red, textcolor=color.white, text="ATR STOP", size=size.tiny)
plotshape(showStopLabels and atrExitPut, title="ATR STOP PUT", style=shape.labelup, location=location.belowbar, color=color.red, textcolor=color.white, text="ATR STOP", size=size.tiny)
plotshape(showStopLabels and emaExitCall, title="7 EMA EXIT CALL", style=shape.labeldown, location=location.abovebar, color=color.maroon, textcolor=color.white, text="7 EMA EXIT", size=size.tiny)
plotshape(showStopLabels and emaExitPut, title="7 EMA EXIT PUT", style=shape.labelup, location=location.belowbar, color=color.maroon, textcolor=color.white, text="7 EMA EXIT", size=size.tiny)
alertcondition(atrStopAlerts and atrExitCall, "ATR STOP CALL", "ATR trailing stop triggered for CALL on {{ticker}} {{interval}}")
alertcondition(atrStopAlerts and atrExitPut, "ATR STOP PUT", "ATR trailing stop triggered for PUT on {{ticker}} {{interval}}")
alertcondition(emaStopAlerts and emaExitCall, "7 EMA EXIT CALL", "Candle closed below 7 EMA after CALL on {{ticker}} {{interval}}")
alertcondition(emaStopAlerts and emaExitPut, "7 EMA EXIT PUT", "Candle closed above 7 EMA after PUT on {{ticker}} {{interval}}")
 
priceUp9 = ta.crossover(close, e9) and barstate.isconfirmed
priceDown9 = ta.crossunder(close, e9) and barstate.isconfirmed
cross5up = ta.crossover(e5, e9) and barstate.isconfirmed
cross5dn = ta.crossunder(e5, e9) and barstate.isconfirmed
cross9up = ta.crossover(e9, e20) and barstate.isconfirmed
cross9dn = ta.crossunder(e9, e20) and barstate.isconfirmed
plotshape(showAux and priceUp9, title="Price Cross Above EMA 9", text="", style=shape.circle, location=location.belowbar, color=color.lime, size=size.tiny)
plotshape(showAux and priceDown9, title="Price Cross Below EMA 9", text="", style=shape.circle, location=location.abovebar, color=color.red, size=size.tiny)
plotshape(showEma920Arrows and cross9up, title="EMA 9 crosses ABOVE EMA 20", style=shape.triangleup, location=location.belowbar, color=color.lime, size=size.small)
plotshape(showEma920Arrows and cross9dn, title="EMA 9 crosses BELOW EMA 20", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)
 
alertcondition(earlyCallEvent, "EARLY CALL", "EARLY CALL on {{ticker}} {{interval}}")
alertcondition(earlyPutEvent, "EARLY PUT", "EARLY PUT on {{ticker}} {{interval}}")
alertcondition(callEvent, "CALL CONFIRMED", "4/4 CALL CONFIRMED on {{ticker}} {{interval}}")
alertcondition(putEvent, "PUT CONFIRMED", "4/4 PUT CONFIRMED on {{ticker}} {{interval}}")
alertcondition(priceUp9, "Price crosses above EMA 9", "Price crossed above EMA 9 on {{ticker}}")
alertcondition(priceDown9, "Price crosses below EMA 9", "Price crossed below EMA 9 on {{ticker}}")
alertcondition(cross5up, "EMA 5 crosses above 9", "EMA 5/9 bullish cross on {{ticker}}")
alertcondition(cross5dn, "EMA 5 crosses below 9", "EMA 5/9 bearish cross on {{ticker}}")
alertcondition(cross9up, "EMA 9 crosses above 20", "EMA 9/20 bullish cross on {{ticker}}")
alertcondition(cross9dn, "EMA 9 crosses below 20", "EMA 9/20 bearish cross on {{ticker}}")
rsi50up = ta.crossover(chartRsi, 50) and barstate.isconfirmed
rsi50dn = ta.crossunder(chartRsi, 50) and barstate.isconfirmed
alertcondition(rsi50up, "Chart RSI crosses above 50", "RSI crossed above 50 on {{ticker}} {{interval}}")
alertcondition(rsi50dn, "Chart RSI crosses below 50", "RSI crossed below 50 on {{ticker}} {{interval}}")
 
// Six dashboard rows, with adjustable location, size and colors.
dashPos = switch dashPosition
    "Top Left" => position.top_left
    "Bottom Right" => position.bottom_right
    "Bottom Left" => position.bottom_left
    "Middle Right" => position.middle_right
    "Middle Left" => position.middle_left
    => position.top_right
textSize = switch dashSize
    "Tiny" => size.tiny
    "Normal" => size.normal
    "Large" => size.large
    => size.small
var table dash = table.new(dashPos, 2, 6, border_width=1)
statusBg(bool bull, bool bear) => bull ? dashCall : bear ? dashPut : dashNeutral
statusText(bool bull, bool bear) => bull ? "CALL" : bear ? "PUT" : "WAITING"
writeRow(int index, string name, string value, color bg) =>
    table.cell(dash, 0, index, name, bgcolor=dashLabelBg, text_color=dashText, text_size=textSize)
    table.cell(dash, 1, index, value, bgcolor=bg, text_color=dashText, text_size=textSize)
if barstate.islast
    if showDash
        writeRow(0, "ORB (" + orbChoice + "m)", orbUp ? "ABOVE HIGH" : orbDn ? "BELOW LOW" : "WAITING", statusBg(orbUp, orbDn))
        writeRow(1, "9 EMA / 2 Candles", ema9TwoUp ? "ABOVE" : ema9TwoDown ? "BELOW" : "WAITING", statusBg(ema9TwoUp, ema9TwoDown))
        writeRow(2, "VWAP", vwapUp ? "ABOVE" : vwapDown ? "BELOW" : "WAITING", statusBg(vwapUp, vwapDown))
        writeRow(3, "RSI (Chart TF)", na(chartRsi) ? "N/A" : str.tostring(chartRsi, "#.0") + (rsiCall ? " CALL" : rsiPut ? " PUT" : " NEUTRAL"), statusBg(rsiCall, rsiPut))
        writeRow(4, "Unconfirmed", statusText(earlyCall, earlyPut), statusBg(earlyCall, earlyPut))
        writeRow(5, "Confirmed", callReady ? "CALL CONFIRMED" : putReady ? "PUT CONFIRMED" : "WAITING", statusBg(callReady, putReady))
    else
        table.clear(dash, 0, 0, 1, 5)

← 返回列表