本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("🎀 Ms Robles ORB Confirmation", overlay=true, max_lines_count=500, max_labels_count=500)
TZ = "America/New_York"
// ================= INPUTS =================
gS = "Sessions (ET) - 15 min windows"
useNY = input.bool(true, "NY", group=gS)
useLDN = input.bool(true, "London", group=gS)
useAsia = input.bool(true, "Asia", group=gS)
sNY = input.session("0930-0945", "NY range window", group=gS)
sLDN = input.session("0300-0315", "London range window", group=gS)
sAS = input.session("2000-2015", "Asia range window", group=gS)
gT = "Trade rules"
winMin = input.int(120, "Trade window after range (min)", minval=15, group=gT)
rr = input.float(2.0, "Reward : Risk", step=0.5, group=gT)
slMode = input.string("Midpoint", "Aggressive SL", options=["Midpoint", "Opposite side"], group=gT)
slBuf = input.float(2.0, "SL buffer (points)", group=gT)
fakeBars = input.int(3, "Fakeout: bars to close back inside", minval=1, group=gT)
tol = input.float(2.0, "Retest tolerance (points)", group=gT)
gQ = "Quality filters (A / B+)"
dispMult = input.float(0.8, "Displacement: body >= x * ATR", step=0.1, group=gQ)
bodyPct = input.float(60, "Displacement: body % of candle", group=gQ)
useTrend = input.bool(true, "Trend filter (HTF EMA)", group=gQ)
htf = input.timeframe("60", "HTF for trend", group=gQ)
emaLen = input.int(50, "HTF EMA length", group=gQ)
useVol = input.bool(true, "Volume above 20-bar average", group=gQ)
minRng = input.float(0.3, "Min range size (x 15m ATR)", step=0.1, group=gQ)
maxRng = input.float(2.0, "Max range size (x 15m ATR)", step=0.1, group=gQ)
minA = input.int(5, "Score needed for A (max 6)", minval=1, maxval=6, group=gQ)
minB = input.int(4, "Score needed for B+", minval=1, maxval=6, group=gQ)
gC = "Colors"
colBull = input.color(#FF69B4, "Bullish (hot pink)", group=gC)
colBear = input.color(#C2185B, "Bearish (raspberry)", group=gC)
colBlush = input.color(#FFC1D6, "Blush", group=gC)
colText = input.color(#AD1457, "Table text", group=gC)
// ================= DATA =================
atr15 = request.security(syminfo.tickerid, "15", ta.atr(14)[1], lookahead=barmerge.lookahead_on)
htfEma = request.security(syminfo.tickerid, htf, ta.ema(close, emaLen)[1], lookahead=barmerge.lookahead_on)
atrC = ta.atr(14)
volAvg = ta.sma(volume, 20)
// ================= SESSION WINDOWS =================
nyW = useNY and not na(time(timeframe.period, sNY, TZ))
ldnW = useLDN and not na(time(timeframe.period, sLDN, TZ))
asW = useAsia and not na(time(timeframe.period, sAS, TZ))
inWin = nyW or ldnW or asW
startNew = inWin and not inWin[1]
lockNow = not inWin and inWin[1]
// ================= STATE =================
var float orH = na
var float orL = na
var bool locked = false
var int lockT = 0
var string sesName = "-"
var int dir = 0
var int brkBar = 0
var int brkScore = 0
var bool longUsed = false
var bool shortUsed = false
var bool cutieDone = false
var string status = "Waiting for open"
if startNew
orH := high
orL := low
locked := false
sesName := nyW ? "NY" : ldnW ? "London" : "Asia"
dir := 0
longUsed := false
shortUsed := false
cutieDone := false
status := "Building 15m range"
else if inWin
orH := math.max(orH, high)
orL := math.min(orL, low)
if lockNow
locked := true
lockT := time
status := "Range set - watching"
active = locked and not inWin and time <= lockT + winMin * 60000
conf = barstate.isconfirmed
mid = (orH + orL) / 2
rngPts = orH - orL
// ================= CANDLE QUALITY =================
body = math.abs(close - open)
rng = high - low
disp = rng > 0 and body >= dispMult * atrC and body / rng * 100 >= bodyPct
volOk = not useVol or volume > volAvg
rangeOk = rngPts >= minRng * atr15 and rngPts <= maxRng * atr15
scL = 1 + (disp and close > open ? 2 : 0) + (not useTrend or close > htfEma ? 1 : 0) + (volOk ? 1 : 0) + (rangeOk ? 1 : 0)
scS = 1 + (disp and close < open ? 2 : 0) + (not useTrend or close < htfEma ? 1 : 0) + (volOk ? 1 : 0) + (rangeOk ? 1 : 0)
// ================= SIGNALS =================
bool bullBO = false
bool bearBO = false
bool waitL = false
bool waitS = false
bool fake = false
bool cuteL = false
bool cuteS = false
int fkDir = 0
float aggE = na
float aggSL = na
float aggTP = na
float cutE = na
float cutSL = na
float cutTP = na
if active and conf
// 1) Fakeout: closes back inside the range shortly after breaking
if dir == 1 and bar_index > brkBar and bar_index - brkBar <= fakeBars and close < orH
fake := true
fkDir := 1
dir := 0
status := "Fakeout (long failed)"
else if dir == -1 and bar_index > brkBar and bar_index - brkBar <= fakeBars and close > orL
fake := true
fkDir := -1
dir := 0
status := "Fakeout (short failed)"
// 2) First close outside the range = breakout
if dir == 0 and not fake
if close > orH and not longUsed
dir := 1
longUsed := true
brkBar := bar_index
brkScore := scL
cutieDone := false
if scL >= minB
bullBO := true
aggE := close
aggSL := (slMode == "Midpoint" ? mid : orL) - slBuf
aggTP := close + rr * (close - aggSL)
status := "Bullish breakout " + (scL >= minA ? "A" : "B+")
else
waitL := true
status := "Weak breakout - WAIT for retest"
else if close < orL and not shortUsed
dir := -1
shortUsed := true
brkBar := bar_index
brkScore := scS
cutieDone := false
if scS >= minB
bearBO := true
aggE := close
aggSL := (slMode == "Midpoint" ? mid : orH) + slBuf
aggTP := close - rr * (aggSL - close)
status := "Bearish breakout " + (scS >= minA ? "A" : "B+")
else
waitS := true
status := "Weak breakout - WAIT for retest"
// 3) Cutie Confirmation: retest of the edge, hold, close back in trend direction
if dir == 1 and not cutieDone and bar_index > brkBar and low <= orH + tol and close > orH and close > open
cuteL := true
cutieDone := true
cutE := close
cutSL := math.min(low, orH) - slBuf
cutTP := close + rr * (close - cutSL)
status := "Cutie Confirmation BUY"
if dir == -1 and not cutieDone and bar_index > brkBar and high >= orL - tol and close < orL and close < open
cuteS := true
cutieDone := true
cutE := close
cutSL := math.max(high, orL) + slBuf
cutTP := close - rr * (cutSL - close)
status := "Cutie Confirmation SELL"
// ================= WIN-RATE TRACKER =================
f_track(bool newSig, int d, float e, float s, float t) =>
var int w = 0
var int l = 0
var int ad = 0
var float sl_ = na
var float tp_ = na
if ad == 1
if low <= sl_
l += 1
ad := 0
else if high >= tp_
w += 1
ad := 0
else if ad == -1
if high >= sl_
l += 1
ad := 0
else if low <= tp_
w += 1
ad := 0
if newSig and ad == 0
ad := d
sl_ := s
tp_ := t
[w, l, ad]
[aW, aL, aAct] = f_track(bullBO or bearBO, bullBO ? 1 : -1, aggE, aggSL, aggTP)
[cW, cL, cAct] = f_track(cuteL or cuteS, cuteL ? 1 : -1, cutE, cutSL, cutTP)
// ================= DRAWING =================
f_draw(float e, float s, float t, color c) =>
x2 = bar_index + 20
line.new(bar_index, e, x2, e, color=c, width=2)
line.new(bar_index, s, x2, s, color=colBear, style=line.style_dashed)
line.new(bar_index, t, x2, t, color=c, style=line.style_dashed)
label.new(x2, t, "TP", style=label.style_label_left, color=color.new(c, 80), textcolor=colText, size=size.tiny)
label.new(x2, s, "SL", style=label.style_label_left, color=color.new(colBear, 80), textcolor=colText, size=size.tiny)
if bullBO
label.new(bar_index, low, "🎀 BUY " + (brkScore >= minA ? "A" : "B+"), style=label.style_label_up, color=colBull, textcolor=color.white, size=size.small)
f_draw(aggE, aggSL, aggTP, colBull)
if bearBO
label.new(bar_index, high, "🎀 SELL " + (brkScore >= minA ? "A" : "B+"), style=label.style_label_down, color=colBear, textcolor=color.white, size=size.small)
f_draw(aggE, aggSL, aggTP, colBear)
if waitL
label.new(bar_index, low, "⏳ Wait for retest", style=label.style_label_up, color=colBlush, textcolor=colText, size=size.small)
if waitS
label.new(bar_index, high, "⏳ Wait for retest", style=label.style_label_down, color=colBlush, textcolor=colText, size=size.small)
if fake
label.new(bar_index, fkDir == 1 ? high : low, "💔 Fakeout", style=fkDir == 1 ? label.style_label_down : label.style_label_up, color=color.new(colBlush, 0), textcolor=colText, size=size.small)
if cuteL
label.new(bar_index, low, "🎀 Cutie BUY " + (brkScore >= minA ? "A" : "B+"), style=label.style_label_up, color=colBull, textcolor=color.white, size=size.small)
f_draw(cutE, cutSL, cutTP, colBull)
if cuteS
label.new(bar_index, high, "🎀 Cutie SELL " + (brkScore >= minA ? "A" : "B+"), style=label.style_label_down, color=colBear, textcolor=color.white, size=size.small)
f_draw(cutE, cutSL, cutTP, colBear)
showR = not na(orH) and (inWin or (locked and time <= lockT + winMin * 60000))
pH = plot(showR ? orH : na, "OR High", color=colBull, linewidth=2, style=plot.style_linebr)
pL = plot(showR ? orL : na, "OR Low", color=colBear, linewidth=2, style=plot.style_linebr)
plot(showR ? mid : na, "OR Mid", color=color.new(colBlush, 20), linewidth=1, style=plot.style_linebr)
fill(pH, pL, color=color.new(colBlush, 82))
// ================= TABLE =================
f_wr(int w, int l) => (w + l) == 0 ? "-" : str.tostring(w / (w + l) * 100, "#") + "% (" + str.tostring(w) + "W/" + str.tostring(l) + "L)"
var table tb = table.new(position.top_right, 2, 6, bgcolor=color.new(colBlush, 5), border_width=1, border_color=colBull, frame_color=colBull, frame_width=2)
if barstate.islast
table.cell(tb, 0, 0, "🎀 Ms Robles ORB Confirmation", text_color=colText, text_size=size.normal)
table.merge_cells(tb, 0, 0, 1, 0)
table.cell(tb, 0, 1, "Session", text_color=colText, text_size=size.small)
table.cell(tb, 1, 1, sesName, text_color=colText, text_size=size.small)
table.cell(tb, 0, 2, "Range (pts)", text_color=colText, text_size=size.small)
table.cell(tb, 1, 2, na(rngPts) ? "-" : str.tostring(rngPts, "#.##"), text_color=colText, text_size=size.small)
table.cell(tb, 0, 3, "Status", text_color=colText, text_size=size.small)
table.cell(tb, 1, 3, status, text_color=colText, text_size=size.small)
table.cell(tb, 0, 4, "Aggressive", text_color=colText, text_size=size.small)
table.cell(tb, 1, 4, f_wr(aW, aL), text_color=colText, text_size=size.small)
table.cell(tb, 0, 5, "Cutie", text_color=colText, text_size=size.small)
table.cell(tb, 1, 5, f_wr(cW, cL), text_color=colText, text_size=size.small)
// ================= ALERTS =================
alertcondition(bullBO, "🎀 Bullish Breakout (A/B+)", "🎀 Ms Robles ORB Confirmation: Bullish Breakout - aggressive BUY")
alertcondition(bearBO, "🎀 Bearish Breakout (A/B+)", "🎀 Ms Robles ORB Confirmation: Bearish Breakout - aggressive SELL")
alertcondition(waitL or waitS, "⏳ Wait for Retest", "🎀 Ms Robles ORB Confirmation: Weak breakout - wait for retest")
alertcondition(fake, "💔 Fakeout", "🎀 Ms Robles ORB Confirmation: Fakeout - price closed back inside the range")
alertcondition(cuteL, "🎀 Cutie Confirmation BUY", "🎀 Ms Robles ORB Confirmation: Cutie Confirmation BUY")
alertcondition(cuteS, "🎀 Cutie Confirmation SELL", "🎀 Ms Robles ORB Confirmation: Cutie Confirmation SELL")