本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("ORB Ultimate+", shorttitle = "ORB Ultimate+", overlay = true, max_lines_count = 500, max_labels_count = 500, max_boxes_count = 500, max_bars_back = 1000)
const string TZ = "America/New_York"
const string G_HL = "HTF Liquidity"
const string G_SL = "Session Liquidity"
const string G_SMT = "SMT Divergence"
const string G_RB = "Rejection Blocks"
const string G_OR = "Opening Range"
const string G_FV = "HTF Fair Value Gaps"
const string G_BI = "HTF Bias"
const string G_AL = "Alerts"
const int CW_WIN = 10
const int GRADE_MS = 60 * 60 * 1000
const int SMT_SPAN = 120
bool iHlOn = input.bool(true, "Enable", group = G_HL)
color iHlBsl = input.color(#787B86, "BSL", inline = "hc", group = G_HL)
color iHlSsl = input.color(#787B86, "SSL", inline = "hc", group = G_HL)
string iHlTf = input.timeframe("60", "Timeframe", group = G_HL)
string iHlStr = input.string("Normal", "Strictness", options = ["Sensitive", "Normal", "Strict"], group = G_HL)
string iHlSt = input.string("Dotted", "Line style", options = ["Solid", "Dashed", "Dotted"], inline = "hs", group = G_HL)
int iHlW = input.int(1, "Width", minval = 1, maxval = 4, inline = "hs", group = G_HL)
bool iHlLb = input.bool(true, "Labels", inline = "hl", group = G_HL)
string iHlLbSz = input.string("Tiny", "", options = ["Tiny", "Small", "Normal", "Large", "Huge"], inline = "hl", group = G_HL)
string iSlSt = input.string("Dotted", "Line style", options = ["Solid", "Dashed", "Dotted"], group = G_SL)
string iSlLbSz = input.string("Tiny", "Label size", options = ["Tiny", "Small", "Normal", "Large", "Huge"], group = G_SL)
bool iSlKeep = input.bool(false, "Preserve After Mitigation", group = G_SL)
bool iAmOn = input.bool(true, "NY AM", inline = "am", group = G_SL)
color iAmC = input.color(#787B86, "", inline = "am", group = G_SL)
string iAmS = input.session("0930-1100", "", inline = "am", group = G_SL)
bool iPmOn = input.bool(true, "NY PM", inline = "pm", group = G_SL)
color iPmC = input.color(#787B86, "", inline = "pm", group = G_SL)
string iPmS = input.session("1330-1600", "", inline = "pm", group = G_SL)
bool iAsOn = input.bool(true, "Asia", inline = "as", group = G_SL)
color iAsC = input.color(#787B86, "", inline = "as", group = G_SL)
string iAsS = input.session("2000-0000", "", inline = "as", group = G_SL)
bool iLoOn = input.bool(true, "London", inline = "lo", group = G_SL)
color iLoC = input.color(#787B86, "", inline = "lo", group = G_SL)
string iLoS = input.session("0200-0500", "", inline = "lo", group = G_SL)
bool iPdOn = input.bool(true, "PDH / PDL", inline = "pd", group = G_SL)
color iPdC = input.color(#787B86, "", inline = "pd", group = G_SL)
bool iPwOn = input.bool(true, "PWH / PWL", inline = "pw", group = G_SL)
color iPwC = input.color(#787B86, "", inline = "pw", group = G_SL)
bool iDtOn = input.bool(true, "DATA H / L", inline = "dt", group = G_SL)
color iDtC = input.color(#787B86, "", inline = "dt", group = G_SL)
float iDtMin = input.float(10.0, "Min wick (pts)", minval = 0, step = 0.25, inline = "dt", group = G_SL)
string iSmMode = input.string("Automatic", "Correlated asset", options = ["Automatic", "Manual"], inline = "sm", group = G_SMT)
string iSmSym = input.symbol("CME_MINI:ES1!", "", inline = "sm", group = G_SMT)
string iSmSens = input.string("Normal", "Sensitivity", options = ["Sensitive", "Normal", "Strict"], group = G_SMT)
int iSmMax = input.int(5, "Max visible", minval = 1, maxval = 50, group = G_SMT)
bool iSmRt = input.bool(false, "Real-time SMTs", group = G_SMT)
bool iSmGap = input.bool(false, "Gap SMTs", group = G_SMT)
bool iSmSeq = input.bool(false, "Sequential SMTs", group = G_SMT)
color iSmBuC = input.color(#5D606B, "Bullish", inline = "sb", group = G_SMT)
int iSmBuW = input.int(1, "", minval = 1, maxval = 4, inline = "sb", group = G_SMT)
string iSmBuSt = input.string("Solid", "", options = ["Solid", "Dashed", "Dotted"], inline = "sb", group = G_SMT)
color iSmBeC = input.color(#5D606B, "Bearish", inline = "se", group = G_SMT)
int iSmBeW = input.int(1, "", minval = 1, maxval = 4, inline = "se", group = G_SMT)
string iSmBeSt = input.string("Solid", "", options = ["Solid", "Dashed", "Dotted"], inline = "se", group = G_SMT)
bool iSmLb = input.bool(true, "Labels", inline = "sl", group = G_SMT)
color iSmLbC = input.color(#5D606B, "", inline = "sl", group = G_SMT)
string iSmLbSz = input.string("Tiny", "", options = ["Tiny", "Small", "Normal", "Large", "Huge"], inline = "sl", group = G_SMT)
bool iSmSymT = input.bool(true, "Show symbol", inline = "sl", group = G_SMT)
bool iRbOn = input.bool(true, "Enable", group = G_RB)
color iRbBu = input.color(color.new(#089981, 82), "Bullish", inline = "rc", group = G_RB)
color iRbBe = input.color(color.new(#F23645, 82), "Bearish", inline = "rc", group = G_RB)
bool iRbCe = input.bool(true, "50% (CE) line", inline = "rce", group = G_RB)
string iRbCeSt = input.string("Dashed", "", options = ["Solid", "Dashed", "Dotted"], inline = "rce", group = G_RB)
bool iRbHtf = input.bool(false, "Project from HTF", inline = "rh", group = G_RB)
string iRbTf = input.timeframe("15", "", inline = "rh", group = G_RB)
bool iRbTfLb = input.bool(true, "HTF box timeframe label", group = G_RB)
bool iOrOn = input.bool(true, "Enable", group = G_OR)
string iOrLen = input.string("15m", "Range", options = ["15m", "5m"], group = G_OR)
bool iOrAs = input.bool(false, "Asia ORB", inline = "ox", group = G_OR)
bool iOrLo = input.bool(false, "London ORB", inline = "ox", group = G_OR)
color iOrFill = input.color(color.new(#2962FF, 88), "Fill", group = G_OR)
color iOrHc = input.color(#089981, "High", inline = "oc", group = G_OR)
color iOrMc = input.color(#787B86, "50%", inline = "oc", group = G_OR)
color iOrLc = input.color(#F23645, "Low", inline = "oc", group = G_OR)
color iOrLnC = input.color(#434651, "Line", inline = "ol", group = G_OR)
string iOrSt = input.string("Solid", "", options = ["Solid", "Dashed", "Dotted"], inline = "ol", group = G_OR)
int iOrW = input.int(1, "", minval = 1, maxval = 4, inline = "ol", group = G_OR)
bool iOrLb = input.bool(true, "Labels", inline = "olb", group = G_OR)
string iOrLbSz = input.string("Tiny", "", options = ["Tiny", "Small", "Normal", "Large", "Huge"], inline = "olb", group = G_OR)
bool iOrPx = input.bool(false, "Show prices", inline = "olb", group = G_OR)
bool iOrNoon = input.bool(true, "Remove ORB after 12:00 ET", group = G_OR)
bool iFvOn = input.bool(true, "Enable", group = G_FV)
bool iFv1On = input.bool(true, "", inline = "f1", group = G_FV)
string iFv1 = input.timeframe("15", "", inline = "f1", group = G_FV)
bool iFv2On = input.bool(true, "", inline = "f1", group = G_FV)
string iFv2 = input.timeframe("60", "", inline = "f1", group = G_FV)
bool iFv3On = input.bool(true, "", inline = "f1", group = G_FV)
string iFv3 = input.timeframe("240", "", inline = "f1", group = G_FV)
color iFvBu = input.color(color.new(#089981, 75), "Bullish", inline = "fc", group = G_FV)
color iFvBe = input.color(color.new(#F23645, 75), "Bearish", inline = "fc", group = G_FV)
bool iFvBrd = input.bool(false, "Border", group = G_FV)
bool iFvCe = input.bool(false, "50% (CE) line", inline = "fce", group = G_FV)
string iFvCeSt = input.string("Dashed", "", options = ["Solid", "Dashed", "Dotted"], inline = "fce", group = G_FV)
color iFvLbC = input.color(#434651, "Label", inline = "fl", group = G_FV)
string iFvLbSz = input.string("Tiny", "", options = ["Tiny", "Small", "Normal", "Large", "Huge"], inline = "fl", group = G_FV)
float iFvMin = input.float(0.0, "Min gap size (pts)", minval = 0, step = 0.25, group = G_FV)
bool iB1On = input.bool(true, "", inline = "b1", group = G_BI)
string iB1 = input.timeframe("W", "", inline = "b1", group = G_BI)
bool iB2On = input.bool(true, "", inline = "b1", group = G_BI)
string iB2 = input.timeframe("D", "", inline = "b1", group = G_BI)
bool iB3On = input.bool(true, "", inline = "b2", group = G_BI)
string iB3 = input.timeframe("240", "", inline = "b2", group = G_BI)
bool iB4On = input.bool(true, "", inline = "b2", group = G_BI)
string iB4 = input.timeframe("60", "", inline = "b2", group = G_BI)
bool iBiTbl = input.bool(true, "Bias table", group = G_BI)
bool iFkOn = input.bool(true, "ORB Fakeout", inline = "fk", group = G_BI)
color iFkC = input.color(#787B86, "", inline = "fk", group = G_BI)
bool iCwOn = input.bool(true, "CW Trigger", inline = "cw", group = G_BI)
color iCwBu = input.color(#089981, "", inline = "cw", group = G_BI)
color iCwBe = input.color(#F23645, "", inline = "cw", group = G_BI)
bool iLim = input.bool(true, "Limit lines (SL / BE / TP)", group = G_BI)
color iSlC = input.color(#F23645, "SL", inline = "lc", group = G_BI)
color iBeC = input.color(#FF9800, "BE", inline = "lc", group = G_BI)
color iTpC = input.color(#089981, "TP", inline = "lc", group = G_BI)
bool iMinRR = input.bool(true, "Min RR for TP levels", group = G_BI)
bool iChk = input.bool(true, "Setup Checklist", group = G_BI)
bool iAlSw = input.bool(true, "Session liquidity sweep", group = G_AL)
bool iAlCw = input.bool(true, "CW entry", group = G_AL)
bool iAw1On = input.bool(true, "Window 1", inline = "a1", group = G_AL)
string iAw1 = input.session("0930-1200", "", inline = "a1", group = G_AL)
bool iAw2On = input.bool(false, "Window 2", inline = "a2", group = G_AL)
string iAw2 = input.session("1330-1600", "", inline = "a2", group = G_AL)
bool iAw3On = input.bool(false, "Window 3", inline = "a3", group = G_AL)
string iAw3 = input.session("0200-0500", "", inline = "a3", group = G_AL)
f_st(string s) => s == "Dashed" ? line.style_dashed : s == "Dotted" ? line.style_dotted : line.style_solid
f_sz(string s) => s == "Small" ? size.small : s == "Normal" ? size.normal : s == "Large" ? size.large : s == "Huge" ? size.huge : size.tiny
f_in(string s) => not na(time(timeframe.period, s + ":1234567", TZ))
f_hm(string s, int o) => int(str.tonumber(str.substring(s, o, o + 2))) * 60 + int(str.tonumber(str.substring(s, o + 2, o + 4)))
f_px(float x) => str.tostring(x, format.mintick)
f_tfLong(string tf) =>
int s = timeframe.in_seconds(tf)
s >= 2419200 ? "Monthly" : s >= 604800 ? "Weekly" : s >= 86400 ? "Daily" : s >= 3600 ? str.tostring(s / 3600) + "H" : str.tostring(s / 60) + "m"
f_tfShort(string tf) =>
int s = timeframe.in_seconds(tf)
s >= 2419200 ? "MN" : s >= 604800 ? "W1" : s >= 86400 ? "D1" : s >= 3600 ? "H" + str.tostring(s / 3600) : "M" + str.tostring(s / 60)
f_grade(int n) => n >= 4 ? "A+" : n == 3 ? "A" : n == 2 ? "B" : n == 1 ? "C" : "D"
int tfSec = timeframe.in_seconds()
int tfMs = tfSec * 1000
int rx = time + 3 * tfMs
var array<int> tsSmt = array.from(0, 0)
var array<int> tsRb = array.from(0, 0)
var array<int> tsFvg = array.from(0, 0)
var array<int> tsSwp = array.from(0, 0)
f_recent(array<int> a, int d) =>
int t = a.get(d == 1 ? 0 : 1)
t > 0 and t >= time - GRADE_MS
f_bias() =>
var int st = 0
var float sh = na
var float sl = na
float ph = ta.pivothigh(high, 2, 2)
float pl = ta.pivotlow(low, 2, 2)
if not na(ph)
sh := ph
if not na(pl)
sl := pl
if not na(sh) and close > sh
st := 1
sh := na
if not na(sl) and close < sl
st := -1
sl := na
st[1]
int bs1 = request.security(syminfo.tickerid, iB1, f_bias(), lookahead = barmerge.lookahead_on)
int bs2 = request.security(syminfo.tickerid, iB2, f_bias(), lookahead = barmerge.lookahead_on)
int bs3 = request.security(syminfo.tickerid, iB3, f_bias(), lookahead = barmerge.lookahead_on)
int bs4 = request.security(syminfo.tickerid, iB4, f_bias(), lookahead = barmerge.lookahead_on)
int nBu = (iB1On and nz(bs1) == 1 ? 1 : 0) + (iB2On and nz(bs2) == 1 ? 1 : 0) + (iB3On and nz(bs3) == 1 ? 1 : 0) + (iB4On and nz(bs4) == 1 ? 1 : 0)
int nBe = (iB1On and nz(bs1) == -1 ? 1 : 0) + (iB2On and nz(bs2) == -1 ? 1 : 0) + (iB3On and nz(bs3) == -1 ? 1 : 0) + (iB4On and nz(bs4) == -1 ? 1 : 0)
int bias = nBu > nBe ? 1 : nBe > nBu ? -1 : 0
type Lvl
float y
int t
int side
int kind
line ln
label lb
string txt
var array<Lvl> lvls = array.new<Lvl>()
f_lvlC(int k, int side) =>
switch k
0 => side == 1 ? iHlBsl : iHlSsl
1 => iAmC
2 => iPmC
3 => iAsC
4 => iLoC
5 => iPdC
6 => iPwC
=> iDtC
f_addLvl(float y, int t, int side, int k, string txt) =>
color c = f_lvlC(k, side)
bool hl = k == 0
line ln = line.new(t, y, rx, y, xloc.bar_time, color = c, style = f_st(hl ? iHlSt : iSlSt), width = hl ? iHlW : 1)
label lb = (not hl or iHlLb) ? label.new(rx, y, txt, xloc.bar_time, color = color(na), textcolor = c, style = label.style_label_left, size = f_sz(hl ? iHlLbSz : iSlLbSz)) : na
lvls.push(Lvl.new(y, t, side, k, ln, lb, txt))
f_dropKind(int k) =>
if lvls.size() > 0
for i = lvls.size() - 1 to 0
Lvl l = lvls.get(i)
if l.kind == k
l.ln.delete()
l.lb.delete()
lvls.remove(i)
f_cap(int k, int side, int mx) =>
int n = 0
if lvls.size() > 0
for i = lvls.size() - 1 to 0
Lvl l = lvls.get(i)
if l.kind == k and l.side == side
n += 1
if n > mx
l.ln.delete()
l.lb.delete()
lvls.remove(i)
bool sesShow = timeframe.isintraday and tfSec < 14400
bool pdShow = timeframe.isintraday
bool pwShow = tfSec < 604800
bool hlShow = iHlOn and timeframe.in_seconds(iHlTf) > tfSec
bool dtShow = iDtOn and tfSec >= 60 and tfSec < 3600
int hlN = iHlStr == "Sensitive" ? 1 : iHlStr == "Strict" ? 3 : 2
f_piv(int n) =>
float ph = ta.pivothigh(high, n, n)
float pl = ta.pivotlow(low, n, n)
[ph[1], pl[1], time[n + 1], time]
[hlPh, hlPl, hlPt, hlT] = request.security(syminfo.tickerid, iHlTf, f_piv(hlN), lookahead = barmerge.lookahead_on)
if hlShow and hlT != hlT[1]
if not na(hlPh)
f_addLvl(hlPh, hlPt, 1, 0, "BSL")
f_cap(0, 1, 10)
if not na(hlPl)
f_addLvl(hlPl, hlPt, -1, 0, "SSL")
f_cap(0, -1, 10)
type Ses
float h = na
float l = na
int hT = 0
int lT = 0
method track(Ses s, bool inS, bool st) =>
if st
s.h := high
s.l := low
s.hT := time
s.lT := time
else if inS
if high > s.h
s.h := high
s.hT := time
if low < s.l
s.l := low
s.lT := time
s
f_sesEnd(Ses s, int k, string nm) =>
if not na(s.h)
f_dropKind(k)
f_addLvl(s.h, s.hT, 1, k, nm + " H")
f_addLvl(s.l, s.lT, -1, k, nm + " L")
var Ses sAm = Ses.new()
var Ses sPm = Ses.new()
var Ses sAs = Ses.new()
var Ses sLo = Ses.new()
bool inAm = f_in(iAmS)
bool inPm = f_in(iPmS)
bool inAs = f_in(iAsS)
bool inLo = f_in(iLoS)
sAm.track(inAm, inAm and not inAm[1])
sPm.track(inPm, inPm and not inPm[1])
sAs.track(inAs, inAs and not inAs[1])
sLo.track(inLo, inLo and not inLo[1])
if sesShow
if iAmOn and not inAm and inAm[1]
f_sesEnd(sAm, 1, "NY AM")
if iPmOn and not inPm and inPm[1]
f_sesEnd(sPm, 2, "NY PM")
if iAsOn and not inAs and inAs[1]
f_sesEnd(sAs, 3, "Asia")
if iLoOn and not inLo and inLo[1]
f_sesEnd(sLo, 4, "London")
[pdH, pdL, pdT] = request.security(syminfo.tickerid, "D", [high[1], low[1], time], lookahead = barmerge.lookahead_on)
[pwH, pwL, pwT] = request.security(syminfo.tickerid, "W", [high[1], low[1], time], lookahead = barmerge.lookahead_on)
if iPdOn and pdShow and pdT != pdT[1] and not na(pdH)
f_dropKind(5)
f_addLvl(pdH, pdT, 1, 5, "PDH")
f_addLvl(pdL, pdT, -1, 5, "PDL")
if iPwOn and pwShow and pwT != pwT[1] and not na(pwH)
f_dropKind(6)
f_addLvl(pwH, pwT, 1, 6, "PWH")
f_addLvl(pwL, pwT, -1, 6, "PWL")
string dtTf = tfSec < 60 ? timeframe.period : "1"
[dtT, dtH, dtL, dtO, dtC] = request.security_lower_tf(syminfo.tickerid, dtTf, [time, high, low, open, close])
if dtShow and dtT.size() > 0
for i = 0 to dtT.size() - 1
int tt = dtT.get(i)
if hour(tt, TZ) == 8 and minute(tt, TZ) == 30
float uw = dtH.get(i) - math.max(dtO.get(i), dtC.get(i))
float lw = math.min(dtO.get(i), dtC.get(i)) - dtL.get(i)
if uw >= iDtMin or lw >= iDtMin
f_dropKind(7)
if uw >= iDtMin
f_addLvl(dtH.get(i), tt, 1, 7, "DATA H")
if lw >= iDtMin
f_addLvl(dtL.get(i), tt, -1, 7, "DATA L")
bool swHit = false
string swTxt = ""
if lvls.size() > 0
for i = lvls.size() - 1 to 0
Lvl l = lvls.get(i)
if l.t < time and (l.side == 1 ? high > l.y : low < l.y)
tsSwp.set(l.side == 1 ? 1 : 0, time)
if l.kind > 0
swHit := true
swTxt := swTxt + (swTxt == "" ? "" : ", ") + l.txt
if iSlKeep and l.kind > 0
l.ln.set_x2(time)
if not na(l.lb)
l.lb.set_x(time)
else
l.ln.delete()
l.lb.delete()
lvls.remove(i)
string pairSym = switch syminfo.root
"NQ" => "CME_MINI:ES1!"
"ES" => "CME_MINI:NQ1!"
"MNQ" => "CME_MINI:MES1!"
"MES" => "CME_MINI:MNQ1!"
"YM" => "CME_MINI:ES1!"
"MYM" => "CME_MINI:MES1!"
"GC" => "COMEX:SI1!"
"SI" => "COMEX:GC1!"
"MGC" => "COMEX:SIL1!"
"SIL" => "COMEX:MGC1!"
=> iSmSym
string smtSym = iSmMode == "Automatic" ? pairSym : iSmSym
array<string> smtParts = str.split(smtSym, ":")
string pairNm = str.upper(str.replace_all(str.replace_all(smtParts.get(smtParts.size() - 1), "1!", ""), "2!", ""))
f_pair() => [time, high, low, low > high[2], high < low[2]]
[pT, pH, pL, pFb, pFs] = request.security(ticker.inherit(syminfo.tickerid, smtSym), timeframe.period, f_pair(), gaps = barmerge.gaps_on, ignore_invalid_symbol = true)
bool smOn = timeframe.isintraday
bool pOk = smOn and not na(pT) and pT == time
var float fH = na
var float fL = na
if pOk
fH := pH
fL := pL
type SmtD
line ln
label lb
var array<SmtD> smts = array.new<SmtD>()
f_smtDraw(int d, int x1, float y1, int x2, float y2, string tag) =>
color c = d == 1 ? iSmBuC : iSmBeC
line ln = line.new(x1, y1, x2, y2, xloc.bar_time, color = c, width = d == 1 ? iSmBuW : iSmBeW, style = f_st(d == 1 ? iSmBuSt : iSmBeSt))
string tx = tag + (iSmSymT ? " w/ " + pairNm : "")
label lb = iSmLb ? label.new(x2, y2, tx, xloc.bar_time, color = color(na), textcolor = iSmLbC, style = d == 1 ? label.style_label_up : label.style_label_down, size = f_sz(iSmLbSz)) : na
smts.push(SmtD.new(ln, lb))
if smts.size() > iSmMax
SmtD o = smts.shift()
o.ln.delete()
o.lb.delete()
int smN = iSmSens == "Sensitive" ? 1 : iSmSens == "Strict" ? 6 : 4
float cPh = ta.pivothigh(high, smN, smN)
float cPl = ta.pivotlow(low, smN, smN)
float pWinH = ta.highest(fH, 2 * smN + 1)
float pWinL = ta.lowest(fL, 2 * smN + 1)
int pvT = time[smN]
var float lPh = na
var float lPph = na
var int lPhT = 0
var int lPhBi = 0
var float lPl = na
var float lPpl = na
var int lPlT = 0
var int lPlBi = 0
if smOn and not na(cPh)
if not na(lPh) and not na(lPph) and not na(pWinH) and bar_index - smN - lPhBi <= SMT_SPAN
if (cPh > lPh and pWinH <= lPph) or (cPh < lPh and pWinH > lPph)
tsSmt.set(1, time)
f_smtDraw(-1, lPhT, lPh, pvT, cPh, "SMT")
lPh := cPh
lPph := pWinH
lPhT := pvT
lPhBi := bar_index - smN
if smOn and not na(cPl)
if not na(lPl) and not na(lPpl) and not na(pWinL) and bar_index - smN - lPlBi <= SMT_SPAN
if (cPl < lPl and pWinL >= lPpl) or (cPl > lPl and pWinL < lPpl)
tsSmt.set(0, time)
f_smtDraw(1, lPlT, lPl, pvT, cPl, "SMT")
lPl := cPl
lPpl := pWinL
lPlT := pvT
lPlBi := bar_index - smN
var line rtBuL = na
var line rtBeL = na
var label rtBuB = na
var label rtBeB = na
if barstate.islast
rtBuL.delete()
rtBeL.delete()
rtBuB.delete()
rtBeB.delete()
if iSmRt and pOk
if not na(lPl) and not na(lPpl) and ((low < lPl and pL >= lPpl) or (low > lPl and pL < lPpl))
rtBuL := line.new(lPlT, lPl, time, low, xloc.bar_time, color = iSmBuC, width = iSmBuW, style = line.style_dashed)
rtBuB := iSmLb ? label.new(time, low, "SMT" + (iSmSymT ? " w/ " + pairNm : ""), xloc.bar_time, color = color(na), textcolor = iSmLbC, style = label.style_label_up, size = f_sz(iSmLbSz)) : na
if not na(lPh) and not na(lPph) and ((high > lPh and pH <= lPph) or (high < lPh and pH > lPph))
rtBeL := line.new(lPhT, lPh, time, high, xloc.bar_time, color = iSmBeC, width = iSmBeW, style = line.style_dashed)
rtBeB := iSmLb ? label.new(time, high, "SMT" + (iSmSymT ? " w/ " + pairNm : ""), xloc.bar_time, color = color(na), textcolor = iSmLbC, style = label.style_label_down, size = f_sz(iSmLbSz)) : na
bool cFb = low > high[2]
bool cFs = high < low[2]
if iSmGap and pOk
if cFb != pFb
tsSmt.set(0, time)
f_smtDraw(1, time[2], low[2], time, low, "Gap SMT")
if cFs != pFs
tsSmt.set(1, time)
f_smtDraw(-1, time[2], high[2], time, high, "Gap SMT")
type QCyc
int lenS
string nm
int id = -1
float h = na
float l = na
int hT = 0
int lT = 0
float qh = na
float ql = na
float h1 = na
float l1 = na
int hT1 = 0
int lT1 = 0
float qh1 = na
float ql1 = na
method step(QCyc c, int sNy) =>
int nid = int(math.floor(sNy / c.lenS))
if nid != c.id
if c.id != -1 and not na(c.h)
if not na(c.h1) and not na(c.qh) and not na(c.qh1)
if (c.h > c.h1 and c.qh <= c.qh1) or (c.h < c.h1 and c.qh > c.qh1)
tsSmt.set(1, time)
f_smtDraw(-1, c.hT1, c.h1, c.hT, c.h, "SSMT " + c.nm)
if not na(c.l1) and not na(c.ql) and not na(c.ql1)
if (c.l < c.l1 and c.ql >= c.ql1) or (c.l > c.l1 and c.ql < c.ql1)
tsSmt.set(0, time)
f_smtDraw(1, c.lT1, c.l1, c.lT, c.l, "SSMT " + c.nm)
c.h1 := c.h
c.l1 := c.l
c.hT1 := c.hT
c.lT1 := c.lT
c.qh1 := c.qh
c.ql1 := c.ql
c.id := nid
c.h := high
c.l := low
c.hT := time
c.lT := time
c.qh := pOk ? pH : na
c.ql := pOk ? pL : na
else
if high > c.h
c.h := high
c.hT := time
if low < c.l
c.l := low
c.lT := time
if pOk
c.qh := na(c.qh) ? pH : math.max(c.qh, pH)
c.ql := na(c.ql) ? pL : math.min(c.ql, pL)
c
var QCyc qMic = QCyc.new(1350, "Micro")
var QCyc q90 = QCyc.new(5400, "90m")
var QCyc qDay = QCyc.new(21600, "Daily")
int sNy = ((hour(time, TZ) + 6) % 24) * 3600 + minute(time, TZ) * 60 + second(time, TZ)
if iSmSeq and smOn
if tfSec <= 60
qMic.step(sNy)
if tfSec <= 900
q90.step(sNy)
if tfSec <= 3600
qDay.step(sNy)
type Zone
int dir
float top
float bot
int t
int src
box bx
line ce
f_rbCalc(int n) =>
var float sh = na
var float sl = na
float ph = ta.pivothigh(high, n, n)
float pl = ta.pivotlow(low, n, n)
if not na(ph)
sh := ph
if not na(pl)
sl := pl
int d = 0
float top = na
float bot = na
if not na(sh) and high > sh
if math.max(open, close) < sh
d := -1
top := high
bot := math.max(open, close)
sh := na
if not na(sl) and low < sl
if math.min(open, close) > sl
d := 1
top := math.min(open, close)
bot := low
sl := na
[d, top, bot]
f_rbHtf() =>
[d, tp, bt] = f_rbCalc(2)
[d[1], tp[1], bt[1], time[1], time]
[rbD, rbTop, rbBot] = f_rbCalc(2)
[rhD, rhTop, rhBot, rhX, rhN] = request.security(syminfo.tickerid, iRbTf, f_rbHtf(), lookahead = barmerge.lookahead_on)
bool rbUseHtf = iRbHtf and timeframe.in_seconds(iRbTf) > tfSec
var array<Zone> rbs = array.new<Zone>()
f_rbAdd(int d, float tp, float bt, int t, string tag) =>
color c = d == 1 ? iRbBu : iRbBe
box bx = box.new(t, tp, rx, bt, xloc = xloc.bar_time, border_color = color(na), border_width = 0, bgcolor = c, text = tag, text_size = size.tiny, text_color = color.new(c, 0), text_halign = text.align_right)
line ce = iRbCe ? line.new(t, (tp + bt) / 2, rx, (tp + bt) / 2, xloc.bar_time, color = color.new(c, 30), style = f_st(iRbCeSt)) : na
rbs.push(Zone.new(d, tp, bt, t, 0, bx, ce))
tsRb.set(d == 1 ? 0 : 1, time)
if rbs.size() > 10
Zone o = rbs.shift()
o.bx.delete()
o.ce.delete()
if iRbOn
if rbUseHtf
if rhN != rhN[1] and nz(rhD) != 0
f_rbAdd(rhD, rhTop, rhBot, rhX, iRbTfLb ? f_tfShort(iRbTf) : "")
else if rbD != 0
f_rbAdd(rbD, rbTop, rbBot, time, "")
if rbs.size() > 0
for i = rbs.size() - 1 to 0
Zone z = rbs.get(i)
if z.t < time
if (z.dir == 1 and close < z.bot) or (z.dir == -1 and close > z.top)
z.bx.delete()
z.ce.delete()
rbs.remove(i)
else if (z.dir == 1 ? low <= z.top : high >= z.bot)
tsRb.set(z.dir == 1 ? 0 : 1, time)
f_gap() =>
int d = low[1] > high[3] ? 1 : high[1] < low[3] ? -1 : 0
float top = d == 1 ? low[1] : d == -1 ? low[3] : na
float bot = d == 1 ? high[3] : d == -1 ? high[1] : na
[d, top, bot, time[2], time]
[g1D, g1T, g1B, g1X, g1N] = request.security(syminfo.tickerid, iFv1, f_gap(), lookahead = barmerge.lookahead_on)
[g2D, g2T, g2B, g2X, g2N] = request.security(syminfo.tickerid, iFv2, f_gap(), lookahead = barmerge.lookahead_on)
[g3D, g3T, g3B, g3X, g3N] = request.security(syminfo.tickerid, iFv3, f_gap(), lookahead = barmerge.lookahead_on)
bool fv1 = iFvOn and iFv1On and timeframe.in_seconds(iFv1) > tfSec
bool fv2 = iFvOn and iFv2On and timeframe.in_seconds(iFv2) > tfSec
bool fv3 = iFvOn and iFv3On and timeframe.in_seconds(iFv3) > tfSec
var array<Zone> gaps = array.new<Zone>()
f_gapNew(int s, int d, float tp, float bt, int t) =>
if d != 0 and not na(tp) and tp - bt >= iFvMin
gaps.push(Zone.new(d, tp, bt, t, s, na, na))
if gaps.size() > 90
gaps.shift()
if fv1 and g1N != g1N[1]
f_gapNew(0, nz(g1D), g1T, g1B, g1X)
if fv2 and g2N != g2N[1]
f_gapNew(1, nz(g2D), g2T, g2B, g2X)
if fv3 and g3N != g3N[1]
f_gapNew(2, nz(g3D), g3T, g3B, g3X)
if gaps.size() > 0
for i = gaps.size() - 1 to 0
Zone z = gaps.get(i)
if (z.dir == 1 and close < z.bot) or (z.dir == -1 and close > z.top)
gaps.remove(i)
else if low <= z.top and high >= z.bot
tsFvg.set(z.dir == 1 ? 0 : 1, time)
var array<box> fvBx = array.new<box>()
var array<line> fvLn = array.new<line>()
if barstate.islast
for b in fvBx
b.delete()
for l in fvLn
l.delete()
fvBx.clear()
fvLn.clear()
array<string> tfs = array.from(iFv1, iFv2, iFv3)
array<bool> ons = array.from(fv1, fv2, fv3)
for s = 0 to 2
if ons.get(s)
for d in array.from(1, -1)
int bi = -1
float bd = na
for [j, z] in gaps
if z.src == s and z.dir == d
float dist = math.abs(close - (z.top + z.bot) / 2)
if na(bd) or dist < bd
bd := dist
bi := j
if bi >= 0
Zone z = gaps.get(bi)
color c = d == 1 ? iFvBu : iFvBe
fvBx.push(box.new(z.t, z.top, rx, z.bot, xloc = xloc.bar_time, border_color = iFvBrd ? color.new(c, 0) : color(na), border_width = iFvBrd ? 1 : 0, bgcolor = c, text = f_tfShort(tfs.get(s)) + " FVG", text_size = f_sz(iFvLbSz), text_color = iFvLbC, text_halign = text.align_right))
if iFvCe
fvLn.push(line.new(z.t, (z.top + z.bot) / 2, rx, (z.top + z.bot) / 2, xloc.bar_time, color = color.new(c, 30), style = f_st(iFvCeSt)))
type Sw
float y
int t
bool swept = false
var array<Sw> swHi = array.new<Sw>()
var array<Sw> swLo = array.new<Sw>()
float tPh = ta.pivothigh(high, 2, 2)
float tPl = ta.pivotlow(low, 2, 2)
if not na(tPh)
swHi.push(Sw.new(tPh, time[2]))
if swHi.size() > 60
swHi.shift()
if not na(tPl)
swLo.push(Sw.new(tPl, time[2]))
if swLo.size() > 60
swLo.shift()
for s in swHi
if not s.swept and high > s.y
s.swept := true
for s in swLo
if not s.swept and low < s.y
s.swept := true
f_targets(int d, float en, float r) =>
array<Sw> src = d == 1 ? swHi : swLo
array<float> ys = array.new<float>()
array<int> ts = array.new<int>()
for s in src
if not s.swept and d * (s.y - en) > 0
ys.push(s.y)
ts.push(s.t)
array<int> idx = ys.size() > 0 ? ys.sort_indices(d == 1 ? order.ascending : order.descending) : array.new<int>()
int k = 0
float be = en + d * r
int beT = time
if idx.size() > 0
be := ys.get(idx.get(0))
beT := ts.get(idx.get(0))
k := 1
float tp1 = na
int tp1T = time
while k < idx.size() and na(tp1)
float y = ys.get(idx.get(k))
if d * (y - be) > 0 and (not iMinRR or d * (y - en) >= r)
tp1 := y
tp1T := ts.get(idx.get(k))
k += 1
if na(tp1)
tp1 := d * (en + d * 2 * r - be) > 0 ? en + d * 2 * r : be + d * r
float tp2 = na
int tp2T = time
while k < idx.size() and na(tp2)
float y = ys.get(idx.get(k))
if d * (y - tp1) > 0 and (not iMinRR or d * (y - en) >= 2 * r)
tp2 := y
tp2T := ts.get(idx.get(k))
k += 1
if na(tp2)
tp2 := d * (en + d * 3 * r - tp1) > 0 ? en + d * 3 * r : tp1 + d * r
[be, beT, tp1, tp1T, tp2, tp2T]
float atr = ta.atr(14)
var array<float> bgTop = array.new<float>()
var array<int> bgBi = array.new<int>()
var array<float> buBot = array.new<float>()
var array<int> buBi = array.new<int>()
bool ifvBu = false
bool ifvBe = false
if bgTop.size() > 0
for i = bgTop.size() - 1 to 0
if bar_index - bgBi.get(i) > 30
bgTop.remove(i)
bgBi.remove(i)
else if close > bgTop.get(i) and close[1] <= bgTop.get(i)
ifvBu := true
bgTop.remove(i)
bgBi.remove(i)
if buBot.size() > 0
for i = buBot.size() - 1 to 0
if bar_index - buBi.get(i) > 30
buBot.remove(i)
buBi.remove(i)
else if close < buBot.get(i) and close[1] >= buBot.get(i)
ifvBe := true
buBot.remove(i)
buBi.remove(i)
if cFs
bgTop.push(low[2])
bgBi.push(bar_index)
if cFb
buBot.push(high[2])
buBi.push(bar_index)
bool dispBu = close > open and close - open >= 1.5 * atr
bool dispBe = close < open and open - close >= 1.5 * atr
var float beRunO = na
var float buRunO = na
bool cisdBu = close > open and not na(beRunO) and close > beRunO
bool cisdBe = close < open and not na(buRunO) and close < buRunO
if close < open and not (close[1] < open[1])
beRunO := open
if close > open and not (close[1] > open[1])
buRunO := open
int orLen = iOrLen == "5m" ? 5 : 15
bool orTfOk = timeframe.isintraday and tfSec <= orLen * 60
int asSt = f_hm(iAsS, 0)
int asEn = f_hm(iAsS, 5)
int loSt = f_hm(iLoS, 0)
int loEn = f_hm(iLoS, 5)
int nyMin = hour(time, TZ) * 60 + minute(time, TZ)
int nySec = nyMin * 60 + second(time, TZ)
f_win(int st) => nyMin >= st and nyMin < st + orLen
int winSt = f_win(570) ? 570 : (iOrAs and f_win(asSt)) ? asSt : (iOrLo and f_win(loSt)) ? loSt : -1
bool inOR = orTfOk and winSt >= 0
bool orBeg = inOR and (not inOR[1] or winSt != winSt[1])
bool orEnd = inOR and nySec + tfSec >= (winSt + orLen) * 60
var bool orAct = false
var float orH = na
var float orL = na
var float orM = na
var int orT = 0
var int orFin = -1
var int orDead = 0
var float bH = na
var float bL = na
var float exLo = na
var float exHi = na
var int exLoT = 0
var int exHiT = 0
var bool orAbv = false
var bool orBlw = false
var bool cwDone = false
var bool fkDone = false
var int armDir = 0
var float armLvl = na
var int armExp = 0
var box orBx = na
var line oHl = na
var line oMl = na
var line oLl = na
var label oHb = na
var label oMb = na
var label oLb = na
if orBeg
if orAct and not na(orBx)
orBx.set_right(time)
oHl.set_x2(time)
oMl.set_x2(time)
oLl.set_x2(time)
oHb.set_x(time)
oMb.set_x(time)
oLb.set_x(time)
orAct := false
bH := high
bL := low
orT := time
exLo := low
exHi := high
exLoT := time
exHiT := time
else
if inOR
bH := math.max(bH, high)
bL := math.min(bL, low)
if low < exLo
exLo := low
exLoT := time
if high > exHi
exHi := high
exHiT := time
if orEnd and barstate.isconfirmed
orH := bH
orL := bL
orM := (bH + bL) / 2
orAct := true
orFin := bar_index
int rmMin = winSt == 570 ? 720 : winSt == asSt ? asEn : loEn
orDead := time + ((rmMin * 60 - nySec + 86400) % 86400) * 1000
orAbv := false
orBlw := false
cwDone := false
fkDone := false
armDir := 0
orBx := na
if iOrOn
orBx := box.new(orT, orH, rx, orL, xloc = xloc.bar_time, border_color = color(na), border_width = 0, bgcolor = iOrFill)
oHl := line.new(orT, orH, rx, orH, xloc.bar_time, color = iOrLnC, style = f_st(iOrSt), width = iOrW)
oMl := line.new(orT, orM, rx, orM, xloc.bar_time, color = iOrMc, style = f_st(iOrSt), width = iOrW)
oLl := line.new(orT, orL, rx, orL, xloc.bar_time, color = iOrLnC, style = f_st(iOrSt), width = iOrW)
oHb := iOrLb ? label.new(rx, orH, "ORH" + (iOrPx ? " " + f_px(orH) : ""), xloc.bar_time, color = color(na), textcolor = iOrHc, style = label.style_label_left, size = f_sz(iOrLbSz)) : na
oMb := iOrLb ? label.new(rx, orM, "50%" + (iOrPx ? " " + f_px(orM) : ""), xloc.bar_time, color = color(na), textcolor = iOrMc, style = label.style_label_left, size = f_sz(iOrLbSz)) : na
oLb := iOrLb ? label.new(rx, orL, "ORL" + (iOrPx ? " " + f_px(orL) : ""), xloc.bar_time, color = color(na), textcolor = iOrLc, style = label.style_label_left, size = f_sz(iOrLbSz)) : na
if orAct and iOrNoon and time >= orDead
orBx.delete()
oHl.delete()
oMl.delete()
oLl.delete()
oHb.delete()
oMb.delete()
oLb.delete()
orBx := na
orAct := false
armDir := 0
var string gGr = "-"
var string gBi = "-"
var string gSmt = "-"
var string gRb = "-"
var string gFvg = "-"
var string gSwp = "-"
bool cwL = false
bool cwS = false
if orAct and bar_index > orFin and barstate.isconfirmed
bool wasAbv = orAbv
bool wasBlw = orBlw
if iFkOn and not fkDone
if bias == 1 and close < orL
fkDone := true
label.new(time, low, "Fakeout", xloc.bar_time, color = color(na), textcolor = iFkC, style = label.style_label_right, size = size.small)
else if bias == -1 and close > orH
fkDone := true
label.new(time, high, "Fakeout", xloc.bar_time, color = color(na), textcolor = iFkC, style = label.style_label_right, size = size.small)
if iCwOn and not cwDone
if armDir != 0 and armDir != bias
armDir := 0
if bias == 1
bool rH = wasAbv and close > orH and close[1] <= orH
bool rL = wasBlw and close > orL and close[1] <= orL
if rH or rL
armDir := 1
armLvl := rH ? orH : orL
armExp := bar_index + CW_WIN
else if bias == -1
bool rL = wasBlw and close < orL and close[1] >= orL
bool rH = wasAbv and close < orH and close[1] >= orH
if rH or rL
armDir := -1
armLvl := rL ? orL : orH
armExp := bar_index + CW_WIN
int fd = 0
if armDir == 1
if close < open
armExp := bar_index + CW_WIN
if close > armLvl and close > open and (ifvBu or dispBu or cisdBu)
fd := 1
else if bar_index > armExp
armDir := 0
else if armDir == -1
if close > open
armExp := bar_index + CW_WIN
if close < armLvl and close < open and (ifvBe or dispBe or cisdBe)
fd := -1
else if bar_index > armExp
armDir := 0
if fd != 0
float en = close
float sl = fd == 1 ? exLo : exHi
int slT = fd == 1 ? exLoT : exHiT
float r = math.abs(en - sl)
if r > 0
cwDone := true
armDir := 0
cwL := fd == 1
cwS := fd == -1
[be, beT, tp1, tp1T, tp2, tp2T] = f_targets(fd, en, r)
bool cSmt = f_recent(tsSmt, fd)
bool cRb = f_recent(tsRb, fd)
bool cFvg = f_recent(tsFvg, fd)
bool cSwp = f_recent(tsSwp, fd)
int n = (cSmt ? 1 : 0) + (cRb ? 1 : 0) + (cFvg ? 1 : 0) + (cSwp ? 1 : 0)
gGr := f_grade(n)
gBi := fd == 1 ? "Bullish" : "Bearish"
gSmt := cSmt ? "✓" : "-"
gRb := cRb ? "✓" : "-"
gFvg := cFvg ? "✓" : "-"
gSwp := cSwp ? "✓" : "-"
string pat = fd == 1 ? (ifvBu ? "Inverted FVG" : dispBu ? "Displacement" : "CISD") : (ifvBe ? "Inverted FVG" : dispBe ? "Displacement" : "CISD")
string tip = (fd == 1 ? "CW+ · Long" : "CW- · Short") + " · Grade " + gGr + "\nReclaim of " + (armLvl == orH ? "ORH " : "ORL ") + f_px(armLvl) + " · " + pat + "\nEntry " + f_px(en) + " · SL " + f_px(sl) + "\nBE " + f_px(be) + " · TP1 " + f_px(tp1) + " · TP2 " + f_px(tp2) + "\nHTF Bias " + gBi + "\nSMT " + gSmt + " Rejection Block " + gRb + "\nHTF FVG " + gFvg + " Liquidity Sweep " + gSwp
color cc = fd == 1 ? iCwBu : iCwBe
int x2 = time + 8 * tfMs
line.new(time, en, x2, en, xloc.bar_time, color = cc, width = 3)
label.new(x2, en, fd == 1 ? "CW+" : "CW-", xloc.bar_time, color = color(na), textcolor = cc, style = label.style_label_left, size = size.normal, tooltip = tip)
if iLim
line.new(slT, sl, x2, sl, xloc.bar_time, color = iSlC, style = line.style_dotted)
label.new(x2, sl, "SL", xloc.bar_time, color = color(na), textcolor = iSlC, style = label.style_label_left, size = size.small)
line.new(beT, be, x2, be, xloc.bar_time, color = iBeC, style = line.style_dotted)
label.new(x2, be, "BE", xloc.bar_time, color = color(na), textcolor = iBeC, style = label.style_label_left, size = size.small)
line.new(tp1T, tp1, x2, tp1, xloc.bar_time, color = iTpC, style = line.style_dotted)
label.new(x2, tp1, "TP1", xloc.bar_time, color = color(na), textcolor = iTpC, style = label.style_label_left, size = size.small)
line.new(tp2T, tp2, x2, tp2, xloc.bar_time, color = iTpC, style = line.style_dotted)
label.new(x2, tp2, "TP2", xloc.bar_time, color = color(na), textcolor = iTpC, style = label.style_label_left, size = size.small)
if close > orH
orAbv := true
if close < orL
orBlw := true
if barstate.islast
for l in lvls
l.ln.set_x2(rx)
if not na(l.lb)
l.lb.set_x(rx)
for z in rbs
z.bx.set_right(rx)
if not na(z.ce)
z.ce.set_x2(rx)
if orAct and not na(orBx)
orBx.set_right(rx)
oHl.set_x2(rx)
oMl.set_x2(rx)
oLl.set_x2(rx)
if not na(oHb)
oHb.set_x(rx)
oMb.set_x(rx)
oLb.set_x(rx)
color TB_BG = color.new(#787B86, 25)
color BU_C = #089981
color BE_C = #F23645
f_stTx(int s) => s == 1 ? "Bullish" : s == -1 ? "Bearish" : "Neutral"
f_stC(int s) => s == 1 ? BU_C : s == -1 ? BE_C : color.white
var table tbB = table.new(position.top_right, 2, 6, bgcolor = TB_BG)
var table tbG = table.new(position.bottom_right, 2, 6, bgcolor = TB_BG)
if barstate.islast
if iBiTbl
tbB.cell(0, 0, "Timeframe", text_color = color.white, text_size = size.small)
tbB.cell(1, 0, "State", text_color = color.white, text_size = size.small)
int row = 1
array<bool> bOn = array.from(iB1On, iB2On, iB3On, iB4On)
array<string> bTf = array.from(iB1, iB2, iB3, iB4)
array<int> bSt = array.from(nz(bs1), nz(bs2), nz(bs3), nz(bs4))
for i = 0 to 3
if bOn.get(i)
tbB.cell(0, row, f_tfLong(bTf.get(i)), text_color = color.white, text_size = size.small)
tbB.cell(1, row, f_stTx(bSt.get(i)), text_color = f_stC(bSt.get(i)), text_size = size.small)
row += 1
tbB.cell(0, row, "Overall", text_color = color.white, text_size = size.small)
tbB.cell(1, row, f_stTx(bias), text_color = f_stC(bias), text_size = size.small)
if iChk and iCwOn
array<string> gk = array.from("Grade", "HTF Bias", "SMT", "Rejection Block", "HTF FVG", "Liquidity Sweep")
array<string> gv = array.from(gGr, gBi, gSmt, gRb, gFvg, gSwp)
for i = 0 to 5
color vc = i == 0 ? (gGr == "A+" or gGr == "A" ? BU_C : gGr == "B" ? #FF9800 : gGr == "-" ? color.white : BE_C) : i == 1 ? (gBi == "Bullish" ? BU_C : gBi == "Bearish" ? BE_C : color.white) : color.white
tbG.cell(0, i, gk.get(i), text_color = color.white, text_size = size.small, text_halign = text.align_right)
tbG.cell(1, i, gv.get(i), text_color = vc, text_size = size.small)
bool alWin = (not iAw1On and not iAw2On and not iAw3On) or (iAw1On and f_in(iAw1)) or (iAw2On and f_in(iAw2)) or (iAw3On and f_in(iAw3))
if iAlSw and swHit and alWin
alert(syminfo.ticker + " · Session liquidity swept: " + swTxt + " at " + f_px(close), alert.freq_once_per_bar_close)
if iAlCw and (cwL or cwS) and alWin
alert(syminfo.ticker + " · " + (cwL ? "CW+ long" : "CW- short") + " entry at " + f_px(close) + " · Grade " + gGr, alert.freq_once_per_bar_close)
alertcondition(cwL, "ORB Ultimate+ — CW Long", "CW+ long entry on {{ticker}} at {{close}}")
alertcondition(cwS, "ORB Ultimate+ — CW Short", "CW- short entry on {{ticker}} at {{close}}")