Gold Liquidity Sweep V4 | Reversal Pro

Pussycat89 · study · 465 行 · 点赞 9 · TradingView 原页

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

Pine Script

//@version=6
indicator("Gold Liquidity Sweep V4 | Reversal Pro + 3-Mode Backtest", overlay = true, max_labels_count = 500, max_lines_count = 100)
 
// ============================================================================
// GOLD LIQUIDITY SWEEP V4 - REVERSAL PRO
// Three independent simulations run on every confirmed chart candle:
//   Aggressive:    confirmed sweep + close back beyond the swept swing.
//   Balanced:      sweep, then close beyond the OPPOSING confirmed pivot (MSS).
//   Conservative:  sweep, MSS, then a later rejection/retest of MSS price.
// Only the SELECTED mode paints trade levels and sends entry/exit alerts.
// Backtest comparison shows ALL 3 modes simultaneously, with 1 active trade
// per mode. This is an OHLC indicator simulation, NOT Strategy Tester.
// ============================================================================
 
// ─────────────────────────── USER INPUTS ────────────────────────────
string gSetup = "1. Sweep / reversal entries"
string entryMode = input.string("Balanced", "Selected entry mode", options = ["Aggressive", "Balanced", "Conservative"], group = gSetup)
int swingBars = input.int(4, "Confirmed pivot strength (left / right)", minval = 2, maxval = 20, group = gSetup)
int mssExpiry = input.int(12, "Max bars from sweep to MSS", minval = 1, maxval = 100, group = gSetup)
int retestExpiry = input.int(12, "Max bars from MSS to retest", minval = 1, maxval = 100, group = gSetup)
float retestTolATR = input.float(0.20, "Retest tolerance (ATR)", minval = 0.0, maxval = 2.0, step = 0.05, group = gSetup, tooltip = "For BUY, the retest candle LOW must reach within this ATR distance ABOVE the MSS level, then close back above it bullish. Opposite for SELL. Entry only on a later bar than the MSS.")
 
string gTrend = "2. Optional EMA filter"
bool filterOn = input.bool(false, "Use confirmed higher-timeframe EMA filter", group = gTrend)
string trendTf = input.timeframe("15", "EMA timeframe (e.g., 15 = M15)", group = gTrend)
int emaLength = input.int(200, "EMA period", minval = 1, group = gTrend)
bool showEMA = input.bool(false, "Show chart timeframe EMA", group = gTrend)
 
string gRisk = "3. Stop and profit targets"
int atrLength = input.int(14, "ATR period", minval = 1, group = gRisk)
float slBufferATR = input.float(0.20, "Stop buffer beyond sweep (ATR)", minval = 0.0, maxval = 3.0, step = 0.05, group = gRisk)
float tp1R = input.float(1.0, "TP1 (R multiple)", minval = 0.2, maxval = 20.0, step = 0.1, group = gRisk)
float tp2R = input.float(2.0, "TP2 (R multiple)", minval = 0.3, maxval = 30.0, step = 0.1, group = gRisk)
float tp1Percent = input.float(50.0, "Close at TP1 (% position)", minval = 10.0, maxval = 90.0, step = 5, group = gRisk)
bool moveBE = input.bool(true, "Move remaining SL to entry after TP1", group = gRisk)
 
string gDisplay = "4. Chart / setup panel / alerts"
bool showSwingLevels = input.bool(true, "Draw confirmed swing levels", group = gDisplay)
bool showMSS = input.bool(true, "Mark selected-mode MSS events", group = gDisplay)
bool showSetupPanel = input.bool(true, "Show setup panel", group = gDisplay)
string setupLocation = input.string("Top Right", "Setup panel position", options = ["Top Left", "Top Center", "Top Right", "Middle Left", "Middle Center", "Middle Right", "Bottom Left", "Bottom Center", "Bottom Right"], group = gDisplay)
bool detailedAlerts = input.bool(true, "Send detailed alert() messages", group = gDisplay)
 
string gBT = "5. Backtest comparison"
bool showBacktest = input.bool(true, "Show 3-mode backtest panel (ON/OFF)", group = gBT)
string backtestLocation = input.string("Bottom Left", "Backtest panel position", options = ["Top Left", "Top Center", "Top Right", "Middle Left", "Middle Center", "Middle Right", "Bottom Left", "Bottom Center", "Bottom Right"], group = gBT)
 
// Table positioning: independent 9-point anchors, with collision prevention.
tablePosition(string p) =>
    switch p
        "Top Left" => position.top_left
        "Top Center" => position.top_center
        "Top Right" => position.top_right
        "Middle Left" => position.middle_left
        "Middle Center" => position.middle_center
        "Middle Right" => position.middle_right
        "Bottom Left" => position.bottom_left
        "Bottom Center" => position.bottom_center
        => position.bottom_right
 
bool overlap = showSetupPanel and showBacktest and setupLocation == backtestLocation
string actualBTLocation = overlap ? (setupLocation == "Top Right" ? "Bottom Left" : "Top Right") : backtestLocation
 
int selected = entryMode == "Aggressive" ? 0 : entryMode == "Balanced" ? 1 : 2
float partial = tp1Percent / 100.0
float finalTPR = math.max(tp2R, tp1R + 0.1)
 
// Guard against accidentally selecting a chart timeframe as the "HTF".
if filterOn and timeframe.in_seconds(trendTf) <= timeframe.in_seconds(timeframe.period)
    runtime.error("EMA filter timeframe must be HIGHER than chart timeframe. E.g. on M5, select 15 or 60.")
 
// ───────────────────────── CONFIRMED LEVELS ──────────────────────────
float newPH = ta.pivothigh(high, swingBars, swingBars)
float newPL = ta.pivotlow(low, swingBars, swingBars)
var float lastPH = na
var float lastPL = na
if not na(newPH)
    lastPH := newPH
if not na(newPL)
    lastPL := newPL
 
float atr = ta.atr(atrLength)
float emaChart = ta.ema(close, emaLength)
// Last CLOSED higher-TF EMA. lookahead_on + [1] prevents HTF future leakage.
float emaHTF = request.security(syminfo.tickerid, trendTf, ta.ema(close, emaLength)[1], lookahead = barmerge.lookahead_on)
bool trendLong = not filterOn or (not na(emaHTF) and close > emaHTF)
bool trendShort = not filterOn or (not na(emaHTF) and close < emaHTF)
 
// Wick across a previously CONFIRMED pivot, candle closes back beyond it.
bool sweepLong = not na(lastPL) and low < lastPL and close > lastPL and close > open
bool sweepShort = not na(lastPH) and high > lastPH and close < lastPH and close < open
 
plot(showSwingLevels ? lastPH : na, "Confirmed pivot high", color.new(color.red, 65), 1, plot.style_stepline)
plot(showSwingLevels ? lastPL : na, "Confirmed pivot low", color.new(color.lime, 65), 1, plot.style_stepline)
plot(showEMA ? emaChart : na, "Chart EMA", color.orange, 2)
 
// ─────────────────────── INDEPENDENT MODE STATE ──────────────────────
// stage 0 idle; 1 waiting MSS; 2 waiting MSS retest.
// All fields persist because the objects are created once inside a var array.
type Engine
    int stage = 0
    int setupDir = 0
    int sweptAt = na
    int mssAt = na
    float sweepExtreme = na
    float sweptPivot = na
    float mssLevel = na
    bool inTrade = false
    int direction = 0
    int enteredAt = na
    int lastExitedAt = -1
    float entry = na
    float stop = na
    float tp1 = na
    float tp2 = na
    float risk = na
    bool reachedTP1 = false
    string status = "WAITING"
    int closed = 0
    int won = 0
    int lost = 0
    int flat = 0
    int hitTP1 = 0
    int hitTP2 = 0
    int stopExits = 0
    int beExits = 0
    float netR = 0.0
    float grossWinR = 0.0
    float grossLossR = 0.0
    float peakR = 0.0
    float maxDrawdownR = 0.0
    int lossStreak = 0
    int maxLossStreak = 0
 
var array<Engine> engines = array.from(Engine.new(), Engine.new(), Engine.new())
var int firstTime = na
if na(firstTime)
    firstTime := time
 
// Only events of SELECTED mode are plotted/alerted.
bool buySignal = false
bool sellSignal = false
bool mssLongSignal = false
bool mssShortSignal = false
bool tp1Event = false
bool tp2Event = false
bool slEvent = false
bool beEvent = false
 
if barstate.isconfirmed
    for i = 0 to 2
        Engine e = array.get(engines, i)
        bool opened = false
        bool tp1TouchedEvent = false
        bool tp2TouchedEvent = false
        bool slTouchedEvent = false
        bool beTouchedEvent = false
        bool mssEvent = false
        int mssDirection = 0
        float completedR = na
 
        // ── Step A: manage preexisting position. Entry candle cannot exit.
        if e.inTrade and bar_index > e.enteredAt
            bool touchedStop = e.direction == 1 ? low <= e.stop : high >= e.stop
            bool touchedTP1 = e.direction == 1 ? high >= e.tp1 : low <= e.tp1
            bool touchedTP2 = e.direction == 1 ? high >= e.tp2 : low <= e.tp2
 
            // Conservative, reproducible OHLC assumption: if stop and a TP
            // are BOTH within a candle's range, the STOP executes first.
            if touchedStop
                bool stoppedAtBE = e.reachedTP1 and moveBE and math.abs(e.stop - e.entry) <= syminfo.mintick
                float stopRemainder = (e.stop - e.entry) * e.direction / e.risk
                completedR := e.reachedTP1 ? partial * tp1R + (1.0 - partial) * stopRemainder : -1.0
                e.status := stoppedAtBE ? "CLOSED: TP1 + BE" : "CLOSED: STOP"
                beTouchedEvent := stoppedAtBE
                slTouchedEvent := not stoppedAtBE
                e.stopExits += stoppedAtBE ? 0 : 1
                e.beExits += stoppedAtBE ? 1 : 0
                e.inTrade := false
                e.lastExitedAt := bar_index
            else if touchedTP2
                tp1TouchedEvent := not e.reachedTP1
                tp2TouchedEvent := true
                e.reachedTP1 := true
                completedR := partial * tp1R + (1.0 - partial) * finalTPR
                e.status := "CLOSED: TP2 HIT"
                e.inTrade := false
                e.lastExitedAt := bar_index
            else if touchedTP1 and not e.reachedTP1
                tp1TouchedEvent := true
                e.reachedTP1 := true
                e.status := "TP1 HIT - TP2 OPEN"
                // Activated only AFTER this candle closes; no intrabar magic.
                if moveBE
                    e.stop := e.entry
 
            if tp1TouchedEvent
                e.hitTP1 += 1
            if tp2TouchedEvent
                e.hitTP2 += 1
 
            if not na(completedR)
                e.closed += 1
                e.netR += completedR
                if completedR > 0.000001
                    e.won += 1
                    e.grossWinR += completedR
                    e.lossStreak := 0
                else if completedR < -0.000001
                    e.lost += 1
                    e.grossLossR += math.abs(completedR)
                    e.lossStreak += 1
                    e.maxLossStreak := math.max(e.maxLossStreak, e.lossStreak)
                else
                    e.flat += 1
                    e.lossStreak := 0
                e.peakR := math.max(e.peakR, e.netR)
                e.maxDrawdownR := math.max(e.maxDrawdownR, e.peakR - e.netR)
 
        // ── Step B: track setups and create trades independently per mode.
        // Do not reenter on the same candle as an exit.
        if not e.inTrade and bar_index > e.lastExitedAt
            // Expiry / invalidation of setup, once the sweep candle has passed.
            if e.stage == 1 and bar_index - e.sweptAt > mssExpiry
                e.stage := 0
            if e.stage == 2 and bar_index - e.mssAt > retestExpiry
                e.stage := 0
            if e.stage > 0 and bar_index > e.sweptAt
                bool sweepInvalidated = e.setupDir == 1 ? low <= e.sweepExtreme : high >= e.sweepExtreme
                if sweepInvalidated
                    e.stage := 0
 
            // A fresh sweep supersedes an older pending setup (not an open trade).
            bool freshLong = sweepLong and trendLong and not na(atr)
            bool freshShort = sweepShort and trendShort and not na(atr)
            bool entryCandidate = false
            int candidateDir = 0
 
            if freshLong or freshShort
                e.setupDir := freshLong ? 1 : -1
                e.sweptAt := bar_index
                e.sweepExtreme := freshLong ? low : high
                e.sweptPivot := freshLong ? lastPL : lastPH
                // Snapshot the OPPOSING, already-confirmed pivot at sweep time.
                // BUY MSS: close ABOVE this pivot high; SELL below pivot low.
                e.mssLevel := freshLong ? lastPH : lastPL
                e.mssAt := na
                if i == 0
                    entryCandidate := true
                    candidateDir := e.setupDir
                    e.stage := 0
                else
                    // MSS must be on the appropriate side of sweep close.
                    bool validOpposingPivot = not na(e.mssLevel) and (freshLong ? e.mssLevel > close : e.mssLevel < close)
                    e.stage := validOpposingPivot ? 1 : 0
 
            // Balanced / Conservative MSS after sweep, NOT on sweep candle.
            if i > 0 and e.stage == 1 and bar_index > e.sweptAt
                bool bullMSS = e.setupDir == 1 and close > e.mssLevel and close > open and trendLong
                bool bearMSS = e.setupDir == -1 and close < e.mssLevel and close < open and trendShort
                if bullMSS or bearMSS
                    mssEvent := true
                    mssDirection := e.setupDir
                    e.mssAt := bar_index
                    if i == 1
                        entryCandidate := true
                        candidateDir := e.setupDir
                        e.stage := 0
                    else
                        e.stage := 2
 
            // Conservative: retest on a LATER candle than confirmed MSS.
            if i == 2 and e.stage == 2 and bar_index > e.mssAt
                bool bullRetest = e.setupDir == 1 and low <= e.mssLevel + retestTolATR * atr and close > e.mssLevel and close > open and trendLong
                bool bearRetest = e.setupDir == -1 and high >= e.mssLevel - retestTolATR * atr and close < e.mssLevel and close < open and trendShort
                if bullRetest or bearRetest
                    entryCandidate := true
                    candidateDir := e.setupDir
                    e.stage := 0
 
            if entryCandidate
                float proposedStop = candidateDir == 1 ? e.sweepExtreme - slBufferATR * atr : e.sweepExtreme + slBufferATR * atr
                float proposedRisk = math.abs(close - proposedStop)
                bool validSide = candidateDir == 1 ? proposedStop < close : proposedStop > close
                if validSide and proposedRisk >= syminfo.mintick and not na(proposedRisk)
                    e.direction := candidateDir
                    e.entry := close
                    e.stop := proposedStop
                    e.risk := proposedRisk
                    e.tp1 := e.entry + candidateDir * proposedRisk * tp1R
                    e.tp2 := e.entry + candidateDir * proposedRisk * finalTPR
                    e.enteredAt := bar_index
                    e.reachedTP1 := false
                    e.inTrade := true
                    e.status := candidateDir == 1 ? "ACTIVE BUY" : "ACTIVE SELL"
                    e.stage := 0
                    opened := true
                else
                    e.stage := 0
 
        // Selected mode controls the visible chart and alerts; all modes
        // accumulate separate stats on ALL confirmed historical candles.
        if i == selected
            buySignal := opened and e.direction == 1
            sellSignal := opened and e.direction == -1
            mssLongSignal := mssEvent and mssDirection == 1
            mssShortSignal := mssEvent and mssDirection == -1
            tp1Event := tp1TouchedEvent
            tp2Event := tp2TouchedEvent
            slEvent := slTouchedEvent
            beEvent := beTouchedEvent
 
// Reference to selected mode: same persistent object as in array.
Engine live = array.get(engines, selected)
 
// ─────────────────────────── DRAW ENTRY LEVELS ───────────────────────
var line lineEntry = na
var line lineStop = na
var line lineTP1 = na
var line lineTP2 = na
 
if buySignal or sellSignal
    if not na(lineEntry)
        line.delete(lineEntry)
    if not na(lineStop)
        line.delete(lineStop)
    if not na(lineTP1)
        line.delete(lineTP1)
    if not na(lineTP2)
        line.delete(lineTP2)
    lineEntry := line.new(bar_index, live.entry, bar_index + 1, live.entry, extend = extend.right, color = color.yellow, width = 2)
    lineStop := line.new(bar_index, live.stop, bar_index + 1, live.stop, extend = extend.right, color = color.red, width = 2)
    lineTP1 := line.new(bar_index, live.tp1, bar_index + 1, live.tp1, extend = extend.right, color = color.aqua, style = line.style_dashed, width = 2)
    lineTP2 := line.new(bar_index, live.tp2, bar_index + 1, live.tp2, extend = extend.right, color = color.lime, width = 2)
 
// Track break-even movement in the visual red stop line.
if tp1Event and moveBE and not na(lineStop) and live.inTrade
    line.set_y1(lineStop, live.stop)
    line.set_y2(lineStop, live.stop)
 
plotshape(buySignal, title = "BUY", style = shape.labelup, location = location.belowbar, color = color.lime, text = "BUY", textcolor = color.black, size = size.small)
plotshape(sellSignal, title = "SELL", style = shape.labeldown, location = location.abovebar, color = color.red, text = "SELL", textcolor = color.white, size = size.small)
plotshape(showMSS and mssLongSignal, title = "Bullish MSS", style = shape.triangleup, location = location.belowbar, color = color.aqua, text = "MSS", textcolor = color.aqua, size = size.tiny)
plotshape(showMSS and mssShortSignal, title = "Bearish MSS", style = shape.triangledown, location = location.abovebar, color = color.orange, text = "MSS", textcolor = color.orange, size = size.tiny)
plotshape(tp1Event, title = "TP1 reached", style = shape.circle, location = location.abovebar, color = color.aqua, text = "T1", textcolor = color.aqua, size = size.tiny)
plotshape(tp2Event, title = "TP2 reached", style = shape.labeldown, location = location.abovebar, color = color.lime, text = "T2", textcolor = color.black, size = size.tiny)
plotshape(slEvent, title = "SL reached", style = shape.xcross, location = location.abovebar, color = color.red, text = "SL", textcolor = color.red, size = size.small)
plotshape(beEvent, title = "BE exit", style = shape.circle, location = location.belowbar, color = color.yellow, text = "BE", textcolor = color.yellow, size = size.tiny)
 
alertcondition(buySignal, title = "BUY signal", message = "Gold Reversal Pro BUY | {{ticker}} {{interval}} close {{close}}")
alertcondition(sellSignal, title = "SELL signal", message = "Gold Reversal Pro SELL | {{ticker}} {{interval}} close {{close}}")
alertcondition(tp1Event, title = "TP1 hit", message = "Gold Reversal Pro TP1 | {{ticker}} {{interval}}")
alertcondition(tp2Event, title = "TP2 hit", message = "Gold Reversal Pro TP2 | {{ticker}} {{interval}}")
alertcondition(slEvent, title = "SL hit", message = "Gold Reversal Pro STOP | {{ticker}} {{interval}}")
alertcondition(beEvent, title = "BE exit", message = "Gold Reversal Pro BE | {{ticker}} {{interval}}")
alertcondition(mssLongSignal, title = "Bullish MSS", message = "Gold Reversal Pro bullish MSS | {{ticker}} {{interval}}")
alertcondition(mssShortSignal, title = "Bearish MSS", message = "Gold Reversal Pro bearish MSS | {{ticker}} {{interval}}")
 
if barstate.isconfirmed and detailedAlerts
    if buySignal or sellSignal
        string side = buySignal ? "BUY" : "SELL"
        alert(entryMode + " " + side + " " + syminfo.ticker + " " + timeframe.period + " | Entry " + str.tostring(live.entry, format.mintick) + " | SL " + str.tostring(live.stop, format.mintick) + " | TP1 " + str.tostring(live.tp1, format.mintick) + " | TP2 " + str.tostring(live.tp2, format.mintick), alert.freq_once_per_bar_close)
    // A bar may hit TP1 and TP2 together. Use ONE combined alert because
    // alert.freq_once_per_bar_close permits only one alert() on that bar.
    if tp2Event
        alert(entryMode + (tp1Event ? " TP1 + TP2 HIT " : " TP2 HIT ") + syminfo.ticker, alert.freq_once_per_bar_close)
    else if tp1Event
        alert(entryMode + " TP1 HIT " + syminfo.ticker, alert.freq_once_per_bar_close)
    if slEvent
        alert(entryMode + " STOP LOSS HIT " + syminfo.ticker, alert.freq_once_per_bar_close)
    if beEvent
        alert(entryMode + " BREAK-EVEN EXIT " + syminfo.ticker, alert.freq_once_per_bar_close)
 
// ────────────────────────── TWO MOVABLE PANELS ────────────────────────
priceString(float value) =>
    na(value) ? "—" : str.tostring(value, format.mintick)
num(float value) =>
    str.tostring(value, "#.##")
 
var table setupPanel = table.new(tablePosition(setupLocation), 2, 12, bgcolor = color.new(color.black, 8), frame_color = color.new(color.gray, 20), frame_width = 1, border_width = 1, border_color = color.new(color.gray, 70))
var table btPanel = table.new(tablePosition(actualBTLocation), 4, 13, bgcolor = color.new(color.black, 8), frame_color = color.new(color.gray, 20), frame_width = 1, border_width = 1, border_color = color.new(color.gray, 70))
 
setupRow(int r, string title, string value, color vColor) =>
    table.cell(setupPanel, 0, r, title, text_color = color.silver, text_size = size.small)
    table.cell(setupPanel, 1, r, value, text_color = vColor, text_size = size.small)
 
btMetric(int r, string metric, string ag, string ba, string co, bool colorBySign = false) =>
    table.cell(btPanel, 0, r, metric, text_color = color.silver, text_size = size.small)
    table.cell(btPanel, 1, r, ag, text_color = colorBySign ? (str.startswith(ag, "-") ? color.red : color.lime) : color.white, text_size = size.small, bgcolor = selected == 0 ? color.new(color.blue, 82) : na)
    table.cell(btPanel, 2, r, ba, text_color = colorBySign ? (str.startswith(ba, "-") ? color.red : color.lime) : color.white, text_size = size.small, bgcolor = selected == 1 ? color.new(color.blue, 82) : na)
    table.cell(btPanel, 3, r, co, text_color = colorBySign ? (str.startswith(co, "-") ? color.red : color.lime) : color.white, text_size = size.small, bgcolor = selected == 2 ? color.new(color.blue, 82) : na)
 
modeValue(Engine e, int metric) =>
    string value = "n/a"
    if metric == 0
        value := str.tostring(e.closed)
    else if metric == 1
        value := str.tostring(e.won)
    else if metric == 2
        value := str.tostring(e.lost)
    else if metric == 3
        value := e.closed > 0 ? num(e.won * 100.0 / e.closed) + "%" : "n/a"
    else if metric == 4
        value := str.tostring(e.hitTP1)
    else if metric == 5
        value := str.tostring(e.hitTP2)
    else if metric == 6
        value := num(e.netR) + " R"
    else if metric == 7
        value := e.closed > 0 ? num(e.netR / e.closed) + " R" : "n/a"
    else if metric == 8
        value := e.grossLossR > 0 ? num(e.grossWinR / e.grossLossR) : e.grossWinR > 0 ? "INF" : "n/a"
    else if metric == 9
        value := num(e.maxDrawdownR) + " R"
    else if metric == 10
        value := str.tostring(e.maxLossStreak)
    else if metric == 11
        value := e.inTrade ? "ACTIVE" : "FLAT"
    value
 
if barstate.islast
    if showSetupPanel
        table.cell(setupPanel, 0, 0, "GOLD REVERSAL V4", bgcolor = color.rgb(26, 42, 62), text_color = color.white, text_size = size.small)
        table.cell(setupPanel, 1, 0, entryMode, bgcolor = color.rgb(26, 42, 62), text_color = color.white, text_size = size.small)
        setupRow(1, "LAST SIGNAL", live.direction == 1 ? "BUY" : live.direction == -1 ? "SELL" : "NONE", live.direction == 1 ? color.lime : live.direction == -1 ? color.red : color.white)
        setupRow(2, "ENTRY", priceString(live.entry), color.yellow)
        setupRow(3, "SL (CURRENT)", priceString(live.stop), color.red)
        setupRow(4, "TP1", priceString(live.tp1), color.aqua)
        setupRow(5, "TP2", priceString(live.tp2), color.lime)
        setupRow(6, "ORIGINAL RISK", na(live.risk) ? "—" : priceString(live.risk) + " price", color.white)
        setupRow(7, "TRADE STATUS", live.status, live.inTrade ? color.aqua : color.silver)
        setupRow(8, "PENDING SETUP", live.stage == 1 ? "WAIT MSS" : live.stage == 2 ? "WAIT RETEST" : "NONE", color.white)
        setupRow(9, "MSS LEVEL", live.stage > 0 ? priceString(live.mssLevel) : "—", color.white)
        setupRow(10, "HTF FILTER", filterOn ? trendTf + " EMA " + str.tostring(emaLength) : "OFF", color.white)
        setupRow(11, "TP1 PARTIAL", num(tp1Percent) + "%", color.white)
    else
        table.clear(setupPanel, 0, 0, 1, 11)
 
    if showBacktest
        Engine a = array.get(engines, 0)
        Engine b = array.get(engines, 1)
        Engine c = array.get(engines, 2)
        table.cell(btPanel, 0, 0, "REVERSAL TEST", bgcolor = color.rgb(26, 42, 62), text_color = color.white, text_size = size.small)
        table.cell(btPanel, 1, 0, "AGGRESSIVE", bgcolor = color.rgb(26, 42, 62), text_color = color.white, text_size = size.tiny)
        table.cell(btPanel, 2, 0, "BALANCED", bgcolor = color.rgb(26, 42, 62), text_color = color.white, text_size = size.tiny)
        table.cell(btPanel, 3, 0, "CONSERV.", bgcolor = color.rgb(26, 42, 62), text_color = color.white, text_size = size.tiny)
        btMetric(1, "CLOSED", modeValue(a, 0), modeValue(b, 0), modeValue(c, 0))
        btMetric(2, "WINS", modeValue(a, 1), modeValue(b, 1), modeValue(c, 1))
        btMetric(3, "LOSSES", modeValue(a, 2), modeValue(b, 2), modeValue(c, 2))
        btMetric(4, "WIN RATE", modeValue(a, 3), modeValue(b, 3), modeValue(c, 3))
        btMetric(5, "TP1 HITS", modeValue(a, 4), modeValue(b, 4), modeValue(c, 4))
        btMetric(6, "TP2 HITS", modeValue(a, 5), modeValue(b, 5), modeValue(c, 5))
        btMetric(7, "NET R", modeValue(a, 6), modeValue(b, 6), modeValue(c, 6), true)
        btMetric(8, "AVG / TRADE", modeValue(a, 7), modeValue(b, 7), modeValue(c, 7), true)
        btMetric(9, "PROFIT FACTOR", modeValue(a, 8), modeValue(b, 8), modeValue(c, 8))
        btMetric(10, "CLOSED DD", modeValue(a, 9), modeValue(b, 9), modeValue(c, 9))
        btMetric(11, "MAX LOSS STREAK", modeValue(a, 10), modeValue(b, 10), modeValue(c, 10))
        btMetric(12, "POSITION", modeValue(a, 11), modeValue(b, 11), modeValue(c, 11))
    else
        table.clear(btPanel, 0, 0, 3, 12)
 
// Caveats: R is realized risk units, not dollars. Drawdown is based ONLY on
// the closed-trade R equity curve. Same-bar SL/TP touches are stop-first.
// No commissions, spreads, swap, slippage, gaps, or intrabar execution model.
// Pivot levels are NOT backdated; they exist only after right-side confirmation.

← 返回列表