Mbf Ladder Precision Pivot Ladder Map

MissSippiBigFoot · study · 167 行 · 点赞 16 · TradingView 原页

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

Pine Script

//@version=6
// MBF LADDER v1.1 — Precision Ladder Map (MBF & RZ Trading, 2026-11-08)
// Auto-draws the daily floor-pivot ladder (R3-R2-R1-PIVOT-S1-S2-S3) from the
// previous session's high/low/close, plus PDH/PDL and the overnight high/low,
// on ANY symbol — SPX, SPY, ES, NQ, QQQ — so every chart shows the same map.
// v1.1 (CJ: "bigger and bolder for the ADHD mind"):
//   • thick SOLID lines by default (R/S width 3, PIVOT width 6, PDH/PDL 3)
//   • LARGE price tags filled in the level's color (white text) — readable at a glance
//   • when the market is CLOSED (weekend, after the bell) the ladder shows the
//     NEXT session's levels from the session that just finished, so the map is
//     ready for Monday on Sunday, and for tomorrow after today's close.
// Colors: resistance ORANGE, pivot BLACK, support NAVY, PDH/PDL PINK, overnight GOLD.
// Confluence: a level near PDH/PDL, the overnight H/L or a round number gets ★ and +1 width.
// Alerts: ONE alert → Condition "MBF LADDER" → "Any alert() function call".
indicator("MBF LADDER v1.1 — Precision Ladder Map", "MBF LADDER", overlay = true, max_lines_count = 40, max_labels_count = 40)
 
G1 = "Ladder"
G2 = "Extra levels"
G3 = "Confluence"
G4 = "Style — big & bold"
G5 = "Alerts"
src_tf    = input.timeframe("D", "Pivot timeframe", group = G1, tooltip = "D = daily floor pivots (default). W = weekly pivots for swing trades.")
show_r3   = input.bool(true, "Show R3 / S3", group = G1)
ext_left  = input.int(0, "Start lines N bars before today (0 = at today's open)", minval = 0, maxval = 500, group = G1)
nxt_closed = input.bool(true, "When market is closed, show NEXT session's ladder", group = G1)
show_pdhl = input.bool(true, "PDH / PDL (pink)", group = G2)
show_on   = input.bool(true, "Overnight high / low (gold) — futures & GTH", group = G2)
on_sess   = input.session("1515-0630", "Overnight window (chart time zone below)", group = G2)
tz        = input.string("America/Los_Angeles", "Time zone", group = G2)
conf_pct  = input.float(0.10, "Confluence tolerance (% of price)", minval = 0.01, maxval = 1.0, step = 0.01, group = G3)
rnd_step  = input.float(0.0, "Round-number step (0 = auto)", minval = 0.0, group = G3, tooltip = "Auto: 25 for index futures/SPX, 100 for NQ, 1 for SPY/QQQ-sized prices.")
c_res     = input.color(#FF9800, "Resistance (R)", group = G4)
c_piv     = input.color(#000000, "Pivot", group = G4)
c_sup     = input.color(#0D2B6B, "Support (S)", group = G4)
c_pd      = input.color(#E91E63, "PDH / PDL", group = G4)
c_on      = input.color(#C9A227, "Overnight H / L", group = G4)
w_lvl     = input.int(3, "R / S line width", minval = 1, maxval = 10, group = G4)
w_piv     = input.int(6, "PIVOT line width", minval = 1, maxval = 10, group = G4)
w_pd      = input.int(3, "PDH / PDL line width", minval = 1, maxval = 10, group = G4)
w_on      = input.int(2, "Overnight H / L line width", minval = 1, maxval = 10, group = G4)
ln_style  = input.string("Solid", "Line style", options = ["Solid", "Dashed"], group = G4)
lbl_size  = input.string(size.large, "Price tag size", options = [size.normal, size.large, size.huge], group = G4)
piv_size  = input.string(size.huge, "PIVOT tag size", options = [size.normal, size.large, size.huge], group = G4)
lbl_fill  = input.bool(true, "Filled price tags (white text on level color)", group = G4)
tag_pos   = input.string("Line start (clear of panels)", "Price tag position", options = ["Line start (clear of panels)", "Right of last candle"], group = G4)
lbl_off   = input.int(8, "Tags: bars right of last candle", minval = 1, maxval = 100, group = G4)
al_cross  = input.bool(true, "Alert: price CLOSES across a ladder level", group = G5)
al_sweep  = input.bool(true, "Alert: SWEEP & RECLAIM of a level (wick through, close back)", group = G5)
al_star   = input.bool(false, "Alerts only on ★ confluence levels", group = G5)
 
// ── previous session H/L/C (no repaint: [1] with lookahead on) ──
[pH0, pL0, pC0] = request.security(syminfo.tickerid, src_tf, [high[1], low[1], close[1]], lookahead = barmerge.lookahead_on)
// ── the session in progress / just finished (used only on the last bar when the market is closed) ──
[dH, dL, dC, dTC] = request.security(syminfo.tickerid, src_tf, [high, low, close, time_close], lookahead = barmerge.lookahead_on)
bool mkt_closed = nxt_closed and barstate.islast and not na(dTC) and timenow > dTC + 20 * 60 * 1000
float pH = mkt_closed ? dH : pH0
float pL = mkt_closed ? dL : pL0
float pC = mkt_closed ? dC : pC0
 
P  = (pH + pL + pC) / 3
R1 = 2 * P - pL
S1 = 2 * P - pH
R2 = P + (pH - pL)
S2 = P - (pH - pL)
R3 = pH + 2 * (P - pL)
S3 = pL - 2 * (pH - P)
 
// ── overnight high / low (resets at the start of the window) ──
bool in_on = not na(time(timeframe.period, on_sess, tz))
var float onH = na
var float onL = na
if in_on and not in_on[1]
    onH := high
    onL := low
else if in_on
    onH := math.max(onH, high)
    onL := math.min(onL, low)
 
// ── round-number step ──
float rstep = rnd_step > 0 ? rnd_step : close > 20000 ? 100.0 : close > 2000 ? 25.0 : 1.0
 
f_conf(float lv) =>
    float tol = close * conf_pct / 100
    bool c = math.abs(lv - pH) <= tol or math.abs(lv - pL) <= tol
    c := c or (show_on and not na(onH) and (math.abs(lv - onH) <= tol or math.abs(lv - onL) <= tol))
    c := c or math.abs(lv - math.round(lv / rstep) * rstep) <= tol
    c
 
// ── drawing (redrawn on the last bar only; cheap and never stale) ──
var array<line>  lns = array.new<line>()
var array<label> lbs = array.new<label>()
f_clear() =>
    for l in lns
        line.delete(l)
    for b in lbs
        label.delete(b)
    array.clear(lns)
    array.clear(lbs)
 
string st = ln_style == "Solid" ? line.style_solid : line.style_dashed
 
f_level(float lv, string nm, color c, int w, int x1, string dstr, bool star, string sz) =>
    if not na(lv)
        line ln = line.new(x1, lv, bar_index + lbl_off, lv, color = c, width = star ? w + 1 : w, style = nm == "PIVOT" ? line.style_solid : st, extend = extend.none)
        string txt = (star ? "★ " : "") + nm + " " + dstr + " · " + str.tostring(lv, format.mintick)
        bool tl = tag_pos == "Line start (clear of panels)"
        label lb = label.new(tl ? x1 : bar_index + lbl_off, lv, txt, style = tl ? label.style_label_right : label.style_label_left, color = lbl_fill ? c : color.new(color.white, 100), textcolor = lbl_fill ? color.white : c, size = sz)
        array.push(lns, ln)
        array.push(lbs, lb)
 
var int day_start = na
if timeframe.change(src_tf)
    day_start := bar_index
 
// date shown on the tags: today's session, or the NEXT weekday when showing the next ladder
f_next_day(int t) =>
    int n = t + 86400000
    int dw = dayofweek(n, tz)
    dw == dayofweek.saturday ? n + 2 * 86400000 : dw == dayofweek.sunday ? n + 86400000 : n
 
if barstate.islast
    f_clear()
    int x1 = mkt_closed ? bar_index - 20 : math.max(nz(day_start, bar_index) - ext_left, bar_index - 4900)
    string d = mkt_closed ? str.format_time(f_next_day(dTC), "MMM d", tz) : str.format_time(time, "MMM d", tz)
    if show_r3
        f_level(R3, "R3", c_res, w_lvl, x1, d, f_conf(R3), lbl_size)
    f_level(R2, "R2", c_res, w_lvl, x1, d, f_conf(R2), lbl_size)
    f_level(R1, "R1", c_res, w_lvl, x1, d, f_conf(R1), lbl_size)
    f_level(P, "PIVOT", c_piv, w_piv, x1, d, f_conf(P), piv_size)
    f_level(S1, "S1", c_sup, w_lvl, x1, d, f_conf(S1), lbl_size)
    f_level(S2, "S2", c_sup, w_lvl, x1, d, f_conf(S2), lbl_size)
    if show_r3
        f_level(S3, "S3", c_sup, w_lvl, x1, d, f_conf(S3), lbl_size)
    if show_pdhl
        f_level(pH, "PDH", c_pd, w_pd, x1, d, false, lbl_size)
        f_level(pL, "PDL", c_pd, w_pd, x1, d, false, lbl_size)
    if show_on and not na(onH)
        f_level(onH, "ON-H", c_on, w_on, x1, d, false, lbl_size)
        f_level(onL, "ON-L", c_on, w_on, x1, d, false, lbl_size)
 
// ── alerts (dynamic alert(), one alert covers everything) ──
f_check(float lv, string nm) =>
    if not na(lv) and (not al_star or f_conf(lv))
        string t = syminfo.ticker + " " + nm + " " + str.tostring(lv, format.mintick)
        if al_cross and close > lv and close[1] <= lv
            alert("MBF LADDER ▲ closed ABOVE " + t, alert.freq_once_per_bar_close)
        if al_cross and close < lv and close[1] >= lv
            alert("MBF LADDER ▼ closed BELOW " + t, alert.freq_once_per_bar_close)
        if al_sweep and low < lv and close > lv and open > lv
            alert("MBF LADDER ✓ SWEEP & RECLAIM (bullish) of " + t + " — wick under, close back above. Check the 4-confirmation panel.", alert.freq_once_per_bar_close)
        if al_sweep and high > lv and close < lv and open < lv
            alert("MBF LADDER ✓ SWEEP & REJECT (bearish) of " + t + " — wick over, close back below. Check the 4-confirmation panel.", alert.freq_once_per_bar_close)
 
f_check(R3, "R3")
f_check(R2, "R2")
f_check(R1, "R1")
f_check(P, "PIVOT")
f_check(S1, "S1")
f_check(S2, "S2")
f_check(S3, "S3")
f_check(pH, "PDH")
f_check(pL, "PDL")
 
// data window values (handy for the morning check)
plot(P, "Pivot", display = display.data_window)
plot(R1, "R1", display = display.data_window)
plot(S1, "S1", display = display.data_window)

← 返回列表