本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// PHOENIX OPEN REVERSAL v0.9 — 2026-10-25 — 1 Corinthians 13:4-7 — Phoenix desk build (personal use). REPLACES v0.4c.
// Rebuilt on the v0.1 foundation, the only build that rendered on the chart, using only Pine constructs that build used
// (plots, shapes, bar colours, boxes, labels, tables, fixed-offset history, simple arrays). Nothing that first appeared
// in the builds that failed with RE10140 is used: no variable-offset history, no polylines, no chart points, no pivots.
// Sources read in full before this build (descriptions, code where public, chart images): Premarket High/Low & Opening
// Candle & PDH/PDL (SoulVouge, protected); Opening Range Retest (BruzX); Reversal Candlestick Structure (LuxAlgo, geometry
// only, non-commercial attribution kept); Manipulation Candle Detector (pratikpaul0127, protected); Liquidation/Doji Candles
// (The_Forex_Steward); Opening Candle Zone with ATR Bands (nkCharts); Gaussian Smooth Trend (QuantEdgeB, graded, not a
// trigger: left out of this build); HV Pivot S&R Zones (BigBeluga, left out of this build: its polyline/pivot constructs are
// on the suspect list); Reversal Entry Zones (tradewsamet, left out for the same reason); the desk's own PMH / PML Opening
// Drive Breakout module (PHOENIX_PMH.pine, 805 lines, SMB Capital model): its rules are ported here unchanged — RVOL > 3,
// rejection wick <= 0.5 x body, close beyond PDH and PDC, one alert per side per day, 10-minute late window, SPY / QQQ filter.
// NEW IN v0.5 (the driver's spec of 2026-10-25): WATCH = fast / slow MA cross (5 / 9 by default) with price on the right side
// of VWAP and of yesterday's close -> small yellow box, top centre. CONFIRM = a positive candle identifier in that direction
// while the watch is live (PMH / PML breakout candle, two-candle reversal confirmed by the larger opposite candle,
// manipulation candle, liquidation/doji break, engulfing on volume) -> green (long) or red (short) box. Each box clears a
// set number of minutes after its candle (default 5, adjustable).
// v0.5a: every colour and placement is an input; doji-range break is OFF as a CONFIRM source by default after the
// 2026-10-25 replay (SPY+QQQ, 30 sessions, 5-min: it fired on about one bar in five and graded below the coin-toss baseline).
// v0.6: WATCH fires on any fast/slow cross and says ABOVE or BELOW VWAP; the SPY/QQQ and PDC gates are off by default (they hid
// the 10/20 open long and the 10/45 top); blocked crosses show a grey dot whose tooltip names the rule that blocked them; sweep-and-
// reclaim of a level is a named RECLAIM identifier that can CONFIRM on its own; signals run all session by default; right-edge labels
// merge when levels sit together; box opacity is an input; the grading table has a live status row and a same-chart BASELINE row;
// Ehlers 4-pole Gaussian filter, length 21 (PROVISIONAL: which "21 Gaussian" the driver means is an open question).
// v0.7: box fill opacity lives on the colour swatch only (the v0.6 % input overrode it and looked dead); boxes live N x their length
// (default 3) then stop; OCH / OCL ride the box as small black text; level lines are line objects with one shared set of width /
// style / ray inputs and label text / size / style / price inputs (the Rays-style controls the driver asked for).
// v0.8: from the 10-name replay. CONFIRM = identifier + 5/9 cross within N bars either way, after the first 15 minutes, inside the
// window (defaults 6 bars, 15 min, 60 min: PROVISIONAL, n under 100). Reclaim alone and the other candle identifiers are off as confirm
// sources (graded at or below the coin toss). Every CONFIRMED trade draws its stop and 1R / 2R lines and prints STOPPED / 1R / 2R; the
// table grades by the ATR race and by 1R-before-stop beside the same-chart BASELINE. Dashboard tiny; one opening box at a time (selector).
// v0.9: WATCH and its box only inside the signal window by default; exit mode input (default: first close through the slow MA,
// the PMH module's runner rule; replay +0.23R vs +0.14R for a fixed 2R, n 97, PROVISIONAL), printed as EXIT with the R reached.
// Intraday swing sweeps were tested as an identifier and graded at or below baseline, so they are not added.
// Status: v0.5 through v0.8 RENDERED on the driver's chart. v0.9 built on v0.8, awaiting render. Nothing here is a trade. Every default number is PROVISIONAL unless the
// source it came from is named beside it.
//@version=6
indicator("PHOENIX Open Reversal v0.9", "PHX OpnRev", overlay = true, max_labels_count = 500, max_lines_count = 500, max_boxes_count = 500)
// ───────────────────────────── 1 · SESSION ─────────────────────────────
gS = "1 · Session and timeframe"
tz = input.string("America/New_York", "Exchange time zone", group = gS)
rthSess = input.session("0930-1600", "Regular session", group = gS)
pmSess = input.session("0400-0929", "Premarket session (chart needs extended hours ON)", group = gS)
onSess = input.session("1600-0929", "Overnight session (prior close to open)", group = gS)
windowMin = input.int(60, "Signal window (minutes after 9:30) for RECLAIM / CONFIRM (replay: 15-60 best; PROVISIONAL)", minval = 5, maxval = 390, group = gS)
sigSkipMin = input.int(15, "Ignore the first N minutes for RECLAIM / CONFIRM (replay: opening-candle reclaims were the worst bucket)", minval = 0, maxval = 120, group = gS)
tfGuard = input.bool(true, "Warn when chart is not 2, 3, 5, 15 or 30 minutes", group = gS)
// ───────────────────────────── 2 · LEVELS ─────────────────────────────
gL = "2 · Levels and labels (each on/off)"
showPMH = input.bool(true, "PMH", group = gL, inline = "a")
showPML = input.bool(true, "PML", group = gL, inline = "a")
showONH = input.bool(true, "ONH", group = gL, inline = "a")
showONL = input.bool(true, "ONL", group = gL, inline = "a")
showPDH = input.bool(true, "PDH", group = gL, inline = "b")
showPDL = input.bool(true, "PDL", group = gL, inline = "b")
showPDC = input.bool(true, "PDC", group = gL, inline = "b")
showLvlLabels = input.bool(true, "Level labels at the right edge", group = gL, inline = "ll")
lblOffset = input.int(3, "bars right of price", minval = 0, maxval = 50, group = gL, inline = "ll")
lblMerge = input.float(0.25, "merge labels closer than ATR ×", minval = 0, step = 0.05, group = gL, inline = "ll")
lblOpaque = input.bool(true, "Solid label background", group = gL, inline = "ll")
lblSize = input.string("normal", "Label size", options = ["tiny", "small", "normal", "large"], group = gL)
openBox = input.string("Opening candle", "Opening box (one at a time)", options = ["Opening candle", "Opening range", "None"], group = gL, inline = "c")
showOC = openBox == "Opening candle"
ocMode = input.string("Chart timeframe", "Opening candle length", options = ["Chart timeframe", "Fixed minutes"], group = gL, inline = "c")
ocMin = input.int(5, "Fixed minutes", options = [1, 2, 3, 5, 15, 30], group = gL, inline = "c")
showOCatr = input.bool(true, "Opening candle ATR bands (nkCharts)", group = gL, inline = "d")
ocAtrMult = input.float(1.0, "ATR ×", minval = 0.1, step = 0.1, group = gL, inline = "d")
cOCatr = input.color(#ff9800, "band colour", group = gL, inline = "d")
showOR = openBox == "Opening range"
orMin = input.int(15, "Opening range minutes (when that box is chosen)", options = [5, 15, 30, 60], group = gL, inline = "e")
showVWAP = input.bool(true, "VWAP", group = gL, inline = "f")
vwapAnchor = input.string("9:30 open", "VWAP anchor", options = ["9:30 open", "4:00 premarket"], group = gL, inline = "f")
showPMbox = input.bool(true, "Premarket PMH–PML box (PMH module)", group = gL, inline = "pb")
cPMbox = input.color(color.new(#42a5f5, 90), "", group = gL, inline = "pb")
cPM = input.color(#f23645, "PM", group = gL, inline = "g")
cON = input.color(#ff9800, "ON", group = gL, inline = "g")
cPD = input.color(#f2c14e, "PD", group = gL, inline = "g")
cOC = input.color(#089981, "OC border", group = gL, inline = "g")
cOR = input.color(#2962ff, "OR border", group = gL, inline = "g")
cVW = input.color(#c48cff, "VWAP", group = gL, inline = "g")
cOCfill = input.color(color.new(#089981, 85), "OC box fill (set opacity on this swatch)", group = gL, inline = "bf")
cORfill = input.color(color.new(#2962ff, 80), "OR box fill (set opacity on this swatch)", group = gL, inline = "bf")
lifeMult = input.float(3, "Box lives for × its own length, then stops (5-min box → 15 min; 15 → 45)", minval = 0.5, step = 0.5, group = gL)
lifeRemove = input.bool(false, "Remove the box when its life ends (off = it stays, ended)", group = gL)
ocLblOn = input.bool(true, "OCH / OCL text just above and below the opening-candle box", group = gL, inline = "ol")
ocLblCol = input.color(#000000, "", group = gL, inline = "ol")
ocLblSize = input.string("small", "", options = ["tiny", "small", "normal"], group = gL, inline = "ol")
gLL = "2b · Level lines and labels (one set for all levels)"
lvlWidth = input.int(1, "Line width", minval = 1, maxval = 4, group = gLL, inline = "lw")
lvlStyle = input.string("solid", "style", options = ["solid", "dashed", "dotted"], group = gLL, inline = "lw")
lvlRay = input.bool(true, "Extend today's levels to the right edge (rays); off = segment to the current bar", group = gLL)
lvlHistory = input.bool(true, "Keep earlier days' levels as segments", group = gLL)
lblTextCol = input.color(#ffffff, "Label text colour", group = gLL, inline = "lt")
lblShowPrice = input.bool(true, "show price", group = gLL, inline = "lt")
lblStyle = input.string("label_left", "Label style", options = ["label_left", "label_right", "label_center", "label_up", "label_down", "none"], group = gLL)
// ───────────────────────────── 3 · AVERAGES ─────────────────────────────
gA = "3 · Averages (the WATCH cross uses fast / slow)"
showMA1 = input.bool(true, "Fast MA", group = gA, inline = "m1")
ma1Len = input.int(5, "len", minval = 1, group = gA, inline = "m1")
ma1Type = input.string("EMA", "type", options = ["EMA", "SMA", "WMA"], group = gA, inline = "m1")
showMA2 = input.bool(true, "Slow MA", group = gA, inline = "m2")
ma2Len = input.int(9, "len", minval = 1, group = gA, inline = "m2")
ma2Type = input.string("EMA", "type", options = ["EMA", "SMA", "WMA"], group = gA, inline = "m2")
showMAcloud = input.bool(true, "Cloud between fast and slow", group = gA)
showGauss = input.bool(true, "Gaussian filter line (Ehlers, 4 poles)", group = gA, inline = "ga")
gaussLen = input.int(21, "length", minval = 2, group = gA, inline = "ga")
gaussPoles = input.int(4, "poles", minval = 1, maxval = 4, group = gA, inline = "ga")
cGaussUp = input.color(#26c6da, "rising", group = gA, inline = "gc")
cGaussDn = input.color(#ab47bc, "falling", group = gA, inline = "gc")
cMA1 = input.color(#ffffff, "fast", group = gA, inline = "mc")
cMA2 = input.color(#9aa4b1, "slow", group = gA, inline = "mc")
// ───────────────────────────── 4 · CANDLE IDENTIFIERS ─────────────────────────────
gK = "4 · Candle identifiers (each on/off; each can CONFIRM a watch)"
useTwo = input.bool(true, "Two consecutive reversal candles → both bright yellow", group = gK)
twoDoji = input.bool(true, "doji counts", group = gK, inline = "t1")
twoHammer = input.bool(true, "hammer / hanging man counts", group = gK, inline = "t1")
twoStar = input.bool(true, "shooting star / inv. hammer counts", group = gK, inline = "t1")
dojiBodyPct = input.float(30, "Doji: body % of range below (Liquidation/Doji source default)", minval = 1, maxval = 100, group = gK)
useConfirm = input.bool(true, "Triangle on the next larger candle that turns the other way", group = gK)
confirmWithin = input.int(5, "…within this many bars (PROVISIONAL)", minval = 1, maxval = 20, group = gK)
cYellow = input.color(#ffea00, "Setup candle", group = gK, inline = "k1")
cBull = input.color(#00e676, "Bull", group = gK, inline = "k1")
cBear = input.color(#ff1744, "Bear", group = gK, inline = "k1")
useManip = input.bool(true, "Manipulation candle (sweeps the prior bar, closes through the other side)", group = gK)
cManipBull = input.color(#089981, "manip bull", group = gK, inline = "mc")
cManipBear = input.color(#5bc0eb, "manip bear", group = gK, inline = "mc")
cDojiLine = input.color(#ff9800, "doji line", group = gK, inline = "mc")
manipAllDay = input.bool(false, "Manipulation all day (off = open window only)", group = gK, inline = "mn")
manipColor = input.bool(true, "colour the candle (green bull / sky-blue bear, as the source)", group = gK, inline = "mn")
useDoji = input.bool(true, "Liquidation/doji candle (orange, with the source's line through its range) + break of its range", group = gK)
useEng = input.bool(true, "Engulfing candle on volume (body engulfs the prior body, bar RVOL ≥ below)", group = gK, inline = "en")
engRvol = input.float(1.5, "RVOL", minval = 0.5, step = 0.1, group = gK, inline = "en")
// ───────────────────────────── 5 · PMH / PML OPENING DRIVE BREAKOUT (desk module, SMB Capital model) ─────────────────────────────
gP = "5 · PMH / PML breakout (desk module rules, unchanged)"
pbOn = input.bool(true, "Enable", group = gP)
pbAllowL = input.bool(true, "Long (close above PMH)", group = gP, inline = "pa")
pbAllowS = input.bool(true, "Short (close below PML)", group = gP, inline = "pa")
pbAnyTf = input.bool(true, "Allow timeframes other than 2m / 5m", group = gP)
pbRvolMin = input.float(3.0, "Minimum RVOL (module: 3)", minval = 0, step = 0.25, group = gP, inline = "pr")
pbRvolMode = input.string("Cumulative", "RVOL type", options = ["Cumulative", "Bar"], group = gP, inline = "pr")
pbRvolN = input.int(20, "RVOL baseline: sessions averaged (same clock slot)", minval = 1, maxval = 60, group = gP)
pbAnyBar = input.bool(true, "Alert on the first candle that meets every rule (off = breakout candle only)", group = gP)
pbLateMin = input.int(10, "Later-candle and momentum alerts only within N minutes of the break (0 = no limit)", minval = 0, maxval = 390, group = gP)
pbNeedColor = input.bool(true, "Candle must close green (long) / red (short)", group = gP)
pbWickMax = input.float(0.5, "Max rejection wick (× body)", minval = 0, step = 0.05, group = gP)
pbMaxSig = input.int(1, "Max alerts per direction per day", minval = 1, maxval = 10, group = gP)
pbUseMom = input.bool(true, "MOMENTUM alert: beyond the PMH / PML with RVOL building", group = gP, inline = "pm")
pbMomRvol = input.float(2.0, "min bar RVOL", minval = 0.5, step = 0.25, group = gP, inline = "pm")
pbUseMkt = input.bool(true, "Require SPY / QQQ above (below) their daily EMA", group = gP, inline = "mk")
pbMktMode = input.string("Both", "", options = ["Both", "Either", "SPY only", "QQQ only"], group = gP, inline = "mk")
pbMktLen = input.int(10, "EMA", minval = 1, group = gP, inline = "mk")
pbSpySym = input.symbol("AMEX:SPY", "SPY", group = gP, inline = "ms")
pbQqqSym = input.symbol("NASDAQ:QQQ", "QQQ", group = gP, inline = "ms")
pbShowStop = input.bool(true, "Stop line at the alert candle's low / high", group = gP)
pbLongCol = input.color(#00c853, "Long", group = gP, inline = "pc")
pbShortCol = input.color(#ff1744, "Short", group = gP, inline = "pc")
// ───────────────────────────── 6 · WATCH → CONFIRM ─────────────────────────────
gW = "6 · WATCH (cross on the VWAP side) → CONFIRM (candle identifier)"
useWatch = input.bool(true, "Enable", group = gW)
wCrossLook = input.int(3, "Cross must be within the last N candles (module: 3)", minval = 0, maxval = 20, group = gW)
wVwapMode = input.string("Any side (tag ABOVE / BELOW VWAP)", "VWAP rule", options = ["Any side (tag ABOVE / BELOW VWAP)", "Long above / short below only"], group = gW)
wNeedPdc = input.bool(false, "Price must also be on the same side of yesterday's close (PMH module rule; off for reversals)", group = gW)
wRvolMin = input.float(1.0, "Minimum RVOL for a WATCH (module: 1; 0 = none)", minval = 0, step = 0.25, group = gW)
wUseMkt = input.bool(false, "WATCH needs the SPY / QQQ daily filter (PMH module rule; off for reversals)", group = gW)
wShowBlocked = input.bool(true, "Grey dot on a cross that did not become a WATCH (tooltip names the rule)", group = gW)
wWindowOnly = input.bool(true, "WATCH only inside the signal window (off = tags all day)", group = gW)
wOnce = input.bool(false, "One WATCH per direction per day (module rule; off = re-arm after a stop or an expired watch)", group = gW)
cWithinBars = input.int(6, "Identifier and 5/9 cross must be within N bars of each other, either order (replay: 6; PROVISIONAL)", minval = 1, maxval = 100, group = gW)
cWindowOnly = input.bool(true, "CONFIRM only inside the signal window and after the ignored minutes", group = gW)
cPMH = input.bool(true, "PMH / PML breakout candle", group = gW, inline = "c1")
cTwo = input.bool(false, "two-candle reversal (replay: at baseline)", group = gW, inline = "c1")
cMan = input.bool(false, "manipulation candle (replay: below baseline)", group = gW, inline = "c2")
cDj = input.bool(false, "doji-range break (off: replay graded it below baseline)", group = gW, inline = "c2")
cEn = input.bool(false, "engulfing on volume (replay: below baseline)", group = gW, inline = "c2")
cRc = input.bool(true, "sweep & reclaim of a level (RECLAIM)", group = gW, inline = "c3")
rcNoWatch = input.bool(false, "RECLAIM alone may CONFIRM, no cross needed (replay: below baseline)", group = gW, inline = "c3")
showTrade = input.bool(true, "Draw stop and 1R / 2R lines for each CONFIRMED trade, print STOPPED / 1R / 2R / EXIT", group = gW)
exitMode = input.string("First close through the slow MA", "Trade ends on", options = ["First close through the slow MA", "Stop or 2R only"], group = gW, tooltip = "Replay 2026-10-25, n 97: close-through-the-9 +0.23R per trade vs +0.14R for a fixed 2R. PROVISIONAL.")
clrMin = input.int(5, "Box clears this many minutes after its candle", minval = 1, maxval = 390, group = gW)
tagPos = input.string("Top center", "Box position", options = ["Top left", "Top center", "Top right", "Middle left", "Middle center", "Middle right", "Bottom left", "Bottom center", "Bottom right"], group = gW)
tagSize = input.string("small", "Box text size", options = ["tiny", "small", "normal", "large"], group = gW)
cWatch = input.color(#ffea00, "WATCH", group = gW, inline = "wc")
cLong = input.color(#00c853, "CONFIRMED long", group = gW, inline = "wc")
cShort = input.color(#ff1744, "CONFIRMED short", group = gW, inline = "wc")
markWatch = input.bool(true, "Small WATCH / CONFIRM tags on the candles too", group = gW)
// ───────────────────────────── 7 · SWEEP CORE AND GRADING ─────────────────────────────
gC = "7 · Sweep and reclaim (pop & drop / drop & pop) — small markers"
useSweep = input.bool(true, "Enable", group = gC, inline = "s0")
showSweepMarks = input.bool(true, "show markers", group = gC, inline = "s0")
cSwpDn = input.color(#ff1744, "pop&drop", group = gC, inline = "s0")
cSwpUp = input.color(#00e676, "drop&pop", group = gC, inline = "s0")
sweepDepth = input.float(0.2, "Minimum sweep depth (ATR ×)", minval = 0, step = 0.05, group = gC, tooltip = "Evidence 30 sessions SPY+QQQ 5-min, first 60 min, RTH-only ATR: pop & drop 63% (n=136) vs 51% baseline; with depth ≥ 0.2 ATR 64%. PROVISIONAL.")
onePerLevel = input.bool(true, "One signal per level per direction per session", group = gC)
atrLen = input.int(14, "ATR length (regular-hours bars only)", minval = 2, group = gC)
gV = "8 · Grading table"
showDash = input.bool(true, "Grading table", group = gV, inline = "d")
dashLoc = input.string("Top right", "position", options = ["Top left", "Top center", "Top right", "Middle left", "Middle center", "Middle right", "Bottom left", "Bottom center", "Bottom right"], group = gV, inline = "d")
dashSize = input.string("tiny", "size", options = ["tiny", "small", "normal"], group = gV, inline = "d")
dashStatus = input.bool(true, "Live status row (RVOL · VWAP side · market filter)", group = gV)
dashBaseline = input.bool(true, "BASELINE row: the same race from every bar, both ways (what a coin toss scores here)", group = gV)
cDashBg = input.color(color.new(#1e222d, 15), "background", group = gV, inline = "d")
tgtATR = input.float(0.5, "Hit = +ATR ×", minval = 0.1, step = 0.1, group = gV, inline = "h")
stopATR = input.float(0.5, "before −ATR ×", minval = 0.1, step = 0.1, group = gV, inline = "h")
horizon = input.int(12, "within bars", minval = 1, group = gV, inline = "h")
labelSizeOf(string s) => s == "tiny" ? size.tiny : s == "normal" ? size.normal : s == "large" ? size.large : size.small
// ───────────────────────────── SESSION CLOCK ─────────────────────────────
bool inRTH = not na(time(timeframe.period, rthSess, tz))
bool inPM = not na(time(timeframe.period, pmSess, tz))
bool inON = not na(time(timeframe.period, onSess, tz))
bool newDay = ta.change(dayofmonth(time, tz)) != 0
bool rthFirst = inRTH and (not inRTH[1] or newDay)
var int sessStart = na
if rthFirst
sessStart := time
int minsSinceOpen = na(sessStart) ? na : math.round((time - sessStart) / 60000.0)
bool inWindow = inRTH and not na(minsSinceOpen) and minsSinceOpen < windowMin
int tfMin = timeframe.isminutes ? timeframe.multiplier : 0
bool tfOK = tfMin == 2 or tfMin == 3 or tfMin == 5 or tfMin == 15 or tfMin == 30
int slot = inRTH and not na(minsSinceOpen) and tfMin > 0 ? math.min(math.floor(minsSinceOpen / tfMin), 399) : -1
// ───────────────────────────── ATR FROM REGULAR-HOURS BARS ONLY ─────────────────────────────
var float[] trBuf = array.new_float()
float trNow = ta.tr(true)
if inRTH and barstate.isconfirmed
array.push(trBuf, trNow)
if array.size(trBuf) > atrLen
array.shift(trBuf)
float atrAll = ta.atr(atrLen)
float atr = array.size(trBuf) > 0 ? array.sum(trBuf) / array.size(trBuf) : atrAll
// ───────────────────────────── RVOL: same clock slot averaged over the last N sessions (module method, standalone) ─────────────────────────────
var float[] slotBar = array.new_float(400, na)
var float[] slotCum = array.new_float(400, na)
var float cumVol = 0.
if rthFirst
cumVol := 0.
if inRTH
cumVol := cumVol + nz(volume)
float baseBar = slot >= 0 ? array.get(slotBar, slot) : na
float baseCum = slot >= 0 ? array.get(slotCum, slot) : na
float rvolBar = not na(baseBar) and baseBar > 0 ? nz(volume) / baseBar : na
float rvolCum = not na(baseCum) and baseCum > 0 ? cumVol / baseCum : na
if slot >= 0 and barstate.isconfirmed
array.set(slotBar, slot, na(baseBar) ? nz(volume) : baseBar + (nz(volume) - baseBar) / pbRvolN)
array.set(slotCum, slot, na(baseCum) ? cumVol : baseCum + (cumVol - baseCum) / pbRvolN)
float rvol = pbRvolMode == "Cumulative" ? rvolCum : rvolBar
float rvolSimple = volume / math.max(ta.sma(volume, 20), 1e-9)
// ───────────────────────────── LEVELS ─────────────────────────────
[pdh, pdl, pdc] = request.security(syminfo.tickerid, "D", [high[1], low[1], close[1]], lookahead = barmerge.lookahead_on)
var float pmh = na
var float pml = na
var float onh = na
var float onl = na
var float pmhT = na
var float pmlT = na
var float onhT = na
var float onlT = na
var int pmStartBar = na
if inPM
pmhT := na(pmhT) or not inPM[1] ? high : math.max(pmhT, high)
pmlT := na(pmlT) or not inPM[1] ? low : math.min(pmlT, low)
if not inPM[1]
pmStartBar := bar_index
if inON
onhT := na(onhT) or not inON[1] ? high : math.max(onhT, high)
onlT := na(onlT) or not inON[1] ? low : math.min(onlT, low)
if rthFirst
pmh := pmhT
pml := pmlT
onh := onhT
onl := onlT
pmhT := na
pmlT := na
onhT := na
onlT := na
int ocMinutes = ocMode == "Chart timeframe" ? math.max(tfMin, 1) : ocMin
var float ocH = na
var float ocL = na
var float ocAtr = na
var float rthOpen = na
var int ocStartBar = na
var bool ocDone = false
if rthFirst
ocH := high
ocL := low
ocAtr := atr
rthOpen := open
ocStartBar := bar_index
ocDone := false
else if inRTH and not na(minsSinceOpen) and minsSinceOpen < ocMinutes
ocH := math.max(ocH, high)
ocL := math.min(ocL, low)
bool ocCompleteBar = inRTH and not na(minsSinceOpen) and minsSinceOpen + tfMin >= ocMinutes and not ocDone
if ocCompleteBar
ocDone := true
bool ocReady = ocDone and not ocCompleteBar
var float orH = na
var float orL = na
var int orStartBar = na
var bool orDone = false
if rthFirst
orH := high
orL := low
orStartBar := bar_index
orDone := false
else if inRTH and not na(minsSinceOpen) and minsSinceOpen < orMin
orH := math.max(orH, high)
orL := math.min(orL, low)
bool orCompleteBar = inRTH and not na(minsSinceOpen) and minsSinceOpen + tfMin >= orMin and not orDone
if orCompleteBar
orDone := true
bool orReady = orDone and not orCompleteBar
// VWAP anchor
var float vwPV = 0.
var float vwV = 0.
bool vwReset = vwapAnchor == "9:30 open" ? rthFirst : ((inPM and not inPM[1]) or (rthFirst and not inPM[1]))
if vwReset
vwPV := 0.
vwV := 0.
if inRTH or (vwapAnchor == "4:00 premarket" and inPM)
vwPV := vwPV + hlc3 * nz(volume)
vwV := vwV + nz(volume)
float vwap = vwV > 0 ? vwPV / vwV : na
// ───────────────────────────── AVERAGES ─────────────────────────────
float ma1e = ta.ema(close, ma1Len)
float ma1s = ta.sma(close, ma1Len)
float ma1w = ta.wma(close, ma1Len)
float ma2e = ta.ema(close, ma2Len)
float ma2s = ta.sma(close, ma2Len)
float ma2w = ta.wma(close, ma2Len)
float ma1 = ma1Type == "SMA" ? ma1s : ma1Type == "WMA" ? ma1w : ma1e
float ma2 = ma2Type == "SMA" ? ma2s : ma2Type == "WMA" ? ma2w : ma2e
float gBeta = (1 - math.cos(2 * math.pi / gaussLen)) / (math.pow(2, 1.0 / gaussPoles) - 1)
float gAlpha = -gBeta + math.sqrt(gBeta * gBeta + 2 * gBeta)
float g1 = 1 - gAlpha
var float gf = na
float gfP1 = nz(gf[1], close)
float gfP2 = nz(gf[2], close)
float gfP3 = nz(gf[3], close)
float gfP4 = nz(gf[4], close)
gf := gaussPoles == 1 ? gAlpha * close + g1 * gfP1 : gaussPoles == 2 ? math.pow(gAlpha, 2) * close + 2 * g1 * gfP1 - math.pow(g1, 2) * gfP2 : gaussPoles == 3 ? math.pow(gAlpha, 3) * close + 3 * g1 * gfP1 - 3 * math.pow(g1, 2) * gfP2 + math.pow(g1, 3) * gfP3 : math.pow(gAlpha, 4) * close + 4 * g1 * gfP1 - 6 * math.pow(g1, 2) * gfP2 + 4 * math.pow(g1, 3) * gfP3 - math.pow(g1, 4) * gfP4
bool gaussUp = gf > gf[1]
int sinceXUp = ta.barssince(ta.crossover(ma1, ma2))
int sinceXDn = ta.barssince(ta.crossunder(ma1, ma2))
bool xUpRecent = ma1 > ma2 and not na(sinceXUp) and sinceXUp <= wCrossLook
bool xDnRecent = ma1 < ma2 and not na(sinceXDn) and sinceXDn <= wCrossLook
// ───────────────────────────── MARKET FILTER (SPY / QQQ vs daily EMA, module method) ─────────────────────────────
float spyPx = request.security(pbSpySym, timeframe.period, close)
float qqqPx = request.security(pbQqqSym, timeframe.period, close)
float spyEmaD = request.security(pbSpySym, "D", ta.ema(close, pbMktLen)[1], lookahead = barmerge.lookahead_on)
float qqqEmaD = request.security(pbQqqSym, "D", ta.ema(close, pbMktLen)[1], lookahead = barmerge.lookahead_on)
bool spyUp = not na(spyPx) and not na(spyEmaD) and spyPx > spyEmaD
bool spyDn = not na(spyPx) and not na(spyEmaD) and spyPx < spyEmaD
bool qqqUp = not na(qqqPx) and not na(qqqEmaD) and qqqPx > qqqEmaD
bool qqqDn = not na(qqqPx) and not na(qqqEmaD) and qqqPx < qqqEmaD
bool mktUp = not pbUseMkt or (pbMktMode == "Both" ? spyUp and qqqUp : pbMktMode == "Either" ? spyUp or qqqUp : pbMktMode == "SPY only" ? spyUp : qqqUp)
bool mktDn = not pbUseMkt or (pbMktMode == "Both" ? spyDn and qqqDn : pbMktMode == "Either" ? spyDn or qqqDn : pbMktMode == "SPY only" ? spyDn : qqqDn)
// ───────────────────────────── CANDLE GEOMETRY (LuxAlgo port, fixed offsets only) ─────────────────────────────
bool rc = close < open
bool gc = close > open
float cTop = math.max(open, close)
float cBot = math.min(open, close)
float hlW = high - low
float bodW = cTop - cBot
float hwPer = hlW > 0 ? (high - cTop) / hlW * 100 : 0
float lwPer = hlW > 0 ? (cBot - low) / hlW * 100 : 0
float bPer = hlW > 0 ? bodW / hlW * 100 : 100
bool dojiEq = math.round_to_mintick(close) == math.round_to_mintick(open)
bool smallBody = hlW > 0 and bPer < dojiBodyPct
bool hammerG = lwPer > bPer * 2 and bPer < 50 and hwPer < 2 and not dojiEq
bool ihammerG = hwPer > bPer * 2 and bPer < 50 and lwPer < 2 and not dojiEq
bool revCandle = (twoDoji and smallBody) or (twoHammer and hammerG) or (twoStar and ihammerG)
// Two consecutive reversal candles → yellow; then the next larger candle that turns the other way → triangle
bool twoSetupAny = useTwo and inRTH and revCandle and revCandle[1]
var float setHigh = na
var float setLow = na
var float setBody = na
var int setBar = na
if twoSetupAny
setHigh := math.max(high, high[1])
setLow := math.min(low, low[1])
setBody := math.max(bodW, bodW[1])
setBar := bar_index
bool setLive = not na(setBar) and bar_index > setBar and bar_index - setBar <= confirmWithin
bool confBull = useConfirm and setLive and gc and bodW > setBody and close > setHigh
bool confBear = useConfirm and setLive and rc and bodW > setBody and close < setLow
if confBull or confBear
setBar := na
// Manipulation candle (Manipulation Candle Detector description: sweeps the prior bar's low and closes above its high, and the mirror)
bool manipScope = manipAllDay ? inRTH : inWindow
bool manipBull = useManip and manipScope and low < low[1] and close > high[1]
bool manipBear = useManip and manipScope and high > high[1] and close < low[1]
// Liquidation / doji break (source: body under 30% of range; alerts on a close through its high / low)
var float liqH = na
var float liqL = na
if smallBody and useDoji and inRTH
liqH := high
liqL := low
bool dojiBreakUp = useDoji and inRTH and not na(liqH) and close > liqH and not smallBody
bool dojiBreakDn = useDoji and inRTH and not na(liqL) and close < liqL and not smallBody
if dojiBreakUp or dojiBreakDn
liqH := na
liqL := na
if useDoji and smallBody and inRTH
line.new(bar_index, high, bar_index, low, color = cDojiLine, width = 2)
// Engulfing on volume (body engulfs the prior body, closes beyond it, volume at least the RVOL below)
float rvolForEng = na(rvolBar) ? rvolSimple : rvolBar
bool engBull = useEng and inRTH and gc and rc[1] and open <= cBot[1] and close >= cTop[1] and bodW > bodW[1] and rvolForEng >= engRvol
bool engBear = useEng and inRTH and rc and gc[1] and open >= cTop[1] and close <= cBot[1] and bodW > bodW[1] and rvolForEng >= engRvol
// ───────────────────────────── SWEEP AND RECLAIM ─────────────────────────────
sweptUp(float lv) => not na(lv) and high > lv and close < lv and (high - lv) >= sweepDepth * atr
sweptDn(float lv) => not na(lv) and low < lv and close > lv and (lv - low) >= sweepDepth * atr
var bool uPDH = false
var bool uPMH = false
var bool uONH = false
var bool uOCH = false
var bool uORH = false
var bool uPDL = false
var bool uPML = false
var bool uONL = false
var bool uOCL = false
var bool uORL = false
if rthFirst
uPDH := false
uPMH := false
uONH := false
uOCH := false
uORH := false
uPDL := false
uPML := false
uONL := false
uOCL := false
uORL := false
bool upHit = false
bool dnHit = false
if showPDH and sweptUp(pdh) and not (onePerLevel and uPDH)
upHit := true
uPDH := true
if showPMH and sweptUp(pmh) and not (onePerLevel and uPMH)
upHit := true
uPMH := true
if showONH and sweptUp(onh) and not (onePerLevel and uONH)
upHit := true
uONH := true
if showOC and ocReady and sweptUp(ocH) and not (onePerLevel and uOCH)
upHit := true
uOCH := true
if showOR and orReady and sweptUp(orH) and not (onePerLevel and uORH)
upHit := true
uORH := true
if showPDL and sweptDn(pdl) and not (onePerLevel and uPDL)
dnHit := true
uPDL := true
if showPML and sweptDn(pml) and not (onePerLevel and uPML)
dnHit := true
uPML := true
if showONL and sweptDn(onl) and not (onePerLevel and uONL)
dnHit := true
uONL := true
if showOC and ocReady and sweptDn(ocL) and not (onePerLevel and uOCL)
dnHit := true
uOCL := true
if showOR and orReady and sweptDn(orL) and not (onePerLevel and uORL)
dnHit := true
uORL := true
bool sigShort = useSweep and inWindow and upHit
bool sigLong = useSweep and inWindow and dnHit
// ───────────────────────────── PMH / PML OPENING DRIVE BREAKOUT (module logic, standalone) ─────────────────────────────
bool pbTfOK = pbAnyTf or tfMin == 2 or tfMin == 5
float pbBody = math.abs(close - open)
float pbUpW = high - cTop
float pbDnW = cBot - low
bool pbLive = pbOn and pbTfOK and inRTH and barstate.isconfirmed and not na(pdh) and not na(pdl) and not na(pdc)
bool pbRvolOK = not na(rvol) and rvol > pbRvolMin
bool pbRvolBarOK = not na(rvolBar) and rvolBar > pbRvolMin
var int pbNLong = 0
var int pbNShort = 0
var int pbNMomL = 0
var int pbNMomS = 0
var int pbBrkTmL = na
var int pbBrkTmS = na
if rthFirst
pbNLong := 0
pbNShort := 0
pbNMomL := 0
pbNMomS := 0
pbBrkTmL := na
pbBrkTmS := na
bool pbLongBreak = not na(pmh) and close > pmh and close[1] <= pmh
bool pbShortBreak = not na(pml) and close < pml and close[1] >= pml
if barstate.isconfirmed and inRTH
if pbLongBreak
pbBrkTmL := time_close
if pbShortBreak
pbBrkTmS := time_close
bool pbLateL = pbAnyBar and not pbLongBreak and not na(pmh) and close > pmh
bool pbLateS = pbAnyBar and not pbShortBreak and not na(pml) and close < pml
bool pbInLateL = pbLateMin == 0 or (not na(pbBrkTmL) and time_close - pbBrkTmL <= pbLateMin * 60000)
bool pbInLateS = pbLateMin == 0 or (not na(pbBrkTmS) and time_close - pbBrkTmS <= pbLateMin * 60000)
bool pbLongCtx = pbAllowL and pbLive and close > pdh and close > pdc and (not pbNeedColor or gc) and pbUpW <= pbWickMax * pbBody and mktUp
bool pbShortCtx = pbAllowS and pbLive and close < pdl and close < pdc and (not pbNeedColor or rc) and pbDnW <= pbWickMax * pbBody and mktDn
bool pbLongMain = pbLongCtx and not na(pmh) and close > pmh and pbNLong < pbMaxSig and (pbLongBreak ? pbRvolOK : pbLateL and pbInLateL and (pbRvolBarOK or pbRvolOK))
bool pbShortMain = pbShortCtx and not na(pml) and close < pml and pbNShort < pbMaxSig and (pbShortBreak ? pbRvolOK : pbLateS and pbInLateS and (pbRvolBarOK or pbRvolOK))
bool pbCumUp = not na(rvolCum) and (na(rvolCum[1]) or rvolCum > rvolCum[1])
bool pbMomVol = not na(rvolBar) and rvolBar >= pbMomRvol and pbCumUp
bool pbLongMom = pbLongCtx and pbUseMom and not na(pmh) and close > pmh and pbInLateL and ma1 > ma2 and close > ma2 and pbMomVol and pbNLong == 0 and pbNMomL < 1
bool pbShortMom = pbShortCtx and pbUseMom and not na(pml) and close < pml and pbInLateS and ma1 < ma2 and close < ma2 and pbMomVol and pbNShort == 0 and pbNMomS < 1
bool pbLongSig = pbLongMain or pbLongMom
bool pbShortSig = pbShortMain or pbShortMom
if pbLongSig
if pbLongMain
pbNLong := pbNLong + 1
else
pbNMomL := pbNMomL + 1
if pbShortSig
if pbShortMain
pbNShort := pbNShort + 1
else
pbNMomS := pbNMomS + 1
// stop line at the alert candle's low / high (module: "Stop line at the alert candle's low / high")
var line pbStopLn = na
var float pbTrStop = na
var int pbTrDir = 0
if rthFirst
pbTrDir := 0
if pbLongSig or pbShortSig
pbTrDir := pbLongSig ? 1 : -1
pbTrStop := pbLongSig ? low : high
if pbShowStop
pbStopLn := line.new(bar_index, pbTrStop, bar_index + 1, pbTrStop, color = pbLongSig ? pbLongCol : pbShortCol, width = 1, style = line.style_dashed)
if pbTrDir != 0 and not na(pbStopLn) and inRTH
line.set_x2(pbStopLn, bar_index)
if (pbTrDir > 0 and low < pbTrStop) or (pbTrDir < 0 and high > pbTrStop)
pbTrDir := 0
// ───────────────────────────── WATCH → CONFIRM ─────────────────────────────
bool wVolOK = wRvolMin == 0 or (not na(rvolBar) and rvolBar >= wRvolMin) or (not na(rvolCum) and rvolCum >= wRvolMin) or (na(rvolBar) and na(rvolCum) and rvolSimple >= wRvolMin)
bool afterSkip = inRTH and not na(minsSinceOpen) and minsSinceOpen >= sigSkipMin
bool wScope = inRTH and barstate.isconfirmed and (not wWindowOnly or inWindow)
bool cScope = inRTH and barstate.isconfirmed and (not cWindowOnly or (inWindow and afterSkip))
var int wDir = 0
var int wBar = na
var int wTime = na
var float wVwap = na
var bool wAbove = false
var int cDir = 0
var int cBar = na
var int cTime = na
var string cWhy = ""
var int wCountL = 0
var int wCountS = 0
var int idBarL = na
var int idBarS = na
var float idStopL = na
var float idStopS = na
var string idWhyL = ""
var string idWhyS = ""
var int trDir = 0
var float trEntry = na
var float trStop = na
var float trR = na
var int trBar = na
var bool trHit1 = false
var bool trHit2 = false
var line trStopLn = na
var line trT1Ln = na
var line trT2Ln = na
if rthFirst
wDir := 0
wBar := na
cDir := 0
cBar := na
wCountL := 0
wCountS := 0
idBarL := na
idBarS := na
trDir := 0
bool anySide = wVwapMode == "Any side (tag ABOVE / BELOW VWAP)"
bool aboveV = not na(vwap) and close > vwap
bool belowV = not na(vwap) and close < vwap
bool crossUpNow = not na(sinceXUp) and sinceXUp == 0
bool crossDnNow = not na(sinceXDn) and sinceXDn == 0
bool crossNow = crossUpNow or crossDnNow
bool watchLongRaw = useWatch and wScope and xUpRecent and not na(vwap) and (anySide or aboveV) and (not wNeedPdc or close > pdc) and wVolOK and (not wUseMkt or mktUp)
bool watchShortRaw = useWatch and wScope and xDnRecent and not na(vwap) and (anySide or belowV) and (not wNeedPdc or close < pdc) and wVolOK and (not wUseMkt or mktDn)
bool wLiveNow = wDir != 0 and not na(wBar) and bar_index - wBar <= cWithinBars
bool watchLong = watchLongRaw and not (wDir == 1 and wLiveNow) and (not wOnce or wCountL == 0)
bool watchShort = watchShortRaw and not (wDir == -1 and wLiveNow) and (not wOnce or wCountS == 0)
if watchLong
wDir := 1
wBar := bar_index
wTime := time
wVwap := vwap
wAbove := aboveV
wCountL := wCountL + 1
if watchShort
wDir := -1
wBar := bar_index
wTime := time
wVwap := vwap
wAbove := aboveV
wCountS := wCountS + 1
bool wLive = wDir != 0 and not na(wBar) and bar_index - wBar <= cWithinBars
// identifiers on this bar (each carries its own stop: the candle's extreme)
string whyL = cRc and sigLong ? "reclaim" : cPMH and pbLongSig ? "PMH breakout" : cTwo and confBull ? "two-candle reversal" : cMan and manipBull ? "manipulation candle" : cDj and dojiBreakUp ? "doji-range break" : cEn and engBull ? "engulfing" : ""
string whyS = cRc and sigShort ? "reclaim" : cPMH and pbShortSig ? "PML breakdown" : cTwo and confBear ? "two-candle reversal" : cMan and manipBear ? "manipulation candle" : cDj and dojiBreakDn ? "doji-range break" : cEn and engBear ? "engulfing" : ""
bool idNowL = whyL != "" and cScope
bool idNowS = whyS != "" and cScope
bool idRecentL = not na(idBarL) and bar_index - idBarL <= cWithinBars
bool idRecentS = not na(idBarS) and bar_index - idBarS <= cWithinBars
// CONFIRM: identifier now with a cross that way within N bars before, or a cross now with an identifier within N bars before
bool cfL1 = idNowL and wLive and wDir == 1
bool cfL2 = crossUpNow and idRecentL and cScope and ma1 > ma2
bool cfL3 = rcNoWatch and cRc and sigLong and cScope
bool cfS1 = idNowS and wLive and wDir == -1
bool cfS2 = crossDnNow and idRecentS and cScope and ma1 < ma2
bool cfS3 = rcNoWatch and cRc and sigShort and cScope
bool confirmLong = trDir != 1 and (cfL1 or cfL2 or cfL3)
bool confirmShort = trDir != -1 and (cfS1 or cfS2 or cfS3)
if confirmLong and confirmShort
confirmShort := false
if confirmLong or confirmShort
cDir := confirmLong ? 1 : -1
cBar := bar_index
cTime := time
cWhy := confirmLong ? (cfL1 ? whyL + " + 5/9 cross" : cfL2 ? idWhyL + " then 5/9 cross" : whyL + " (alone)") : (cfS1 ? whyS + " + 5/9 cross" : cfS2 ? idWhyS + " then 5/9 cross" : whyS + " (alone)")
cWhy := cWhy + (close > vwap ? " · above VWAP" : " · below VWAP")
float stp = confirmLong ? (idNowL ? low : idStopL) : (idNowS ? high : idStopS)
trDir := cDir
trEntry := close
trStop := stp
trR := math.abs(close - stp)
trBar := bar_index
trHit1 := false
trHit2 := false
if showTrade and trR > 0
trStopLn := line.new(bar_index, stp, bar_index + 1, stp, color = cShort, width = 1, style = line.style_dashed)
trT1Ln := line.new(bar_index, close + cDir * trR, bar_index + 1, close + cDir * trR, color = cLong, width = 1, style = line.style_dotted)
trT2Ln := line.new(bar_index, close + cDir * 2 * trR, bar_index + 1, close + cDir * 2 * trR, color = cLong, width = 1, style = line.style_dotted)
wDir := 0
if confirmLong
idBarL := na
else
idBarS := na
if idNowL and not confirmLong
idBarL := bar_index
idStopL := low
idWhyL := whyL
if idNowS and not confirmShort
idBarS := bar_index
idStopS := high
idWhyS := whyS
// trade management: stop at the identifier candle's extreme, 1R and 2R marks, re-arm after the stop or 2R
bool trStopped = false
bool trOne = false
bool trTwo = false
bool trExit = false
float trExitR = na
if trDir != 0 and barstate.isconfirmed
if not inRTH
trDir := 0
else if bar_index > trBar
trStopped := trDir > 0 ? low <= trStop : high >= trStop
trOne := not trHit1 and not trStopped and (trDir > 0 ? high >= trEntry + trR : low <= trEntry - trR)
trTwo := not trHit2 and not trStopped and (trDir > 0 ? high >= trEntry + 2 * trR : low <= trEntry - 2 * trR)
if showTrade
if not na(trStopLn)
line.set_x2(trStopLn, bar_index)
if not na(trT1Ln)
line.set_x2(trT1Ln, bar_index)
if not na(trT2Ln)
line.set_x2(trT2Ln, bar_index)
if trStopped
trDir := 0
else
if trOne
trHit1 := true
if trTwo
trHit2 := true
bool maExit = exitMode == "First close through the slow MA" and (trDir > 0 ? close < ma2 : close > ma2)
if maExit
trExit := true
trExitR := trR > 0 ? (trDir > 0 ? close - trEntry : trEntry - close) / trR : na
trDir := 0
else if trTwo and exitMode != "First close through the slow MA"
trDir := 0
bool watchBoxOn = wDir != 0 and not na(wTime) and time - wTime <= clrMin * 60000
bool confBoxOn = cDir != 0 and not na(cTime) and time - cTime <= clrMin * 60000
if wShowBlocked and crossNow and barstate.isconfirmed and inRTH and (not wWindowOnly or inWindow) and not watchLong and not watchShort
string why = (crossUpNow ? "5/9 cross UP" : "5/9 cross DOWN") + " did not become a WATCH:"
why := why + (not useWatch ? "\n· WATCH disabled" : "")
why := why + (not wScope ? "\n· outside the signal window" : "")
why := why + (not anySide and ((crossUpNow and not aboveV) or (not crossUpNow and not belowV)) ? "\n· wrong side of VWAP for this rule" : "")
why := why + (wNeedPdc and ((crossUpNow and not (close > pdc)) or (not crossUpNow and not (close < pdc))) ? "\n· wrong side of yesterday's close" : "")
why := why + (not wVolOK ? "\n· RVOL under " + str.tostring(wRvolMin) + " (bar " + (na(rvolBar) ? "n/a" : str.tostring(rvolBar, "0.00")) + "x, cum " + (na(rvolCum) ? "n/a" : str.tostring(rvolCum, "0.00")) + "x)" : "")
why := why + (wUseMkt and ((crossUpNow and not mktUp) or (not crossUpNow and not mktDn)) ? "\n· SPY/QQQ daily filter against it" : "")
why := why + (wOnce and ((crossUpNow and wCountL > 0) or (not crossUpNow and wCountS > 0)) ? "\n· one WATCH per direction per day already used" : "")
why := why + (((crossUpNow and wDir == 1) or (not crossUpNow and wDir == -1)) and wLiveNow ? "\n· a WATCH this way is already live" : "")
label.new(bar_index, crossUpNow ? low : high, "·", yloc = crossUpNow ? yloc.belowbar : yloc.abovebar, style = label.style_label_center, color = color.new(#9aa4b1, 100), textcolor = color.new(#9aa4b1, 0), size = size.normal, tooltip = why)
// ───────────────────────────── DRAWING ─────────────────────────────
// Level lines: one line object per level per day, shared width / style / ray inputs
lineStyleOf(string st) => st == "dashed" ? line.style_dashed : st == "dotted" ? line.style_dotted : line.style_solid
var line lnPMH = na
var line lnPML = na
var line lnONH = na
var line lnONL = na
var line lnPDH = na
var line lnPDL = na
var line lnPDC = na
mkLvl(line ln, bool on, float v, color c) =>
line r = ln
if rthFirst
if not na(r) and (lvlRay or not lvlHistory)
line.delete(r)
r := na
if on and not na(v)
r := line.new(bar_index, v, bar_index + 1, v, color = c, width = lvlWidth, style = lineStyleOf(lvlStyle), extend = lvlRay ? extend.right : extend.none)
else if not na(r) and inRTH and not lvlRay
line.set_x2(r, bar_index)
r
lnPMH := mkLvl(lnPMH, showPMH, pmh, cPM)
lnPML := mkLvl(lnPML, showPML, pml, cPM)
lnONH := mkLvl(lnONH, showONH, onh, cON)
lnONL := mkLvl(lnONL, showONL, onl, cON)
lnPDH := mkLvl(lnPDH, showPDH, pdh, cPD)
lnPDL := mkLvl(lnPDL, showPDL, pdl, cPD)
lnPDC := mkLvl(lnPDC, showPDC, pdc, color.new(cPD, 40))
plot(showVWAP and inRTH ? vwap : na, "VWAP", color = cVW, linewidth = 1)
pMA1 = plot(showMA1 ? ma1 : na, "Fast MA", color = color.new(cMA1, 30), linewidth = 1)
pMA2 = plot(showMA2 ? ma2 : na, "Slow MA", color = color.new(cMA2, 20), linewidth = 1)
fill(pMA1, pMA2, color = showMAcloud and showMA1 and showMA2 ? (ma1 >= ma2 ? color.new(cBull, 85) : color.new(cBear, 85)) : na, title = "MA cloud")
plot(showGauss ? gf : na, "Gaussian filter", color = gaussUp ? cGaussUp : cGaussDn, linewidth = 2)
var box ocBox = na
var line ocUpAtr = na
var line ocDnAtr = na
var label ocLblH = na
var label ocLblL = na
var box orBox = na
bool ocAlive = not na(minsSinceOpen) and minsSinceOpen < ocMinutes * lifeMult
bool orAlive = not na(minsSinceOpen) and minsSinceOpen < orMin * lifeMult
var box pmBox = na
if showOC and ocCompleteBar and not na(ocH) and not na(ocL) and not na(ocStartBar)
ocBox := box.new(ocStartBar, ocH, bar_index, ocL, bgcolor = cOCfill, border_color = cOC, border_width = 1)
if ocLblOn
ocLblH := label.new(bar_index, ocH, "OCH " + str.tostring(ocH, format.mintick) + "\n", style = label.style_none, textcolor = ocLblCol, size = labelSizeOf(ocLblSize))
ocLblL := label.new(bar_index, ocL, "\nOCL " + str.tostring(ocL, format.mintick), style = label.style_none, textcolor = ocLblCol, size = labelSizeOf(ocLblSize))
if showOCatr and not na(ocAtr)
ocUpAtr := line.new(ocStartBar, ocH + ocAtr * ocAtrMult, bar_index, ocH + ocAtr * ocAtrMult, color = cOCatr, style = line.style_dashed)
ocDnAtr := line.new(ocStartBar, ocL - ocAtr * ocAtrMult, bar_index, ocL - ocAtr * ocAtrMult, color = cOCatr, style = line.style_dashed)
if showOC and ocDone and inRTH and not na(ocBox)
if ocAlive
box.set_right(ocBox, bar_index)
if not na(ocUpAtr)
line.set_x2(ocUpAtr, bar_index)
if not na(ocDnAtr)
line.set_x2(ocDnAtr, bar_index)
if not na(ocLblH)
label.set_x(ocLblH, bar_index)
if not na(ocLblL)
label.set_x(ocLblL, bar_index)
else if lifeRemove
box.delete(ocBox)
ocBox := na
if not na(ocUpAtr)
line.delete(ocUpAtr)
ocUpAtr := na
if not na(ocDnAtr)
line.delete(ocDnAtr)
ocDnAtr := na
if not na(ocLblH)
label.delete(ocLblH)
ocLblH := na
if not na(ocLblL)
label.delete(ocLblL)
ocLblL := na
if showOR and orCompleteBar and not na(orH) and not na(orL) and not na(orStartBar)
orBox := box.new(orStartBar, orH, bar_index, orL, bgcolor = cORfill, border_color = cOR, border_width = 1)
if showOR and orDone and inRTH and not na(orBox)
if orAlive
box.set_right(orBox, bar_index)
else if lifeRemove
box.delete(orBox)
orBox := na
if showPMbox and rthFirst and not na(pmh) and not na(pml) and not na(pmStartBar)
pmBox := box.new(pmStartBar, pmh, bar_index, pml, bgcolor = cPMbox, border_color = color.new(cPMbox, 100), border_width = 0)
if showPMbox and inRTH and not na(pmBox)
box.set_right(pmBox, bar_index)
// Right-edge level labels: levels that sit within lblMerge × ATR of each other share one label (no more piling up)
var label[] lvlLabels = array.new_label()
var float[] lvV = array.new_float()
var string[] lvT = array.new_string()
var color[] lvC = array.new_color()
addLvl(bool on, float v, string t, color c) =>
if on and not na(v)
array.push(lvV, v)
array.push(lvT, t)
array.push(lvC, c)
if barstate.islast
if array.size(lvlLabels) > 0
for i = 0 to array.size(lvlLabels) - 1
label.delete(array.get(lvlLabels, i))
array.clear(lvlLabels)
if showLvlLabels
array.clear(lvV)
array.clear(lvT)
array.clear(lvC)
float[] lv = lvV
string[] lt = lvT
color[] lc = lvC
addLvl(showPMH, pmh, "PMH", cPM)
addLvl(showPML, pml, "PML", cPM)
addLvl(showONH, onh, "ONH", cON)
addLvl(showONL, onl, "ONL", cON)
addLvl(showPDH, pdh, "PDH", cPD)
addLvl(showPDL, pdl, "PDL", cPD)
addLvl(showPDC, pdc, "PDC", color.new(cPD, 30))
addLvl(showVWAP and inRTH, vwap, "VWAP", cVW)
int n = array.size(lv)
if n > 0
int[] order = array.new_int()
for i = 0 to n - 1
array.push(order, i)
// insertion sort by price, highest first
if n > 1
for i = 1 to n - 1
int key = array.get(order, i)
int j = i - 1
bool go = true
while go
if j < 0
go := false
else if array.get(lv, array.get(order, j)) < array.get(lv, key)
array.set(order, j + 1, array.get(order, j))
j := j - 1
else
go := false
array.set(order, j + 1, key)
float tol = lblMerge * atr
int k = 0
while k < n
int idx = array.get(order, k)
float v0 = array.get(lv, idx)
string txt = array.get(lt, idx) + (lblShowPrice ? " " + str.tostring(v0, format.mintick) : "")
color c0 = array.get(lc, idx)
float vSum = v0
int cnt = 1
int m = k + 1
bool more = true
while more
if m >= n
more := false
else if v0 - array.get(lv, array.get(order, m)) <= tol
int idm = array.get(order, m)
txt := txt + "\n" + array.get(lt, idm) + (lblShowPrice ? " " + str.tostring(array.get(lv, idm), format.mintick) : "")
vSum := vSum + array.get(lv, idm)
cnt := cnt + 1
m := m + 1
else
more := false
float yv = vSum / cnt
string lst = lblStyle == "label_right" ? label.style_label_right : lblStyle == "label_center" ? label.style_label_center : lblStyle == "label_up" ? label.style_label_up : lblStyle == "label_down" ? label.style_label_down : lblStyle == "none" ? label.style_none : label.style_label_left
label lb = label.new(bar_index + lblOffset, yv, txt, style = lst, color = lblOpaque ? c0 : color.new(c0, 80), textcolor = lblStyle == "none" ? c0 : lblOpaque ? lblTextCol : c0, size = labelSizeOf(lblSize), textalign = text.align_left)
array.push(lvlLabels, lb)
k := m
// Candles and markers
barcolor(manipColor and manipBull ? cManipBull : manipColor and manipBear ? cManipBear : na, title = "Manipulation candle")
barcolor(twoSetupAny ? cYellow : na, title = "Setup candle (this bar)")
barcolor(twoSetupAny ? cYellow : na, offset = -1, title = "Setup candle (prior bar)")
barcolor(useDoji and smallBody and inRTH and not twoSetupAny and not twoSetupAny[1] ? cDojiLine : na, title = "Liquidation/doji")
plotshape(confBull, "Reversal confirmed bull", shape.triangleup, location.belowbar, cBull, size = size.small)
plotshape(confBear, "Reversal confirmed bear", shape.triangledown, location.abovebar, cBear, size = size.small)
plotshape(engBull, "Engulfing bull on volume", shape.circle, location.belowbar, color.new(cBull, 30), size = size.tiny)
plotshape(engBear, "Engulfing bear on volume", shape.circle, location.abovebar, color.new(cBear, 30), size = size.tiny)
plotshape(showSweepMarks and sigShort, "Pop & drop", shape.xcross, location.abovebar, cSwpDn, size = size.tiny)
plotshape(showSweepMarks and sigLong, "Drop & pop", shape.xcross, location.belowbar, cSwpUp, size = size.tiny)
if sigLong and not confirmLong
label.new(bar_index, low, "RECLAIM", yloc = yloc.belowbar, style = label.style_label_up, color = color.new(cSwpUp, 20), textcolor = color.black, size = size.tiny, tooltip = "Swept a level by at least " + str.tostring(sweepDepth) + " ATR and closed back above it")
if sigShort and not confirmShort
label.new(bar_index, high, "RECLAIM", yloc = yloc.abovebar, style = label.style_label_down, color = color.new(cSwpDn, 20), textcolor = color.white, size = size.tiny, tooltip = "Swept a level by at least " + str.tostring(sweepDepth) + " ATR and closed back below it")
if tfGuard and barstate.islast and not tfOK
label.new(bar_index, high, "PHX OpenRev: built for 2, 3, 5, 15 or 30-minute charts", style = label.style_label_left, color = color.new(#f2c14e, 0), textcolor = color.black, size = size.small)
// PMH / PML breakout tags on the candle (module look: LONG / SHORT, momentum marked)
string tfTxt = str.tostring(timeframe.multiplier) + "M"
if pbLongSig
string tip = syminfo.ticker + " ▲ LONG" + (pbLongMain ? "" : " · momentum") + "\n" + str.format_time(time_close, "HH:mm", tz) + " - " + tfTxt + " candle closed above PMH " + str.tostring(pmh, format.mintick) + "\nRVOL " + (na(rvol) ? "n/a" : str.tostring(rvol, "0.0") + "x") + (pbLongMain ? "" : " (bar " + str.tostring(rvolBar, "0.0") + "x, building)") + "\nStop " + str.tostring(low, format.mintick) + " - risk " + str.tostring(close - low, format.mintick) + " (" + str.tostring((close - low) / close * 100, "0.0") + "%)"
label.new(bar_index, low, pbLongMain ? "LONG" : "LONG MOM", yloc = yloc.belowbar, style = label.style_label_up, color = pbLongCol, textcolor = color.white, size = size.tiny, tooltip = tip)
if pbShortSig
string tip = syminfo.ticker + " ▼ SHORT" + (pbShortMain ? "" : " · momentum") + "\n" + str.format_time(time_close, "HH:mm", tz) + " - " + tfTxt + " candle closed below PML " + str.tostring(pml, format.mintick) + "\nRVOL " + (na(rvol) ? "n/a" : str.tostring(rvol, "0.0") + "x") + (pbShortMain ? "" : " (bar " + str.tostring(rvolBar, "0.0") + "x, building)") + "\nStop " + str.tostring(high, format.mintick) + " - risk " + str.tostring(high - close, format.mintick) + " (" + str.tostring((high - close) / close * 100, "0.0") + "%)"
label.new(bar_index, high, pbShortMain ? "SHORT" : "SHORT MOM", yloc = yloc.abovebar, style = label.style_label_down, color = pbShortCol, textcolor = color.white, size = size.tiny, tooltip = tip)
// WATCH / CONFIRM tags on the candles
if markWatch and (watchLong or watchShort)
label.new(bar_index, watchLong ? low : high, "WATCH", yloc = watchLong ? yloc.belowbar : yloc.abovebar, style = watchLong ? label.style_label_up : label.style_label_down, color = cWatch, textcolor = color.black, size = size.tiny)
if markWatch and (confirmLong or confirmShort)
string ctip = cWhy + "\nentry " + str.tostring(trEntry, format.mintick) + " · stop " + str.tostring(trStop, format.mintick) + " · R " + str.tostring(trR, format.mintick) + "\n1R " + str.tostring(trEntry + cDir * trR, format.mintick) + " · 2R " + str.tostring(trEntry + cDir * 2 * trR, format.mintick)
label.new(bar_index, confirmLong ? low : high, "CONFIRMED", yloc = confirmLong ? yloc.belowbar : yloc.abovebar, style = confirmLong ? label.style_label_up : label.style_label_down, color = confirmLong ? cLong : cShort, textcolor = color.white, size = size.tiny, tooltip = ctip)
if showTrade and trStopped
label.new(bar_index, trStop, "STOPPED", style = label.style_label_center, color = color.new(cShort, 20), textcolor = color.white, size = size.tiny)
if showTrade and trOne
label.new(bar_index, trEntry + (cDir > 0 ? trR : -trR), "1R", style = label.style_label_center, color = color.new(cLong, 20), textcolor = color.black, size = size.tiny)
if showTrade and trExit
label.new(bar_index, close, "EXIT " + (na(trExitR) ? "" : (trExitR >= 0 ? "+" : "") + str.tostring(trExitR, "0.0") + "R"), style = label.style_label_center, color = color.new(#9aa4b1, 0), textcolor = color.white, size = size.tiny, tooltip = "First close through the slow MA (the PMH module runner rule)")
if showTrade and trTwo
label.new(bar_index, trEntry + (cDir > 0 ? 2 * trR : -2 * trR), "2R", style = label.style_label_center, color = color.new(cLong, 0), textcolor = color.black, size = size.tiny)
// WATCH / CONFIRM boxes (top centre by default): watch in yellow, confirmed in green or red; each clears clrMin minutes after its candle
posOf(string p) =>
p == "Top left" ? position.top_left : p == "Top center" ? position.top_center : p == "Top right" ? position.top_right : p == "Middle left" ? position.middle_left : p == "Middle center" ? position.middle_center : p == "Middle right" ? position.middle_right : p == "Bottom left" ? position.bottom_left : p == "Bottom center" ? position.bottom_center : position.bottom_right
var table wBox = table.new(posOf(tagPos), 1, 2, border_width = 0)
if barstate.islast
if watchBoxOn
string wTxt = (wDir > 0 ? "WATCH LONG" : "WATCH SHORT") + " · " + str.tostring(ma1Len) + "/" + str.tostring(ma2Len) + " cross " + (wAbove ? "ABOVE VWAP " : "BELOW VWAP ") + str.tostring(wVwap, format.mintick) + " · " + str.format_time(wTime, "HH:mm", tz)
table.cell(wBox, 0, 0, wTxt, text_color = color.black, bgcolor = color.new(cWatch, 10), text_size = labelSizeOf(tagSize))
else
table.clear(wBox, 0, 0)
if confBoxOn
string cTxt = (cDir > 0 ? "CONFIRMED LONG" : "CONFIRMED SHORT") + " · " + cWhy + " · " + str.format_time(cTime, "HH:mm", tz)
table.cell(wBox, 0, 1, cTxt, text_color = color.white, bgcolor = color.new(cDir > 0 ? cLong : cShort, 10), text_size = labelSizeOf(tagSize))
else
table.clear(wBox, 0, 1)
// ───────────────────────────── SELF-GRADING ─────────────────────────────
var int NDET = 9
var string[] detNames = array.from("PMH break long", "PML break short", "CONFIRMED long", "CONFIRMED short", "Reclaim short (pop&drop)", "Reclaim long (drop&pop)", "Manip bull", "Manip bear", "BASELINE every bar")
var int[] detHits = array.new_int(NDET, 0)
var int[] detTotal = array.new_int(NDET, 0)
var int[] detR1 = array.new_int(NDET, 0)
var float[] oBar = array.new_float()
var float[] oDet = array.new_float()
var float[] oDir = array.new_float()
var float[] oEnt = array.new_float()
var float[] oAtr = array.new_float()
var float[] oStop = array.new_float()
var float[] oRace = array.new_float()
var float[] oRg = array.new_float()
addSig(int det, int dir, float stp) =>
array.push(oBar, bar_index)
array.push(oDet, det)
array.push(oDir, dir)
array.push(oEnt, close)
array.push(oAtr, atr)
array.push(oStop, stp)
array.push(oRace, -1)
array.push(oRg, -1)
if array.size(oBar) > 0
for i = array.size(oBar) - 1 to 0
int b0 = int(array.get(oBar, i))
if bar_index > b0
float d = array.get(oDir, i)
float e = array.get(oEnt, i)
float a = array.get(oAtr, i)
float sp = array.get(oStop, i)
float rr = math.abs(e - sp)
float fav = d > 0 ? high - e : e - low
float adv = d > 0 ? e - low : high - e
bool expired = bar_index - b0 >= horizon
if array.get(oRace, i) < 0
if adv >= stopATR * a
array.set(oRace, i, 0)
else if fav >= tgtATR * a
array.set(oRace, i, 1)
else if expired
array.set(oRace, i, 0)
if array.get(oRg, i) < 0
bool stopHit = d > 0 ? low <= sp : high >= sp
if rr <= 0 or stopHit
array.set(oRg, i, 0)
else if fav >= rr
array.set(oRg, i, 1)
else if expired
array.set(oRg, i, 0)
if array.get(oRace, i) >= 0 and array.get(oRg, i) >= 0
int det = int(array.get(oDet, i))
array.set(detTotal, det, array.get(detTotal, det) + 1)
array.set(detHits, det, array.get(detHits, det) + int(array.get(oRace, i)))
array.set(detR1, det, array.get(detR1, det) + int(array.get(oRg, i)))
array.remove(oBar, i)
array.remove(oDet, i)
array.remove(oDir, i)
array.remove(oEnt, i)
array.remove(oAtr, i)
array.remove(oStop, i)
array.remove(oRace, i)
array.remove(oRg, i)
if barstate.isconfirmed
if pbLongSig
addSig(0, 1, low)
if pbShortSig
addSig(1, -1, high)
if confirmLong
addSig(2, 1, trStop)
if confirmShort
addSig(3, -1, trStop)
if sigShort
addSig(4, -1, high)
if sigLong
addSig(5, 1, low)
if manipBull
addSig(6, 1, low)
if manipBear
addSig(7, -1, high)
if dashBaseline and inRTH
addSig(8, 1, low)
addSig(8, -1, high)
var table dash = table.new(posOf(dashLoc), 4, NDET + 3, bgcolor = cDashBg, border_color = color.new(#373a46, 0), border_width = 1)
var bool dashMerged = false
if showDash and barstate.islast
string ts = labelSizeOf(dashSize)
table.cell(dash, 0, 0, "PHX OpenRev · race = +" + str.tostring(tgtATR) + " ATR before −" + str.tostring(stopATR) + " · 1R = one R before the stop · " + str.tostring(horizon) + " bars", text_color = color.white, text_size = ts)
if not dashMerged
table.merge_cells(dash, 0, 0, 3, 0)
if dashStatus
table.cell(dash, 0, 1, "", text_size = ts)
table.merge_cells(dash, 0, 1, 3, 1)
dashMerged := true
int tB = array.get(detTotal, NDET - 1)
float baseRate = tB > 0 ? array.get(detHits, NDET - 1) * 100.0 / tB : na
float baseR1 = tB > 0 ? array.get(detR1, NDET - 1) * 100.0 / tB : na
string stat = "now: " + (inRTH ? "RTH" : inPM ? "pre-market" : "closed") + " · RVOL " + (na(rvolCum) ? (na(rvolBar) ? "n/a" : str.tostring(rvolBar, "0.0") + "x bar") : str.tostring(rvolCum, "0.0") + "x") + " · " + (na(vwap) ? "VWAP n/a" : close > vwap ? "ABOVE VWAP" : "BELOW VWAP") + " · " + (not pbUseMkt ? "mkt filter off" : mktUp ? "SPY+QQQ up" : mktDn ? "SPY+QQQ down" : "SPY/QQQ mixed") + " · " + str.tostring(ma1Len) + "/" + str.tostring(ma2Len) + (ma1 > ma2 ? " up" : " down") + (trDir != 0 ? " · trade " + (trDir > 0 ? "LONG" : "SHORT") + " stop " + str.tostring(trStop, format.mintick) : "")
int rowOff = dashStatus ? 1 : 0
if dashStatus
table.cell(dash, 0, 1, stat, text_color = color.white, text_size = ts, text_halign = text.align_left)
table.cell(dash, 0, 1 + rowOff, "Detector", text_color = color.white, text_size = ts)
table.cell(dash, 1, 1 + rowOff, "race", text_color = color.white, text_size = ts)
table.cell(dash, 2, 1 + rowOff, "1R", text_color = color.white, text_size = ts)
table.cell(dash, 3, 1 + rowOff, "N", text_color = color.white, text_size = ts)
for i = 0 to NDET - 1
int t = array.get(detTotal, i)
int h = array.get(detHits, i)
int h1 = array.get(detR1, i)
float rate = t > 0 ? h * 100.0 / t : na
float rate1 = t > 0 ? h1 * 100.0 / t : na
string pct = t > 0 ? str.tostring(math.round(rate)) + "%" : "–"
string pct1 = t > 0 ? str.tostring(math.round(rate1)) + "%" : "–"
bool isBase = i == NDET - 1
color cc = t < 30 ? color.new(#f2c14e, 0) : isBase or na(baseRate) ? color.white : rate > baseRate + 5 ? cBull : rate < baseRate - 5 ? cBear : color.white
color cc1 = t < 30 ? color.new(#f2c14e, 0) : isBase or na(baseR1) ? color.white : rate1 > baseR1 + 5 ? cBull : rate1 < baseR1 - 5 ? cBear : color.white
if not isBase or dashBaseline
table.cell(dash, 0, i + 2 + rowOff, array.get(detNames, i), text_color = color.white, text_size = ts, text_halign = text.align_left)
table.cell(dash, 1, i + 2 + rowOff, pct, text_color = cc, text_size = ts, tooltip = t < 30 ? "PROVISIONAL: under N = 30 this is opinion, weight zero" : isBase ? "The same race started on every bar, long and short: the coin-toss score on this chart" : "green: more than 5 points above BASELINE · red: more than 5 below")
table.cell(dash, 2, i + 2 + rowOff, pct1, text_color = cc1, text_size = ts, tooltip = "1R reached before the stop (the signal candle's extreme) within the horizon")
table.cell(dash, 3, i + 2 + rowOff, str.tostring(t), text_color = cc, text_size = ts)
// ───────────────────────────── ALERTS ─────────────────────────────
alertcondition(watchLong or watchShort, "WATCH (fast/slow cross on the VWAP side)", "PHX OpenRev: WATCH on {{ticker}} {{interval}}")
alertcondition(confirmLong, "CONFIRMED LONG", "PHX OpenRev: CONFIRMED LONG on {{ticker}} {{interval}} at {{close}}")
alertcondition(confirmShort, "CONFIRMED SHORT", "PHX OpenRev: CONFIRMED SHORT on {{ticker}} {{interval}} at {{close}}")
alertcondition(trStopped, "Trade STOPPED", "PHX OpenRev: trade stopped on {{ticker}} {{interval}}")
alertcondition(trOne or trTwo, "Trade reached 1R / 2R", "PHX OpenRev: trade target reached on {{ticker}} {{interval}}")
alertcondition(trExit, "Trade EXIT (close through the slow MA)", "PHX OpenRev: exit on {{ticker}} {{interval}}")
alertcondition(pbLongSig, "PMH breakout - LONG", "PHX OpenRev: long alert above the pre-market high on {{ticker}} {{interval}}")
alertcondition(pbShortSig, "PML breakdown - SHORT", "PHX OpenRev: short alert below the pre-market low on {{ticker}} {{interval}}")
alertcondition(sigShort, "Pop & drop", "PHX OpenRev: POP & DROP on {{ticker}} {{interval}} at {{close}}")
alertcondition(sigLong, "Drop & pop", "PHX OpenRev: DROP & POP on {{ticker}} {{interval}} at {{close}}")
alertcondition(twoSetupAny, "Two reversal candles (yellow)", "Two consecutive reversal candles on {{ticker}} {{interval}}")
alertcondition(confBull or confBear, "Reversal confirmed (triangle)", "Reversal confirmed on {{ticker}} {{interval}} at {{close}}")
alertcondition(manipBull or manipBear, "Manipulation candle", "Manipulation candle on {{ticker}} {{interval}}")
alertcondition(ocDone and inRTH and close > ocH and close[1] <= ocH, "Close above opening candle high", "Close above opening candle high on {{ticker}} {{interval}}")
alertcondition(ocDone and inRTH and close < ocL and close[1] >= ocL, "Close below opening candle low", "Close below opening candle low on {{ticker}} {{interval}}")
// Secondary alerts as alert() calls (set a TradingView alert on "Any alert() function call")
string tkr = syminfo.ticker + " " + timeframe.period
if barstate.isconfirmed
if dojiBreakUp
alert("PHX OpenRev: close above liquidation/doji high on " + tkr, alert.freq_once_per_bar_close)
if dojiBreakDn
alert("PHX OpenRev: close below liquidation/doji low on " + tkr, alert.freq_once_per_bar_close)
if engBull or engBear
alert("PHX OpenRev: engulfing on volume on " + tkr, alert.freq_once_per_bar_close)
if pbTrDir == 0 and pbTrDir[1] != 0
alert("PHX OpenRev: PMH / PML trade stop hit on " + tkr, alert.freq_once_per_bar_close)