本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// ─────────────────────────────────────────────────────────────────────────────
// DRYFIRE SCANNER V7.7 — SCORED, LOOSE GATES
//
// Setup: a stock that made a sharp recent leg (the EP), is now CONTRACTING
// against that leg's own range - either holding near the highs or pulled back
// to a moving average - on drying volume.
//
// Entry (next session, handled in the morning workflow, NOT here):
// open above today's CLOSE, no large gap, must not breach today's LOW,
// enter on a break of today's HIGH.
//
// Gates are deliberately loose - a missed setup costs more than an admitted
// one, because the top names get a visual review. The SCORE does the ranking.
// ─────────────────────────────────────────────────────────────────────────────
indicator("DRYFIRE Scanner V7.7", overlay=true, max_bars_back=500)
// ── Hard gates (loose by design) ─────────────────────────────────────────────
high52_tol = input.float(20.0, "Max % Below 52W High", group="Hard Gates")
leg_look = input.int(60, "Leg Search Lookback (bars)", group="Hard Gates")
leg_min = input.float(25.0, "Min Leg Gain %", group="Hard Gates")
min_run_req= input.int(2, "Min narrow-bar run to qualify", group="Hard Gates")
pos_min = input.float(40.0, "Min Position in Box %", group="Hard Gates")
box_max = input.float(10.0, "Max Box Height %", group="Hard Gates")
req_pdl = input.bool(true, "Reject if close below prior bar low", group="Hard Gates")
use_dry_gate=input.bool(true, "Require volume dry-up", group="Hard Gates")
dry_gate_max=input.float(1.2, "Max coil volume vs 50d avg", group="Hard Gates")
use_stop_via=input.bool(true, "Require stop to be viable vs ADR", group="Hard Gates")
stop_adr_min=input.float(0.7, "Min stop width as x ADR20", group="Hard Gates")
// ── Structure ────────────────────────────────────────────────────────────────
ma_type = input.string("EMA", "MA Type", options=["EMA","WMA","SMA"], group="Structure")
ma_f_len = input.int(9, "MA fast", group="Structure")
ma_m_len = input.int(21, "MA mid", group="Structure")
ma_s_len = input.int(50, "MA slow", group="Structure")
// ── Compression ──────────────────────────────────────────────────────────────
comp_look = input.int(4, "Box Window (bars)", group="Compression")
run_look = input.int(12, "Compression Search Window", group="Compression")
ref_len = input.int(50, "Reference Range Lookback", group="Compression")
narrow_x = input.float(0.85, "Narrow if Range% <= Ref% x", group="Compression")
narrow_abs= input.float(2.5, "Also narrow if Range% <=", group="Compression")
today_narrow_min = input.int(2, "Min narrow bars ending TODAY to fire", group="Compression")
// ── Scoring windows ──────────────────────────────────────────────────────────
vert_look = input.int(30, "Vertical Gain Window 1", group="Scoring")
vert_look2= input.int(60, "Vertical Gain Window 2", group="Scoring")
vol_ma_len= input.int(50, "Volume MA Length", group="Scoring")
age_full = input.float(10.0, "Coil age: full marks up to N bars", group="Scoring")
age_zero = input.float(18.0, "Coil age: zero marks at N bars", group="Scoring")
ma_full = input.float(3.0, "MA support: full marks within %", group="Scoring")
ma_zero = input.float(12.0, "MA support: zero marks at %", group="Scoring")
rs_full = input.float(15.0, "RS: full marks at %", group="Scoring")
contr_full= input.float(0.35, "Contraction: full marks at ratio", group="Scoring")
contr_zero= input.float(1.00, "Contraction: zero marks at ratio", group="Scoring")
// ── Penalties ────────────────────────────────────────────────────────────────
stale_runs = input.int(3, "Stale: coils in last 20 bars", group="Penalties")
stale_chg = input.float(5.0, "Stale: 20-bar gain below this %", group="Penalties")
stale_pen = input.float(15.0,"Stale penalty points", group="Penalties")
deep_start = input.float(10.0,"Deep pullback penalty starts at %", group="Penalties")
deep_zero = input.float(20.0,"Deep pullback full penalty at %", group="Penalties")
deep_bars = input.int(15, "Deep penalty only if leg high within N bars", group="Penalties")
deep_pen = input.float(12.0,"Deep pullback penalty points", group="Penalties")
// ── Score display ────────────────────────────────────────────────────────────
pass_floor = input.float(40.0, "Raw floor to qualify (=1/10)", group="Score")
raw_top = input.float(85.0, "Raw treated as 10/10", group="Score")
label_min = input.float(6.0, "Min score to fire", group="Score")
sl_pct = input.float(2.5, "Stop Loss % below entry", group="Entry")
trail_max = input.int(10, "Stop drawing levels after N bars", group="Entry")
// ── Tags ─────────────────────────────────────────────────────────────────────
bench_sym = input.symbol("NSE:NIFTYMIDSML400", "Benchmark", group="Tags")
rs_look = input.int(22, "RS Lookback (bars)", group="Tags")
hist_look = input.int(250, "Character Lookback (bars)", group="Character")
ma_resp_look = input.int(100, "MA Respect Lookback (bars)", group="Character")
bounce_look = input.int(250, "Bounce Lookback (bars)", group="Character")
bounce_fwd = input.int(5, "Bars forward to judge a bounce", group="Character")
bounce_tol = input.float(0.5,"Touch tolerance (% of MA)", group="Character")
rev_look = input.int(140, "Reversal history window (bars, ~6-7mo)", group="Reversal Watch")
rev_min = input.int(2, "Min successful 50-MA reversals in window", group="Reversal Watch")
rev_near = input.float(3.0,"Count as at-the-50 within %", group="Reversal Watch")
// ═════════════════════════════════════════════════════════════════════════════
// MEASUREMENTS
// ═════════════════════════════════════════════════════════════════════════════
ma_f = ma_type == "EMA" ? ta.ema(close, ma_f_len) : ma_type == "WMA" ? ta.wma(close, ma_f_len) : ta.sma(close, ma_f_len)
ma_m = ma_type == "EMA" ? ta.ema(close, ma_m_len) : ma_type == "WMA" ? ta.wma(close, ma_m_len) : ta.sma(close, ma_m_len)
ma_s = ma_type == "EMA" ? ta.ema(close, ma_s_len) : ma_type == "WMA" ? ta.wma(close, ma_s_len) : ta.sma(close, ma_s_len)
stack_aligned = ma_f > ma_m and ma_m > ma_s and close > ma_s
high52 = ta.highest(high, 252)
below_52wh = high52 > 0 ? ((high52 - close) / high52) * 100 : na
// ── Leg: lowest low in lookback, then highest high after it ──────────────────
lo_val = low
lo_idx = 0
for i = 0 to leg_look - 1
if low[i] < lo_val
lo_val := low[i]
lo_idx := i
hi_val = high
hi_idx = 0
for i = 0 to leg_look - 1
if i <= lo_idx and high[i] > hi_val
hi_val := high[i]
hi_idx := i
leg_gain = lo_val > 0 ? ((hi_val - lo_val) / lo_val) * 100 : 0.0
base_bars = hi_idx
pullback_depth = hi_val > 0 ? ((hi_val - close) / hi_val) * 100 : na
// ── EP bar: widest-range bar WITHIN this leg (from the leg low forward) ──────
// This is the reference the coil must contract against. A 50-bar average range
// measures the stock's personality; the EP bar measures the move being digested.
ep_rng = 0.0
ep_hi = high
ep_lo = low
for i = 0 to leg_look - 1
if i <= lo_idx and ((high[i] - low[i]) / close[i] * 100) > ep_rng
ep_rng := (high[i] - low[i]) / close[i] * 100
ep_hi := high[i]
ep_lo := low[i]
// ── Narrowness: percent-based, long reference, loose by design ───────────────
bar_range = high - low
rng_pct = (bar_range / close) * 100
ref_pct = ta.sma(rng_pct, ref_len)
adr10 = ta.sma(rng_pct, 10)
adr20 = ta.sma(rng_pct, 20)
narrow_flag = (rng_pct <= ref_pct * narrow_x) or (rng_pct <= narrow_abs)
// Longest narrow run anywhere in the search window
best_run = 0
cur_run = 0
for i = 0 to run_look - 1
if narrow_flag[i]
cur_run += 1
if cur_run > best_run
best_run := cur_run
else
cur_run := 0
// Consecutive narrow bars ending TODAY - this is what fires a signal
cons_narrow = 0
run_broken = false
for i = 0 to 24
if not run_broken
if narrow_flag[i]
cons_narrow += 1
else
run_broken := true
// ── Boxes ────────────────────────────────────────────────────────────────────
box_hi = ta.highest(high, comp_look)
box_lo = ta.lowest(low, comp_look)
box_pct = box_lo > 0 ? ((box_hi - box_lo) / box_lo) * 100 : na
box_pos = (box_hi - box_lo) > 0 ? ((close - box_lo) / (box_hi - box_lo)) * 100 : 100.0
// Two-bar box: one up day and one down day of 2.5% each is a TIGHT structure;
// two 2.5% days in the same direction is a 5% move. Per-bar range cannot tell
// them apart, the two-bar box can.
box2_hi = math.max(high, high[1])
box2_lo = math.min(low, low[1])
box2_pct = close > 0 ? ((box2_hi - box2_lo) / close) * 100 : na
// ── Contraction against the EP bar ───────────────────────────────────────────
contraction = ep_rng > 0 ? box2_pct / ep_rng : na
contained = high <= ep_hi and low >= ep_lo and high[1] <= ep_hi and low[1] >= ep_lo
// ── Vertical gain, both windows kept separate ───────────────────────────────
// Low-then-high search, same method as the leg detection above. The previous
// version compared ta.highestbars against ta.lowestbars, which reads 0 whenever
// a window's ABSOLUTE high happens to precede its absolute low - even when a
// perfectly good recent upleg exists inside the window (SUPRIYA read 0 on both
// windows despite a 26% leg five bars back). Searching low first, then the
// highest high after it, always yields a valid upleg.
vlo1 = low
vli1 = 0
for i = 0 to vert_look - 1
if low[i] < vlo1
vlo1 := low[i]
vli1 := i
vhi1 = high
for i = 0 to vert_look - 1
if i <= vli1 and high[i] > vhi1
vhi1 := high[i]
vg1 = vlo1 > 0 ? ((vhi1 - vlo1) / vlo1) * 100 : 0.0
vlo2 = low
vli2 = 0
for i = 0 to vert_look2 - 1
if low[i] < vlo2
vlo2 := low[i]
vli2 := i
vhi2 = high
for i = 0 to vert_look2 - 1
if i <= vli2 and high[i] > vhi2
vhi2 := high[i]
vg2 = vlo2 > 0 ? ((vhi2 - vlo2) / vlo2) * 100 : 0.0
vert_gain = math.max(vg1, vg2)
// ── Volume dry-up ────────────────────────────────────────────────────────────
vol_ma = ta.sma(volume, vol_ma_len)
vol_dry = vol_ma > 0 ? ta.sma(volume, comp_look) / vol_ma : na
// ── MA support: distance, plus undercut-and-reclaim ─────────────────────────
big = 1000000.0
ds_f = close >= ma_f ? ((close - ma_f) / ma_f) * 100 : big
ds_m = close >= ma_m ? ((close - ma_m) / ma_m) * 100 : big
ds_s = close >= ma_s ? ((close - ma_s) / ma_s) * 100 : big
dist_sup = math.min(ds_f, math.min(ds_m, ds_s))
ma_sup = dist_sup == ds_f ? ma_f_len : dist_sup == ds_m ? ma_m_len : dist_sup == ds_s ? ma_s_len : 0
// Undercut = low pierced the MA, close recovered above it. Tested separately
// from close-vs-MA, so a wick through support reads differently from a bar
// that never went near it. Scores as full support credit, never a requirement.
und_f = low < ma_f and close > ma_f
und_m = low < ma_m and close > ma_m
und_s = low < ma_s and close > ma_s
und_any = und_f or und_m or und_s
// ── Staleness: repeated coils that go nowhere ───────────────────────────────
// Not repeat firing that is bad - repeat firing WITHOUT the move.
run_start = narrow_flag and not narrow_flag[1]
runs20 = 0
for i = 0 to 19
if run_start[i]
runs20 += 1
chg20 = close[20] > 0 ? ((close - close[20]) / close[20]) * 100 : 0.0
// Point-to-point return, NOT trough-to-peak. Leg Gain measures low-to-high, so
// a stock that fell 20% then recovered 28% off the low shows a 28% "leg" while
// being roughly flat. These two columns together show which one you are holding.
chg60 = close[60] > 0 ? ((close - close[60]) / close[60]) * 100 : 0.0
// ── Entry / stop ─────────────────────────────────────────────────────────────
// Entry is TODAY'S HIGH, not the coil high: an earlier coil bar can sit higher
// and would enter late. Today's LOW is the pre-entry invalidation; the 2.5%
// stop is post-entry.
entry_px = high
sl_px = entry_px * (1.0 - sl_pct / 100.0)
invalid_px = low
pdl_dist = entry_px > 0 ? ((entry_px - invalid_px) / entry_px) * 100 : na
// ── RS ───────────────────────────────────────────────────────────────────────
bench_close = request.security(bench_sym, timeframe.period, close)
stock_ret = close[rs_look] > 0 ? (close - close[rs_look]) / close[rs_look] * 100 : na
bench_ret = bench_close[rs_look] > 0 ? (bench_close - bench_close[rs_look]) / bench_close[rs_look] * 100 : na
rs_outperf = stock_ret - bench_ret
// ═════════════════════════════════════════════════════════════════════════════
// HARD GATES
// ═════════════════════════════════════════════════════════════════════════════
g_stack = stack_aligned
g_52 = not na(below_52wh) and below_52wh <= high52_tol
g_leg = leg_gain >= leg_min
g_comp = best_run >= min_run_req
g_pos = box_pos >= pos_min
g_box = not na(box_pct) and box_pct <= box_max
g_pdl = not req_pdl or close >= low[1]
// Dry-up is the premise of the setup, not a nicety. 1.2 means coil volume 20%
// ABOVE the 50-day average, so this only cuts names with no dry-up at all.
g_dry = not use_dry_gate or (not na(vol_dry) and vol_dry <= dry_gate_max)
// The universe filter demands ATR>3%, so a flat 2.5% stop sits inside the daily
// range of every name in it. Rather than widening the stop in a falling market,
// skip the names the stop cannot be placed on.
stop_vs_adr = adr20 > 0 ? sl_pct / adr20 : na
g_stopvia = not use_stop_via or (not na(stop_vs_adr) and stop_vs_adr >= stop_adr_min)
gates_ok = g_stack and g_52 and g_leg and g_comp and g_pos and g_box and g_pdl and g_dry and g_stopvia
// ═════════════════════════════════════════════════════════════════════════════
// SCORE (components sum to 100, penalties subtract)
// ═════════════════════════════════════════════════════════════════════════════
sc_comp = math.min(math.max(best_run / 3.0, 0.0), 1.0) * 20.0
sc_contr = math.min(math.max((contr_zero - nz(contraction, contr_zero)) / math.max(contr_zero - contr_full, 0.01), 0.0), 1.0) * 15.0
// Curve endpoints follow the gate input: change the gate and the score follows,
// instead of silently scoring against a stale 1.2.
dry_span = math.max(dry_gate_max - 0.5, 0.01)
sc_dry = math.min(math.max((dry_gate_max - nz(vol_dry, dry_gate_max)) / dry_span, 0.0), 1.0) * 14.0
sc_pos = math.min(math.max((box_pos - pos_min) / math.max(95.0 - pos_min, 0.01), 0.0), 1.0) * 12.0
sc_ma = und_any ? 12.0 : math.min(math.max((ma_zero - dist_sup) / math.max(ma_zero - ma_full, 0.01), 0.0), 1.0) * 12.0
sc_rs = math.min(math.max(nz(rs_outperf, 0.0) / math.max(rs_full, 0.01), 0.0), 1.0) * 10.0
sc_box = math.min(math.max((box_max - nz(box_pct, 99.0)) / math.max(box_max - 3.0, 0.01), 0.0), 1.0) * 7.0
sc_age = math.min(math.max((age_zero - base_bars) / math.max(age_zero - age_full, 0.01), 0.0), 1.0) * 6.0
sc_vert = math.min(math.max((vert_gain - 15.0) / 25.0, 0.0), 1.0) * 4.0
// Penalty: coiled repeatedly and went nowhere
// Graded, not a cliff. The rest of the score has no hard steps in it; a binary
// -15 at exactly 3 coils / 5% reintroduced one, and it was firing on 8 of 18
// names. Scales with how far past each threshold the stock actually is.
stale_over = math.min(math.max((runs20 - stale_runs + 1) / 3.0, 0.0), 1.0)
stale_flat = math.min(math.max((stale_chg - chg20) / math.max(stale_chg, 0.01), 0.0), 1.0)
pen_stale = stale_over * stale_flat * stale_pen
// Penalty: gave the leg back, and did it recently. Deep AND recent is a failed
// breakout; deep but long ago is a stock that has since based.
deep_frac = math.min(math.max((nz(pullback_depth, 0.0) - deep_start) / math.max(deep_zero - deep_start, 0.01), 0.0), 1.0)
pen_deep = base_bars <= deep_bars ? deep_frac * deep_pen : 0.0
score_raw = math.max(sc_comp + sc_contr + sc_dry + sc_pos + sc_ma + sc_rs + sc_box + sc_age + sc_vert - pen_stale - pen_deep, 0.0)
qualifies = gates_ok and score_raw >= pass_floor
span = math.max(raw_top - pass_floor, 1.0)
score10 = qualifies ? math.min(1.0 + 9.0 * (score_raw - pass_floor) / span, 10.0) : 0.0
// Setup type: 1 = high flag (holding near the leg high), 2 = pullback to a MA
setup_type = qualifies ? (nz(pullback_depth, 99.0) <= 6.0 ? 1 : 2) : 0
// ═════════════════════════════════════════════════════════════════════════════
// SIGNAL
// ═════════════════════════════════════════════════════════════════════════════
// A signal requires the stock to be IN a coil today, not merely to have coiled
// somewhere recently. Without this it fires on the expansion bar after the
// coil, and the entry sits at the top of an already-extended move.
strong = score10 >= label_min and cons_narrow >= today_narrow_min
sig_bar = strong and not strong[1]
bars_since_sig = ta.barssince(sig_bar)
// ═════════════════════════════════════════════════════════════════════════════
// STOCK CHARACTER — is this a repeat performer or a one-off gate pass?
// ═════════════════════════════════════════════════════════════════════════════
// Every gate is already evaluated on every historical bar, so counting past
// occurrences is nearly free. A name with 6 prior signals has demonstrated this
// behaviour repeatedly; one with 1 is today's coincidence.
sig_hist = 0
for i = 0 to hist_look - 1
if sig_bar[i]
sig_hist += 1
qual_hist = 0
for i = 0 to hist_look - 1
if gates_ok[i]
qual_hist += 1
// "Look to the left" as a number: how much of the time does price actually hold
// above its mid MA. A name that glides reads high; a whippy one reads ~55%.
ma_resp_n = 0
for i = 0 to ma_resp_look - 1
if close[i] > ma_m[i]
ma_resp_n += 1
ma_respect = (ma_resp_n / ma_resp_look) * 100
// ── MA bounce rate: what actually HAPPENS after a touch ─────────────────────
// MA Respect counts bars closing above the MA - it never looks at what follows
// a touch. This does: of the distinct times price reached the fast MA, how
// often was the close higher N bars later. A stock that reliably turns at its
// MA reads high; one that slices through reads low.
// Three separate measures, because a graze of the fast MA and a pullback all the
// way to the slow MA are different events. The 21 and 50 bands are EXCLUSIVE:
// a touch of the 21 counts only if the low held above the 50, so a deep flush
// isn't double-counted as a shallow one.
t9 = low <= ma_f * (1 + bounce_tol / 100)
t21 = low <= ma_m * (1 + bounce_tol / 100) and low > ma_s
t50 = low <= ma_s * (1 + bounce_tol / 100)
f9 = t9 and not t9[1] // one count per pullback, not per bar
f21 = t21 and not t21[1]
f50 = t50 and not t50[1]
touch_n = 0
bounce_n = 0
t21_n = 0
b21_n = 0
t50_n = 0
b50_n = 0
for i = bounce_fwd to bounce_look - 1
if f9[i]
touch_n += 1
if close[i - bounce_fwd] > close[i]
bounce_n += 1
if f21[i]
t21_n += 1
if close[i - bounce_fwd] > close[i]
b21_n += 1
if f50[i]
t50_n += 1
if close[i - bounce_fwd] > close[i]
b50_n += 1
// Reversal watch - separate from DRYFIRE. Not a signal: no levels, no label,
// no gate. A name currently AT or UNDER the 50 that has turned there repeatedly
// over ~6-7 months. These are reversals, not coils, so DRYFIRE correctly gives
// them no score; this flag just surfaces them for a visual look.
rev_hits = 0
rev_seen = 0
for i = bounce_fwd to rev_look - 1
if f50[i]
rev_seen += 1
if close[i - bounce_fwd] > close[i]
rev_hits += 1
dist_ma50 = ((close - ma_s) / ma_s) * 100
at_ma50 = math.abs(dist_ma50) <= rev_near
under_ma50 = low <= ma_s and close > ma_s
rev_watch = (at_ma50 or under_ma50) and rev_hits >= rev_min
bounce_rate = touch_n > 0 ? (bounce_n / touch_n) * 100 : na
bounce_21 = t21_n > 0 ? (b21_n / t21_n) * 100 : na
bounce_50 = t50_n > 0 ? (b50_n / t50_n) * 100 : na
// ═════════════════════════════════════════════════════════════════════════════
// SCREENER OUTPUTS
// ═════════════════════════════════════════════════════════════════════════════
plot(score10, "DRYFIRE SCORE (1-10)", display=display.none)
plot(score_raw, "Raw Score (0-100)", display=display.none)
plot(sig_bar ? 1 : 0, "SIGNAL TODAY", display=display.none)
plot(bars_since_sig, "Bars Since Signal", display=display.none)
plot(setup_type, "Setup Type (1=flag 2=pb)",display=display.none)
plot(close, "Price", display=display.none)
plot(entry_px, "Entry (today high)", display=display.none)
plot(invalid_px, "Invalidation (today low)",display=display.none)
plot(sl_px, "Stop Loss", display=display.none)
plot(pdl_dist, "Low Distance %", display=display.none)
plot(-pen_stale, " pen: stale", display=display.none)
plot(-pen_deep, " pen: deep pullback", display=display.none)
plot(contraction, "Contraction vs EP", display=display.none)
plot(contained ? 1:0, "Inside EP Bar Range", display=display.none)
plot(box2_pct, "2-Bar Box %", display=display.none)
plot(box_pct, "Box Height %", display=display.none)
plot(box_pos, "Position in Box %", display=display.none)
plot(cons_narrow, "Narrow Run Ending Today", display=display.none)
plot(best_run, "Longest Narrow Run", display=display.none)
plot(rng_pct, "Candle Range %", display=display.none)
plot(ref_pct, "Ref Range %", display=display.none)
plot(adr10, "ADR % (10)", display=display.none)
plot(adr20, "ADR % (20)", display=display.none)
plot(vol_dry, "Volume Dry-up Ratio", display=display.none)
plot(dist_sup, "Dist to Nearest MA %", display=display.none)
plot(ma_sup, "Supporting MA", display=display.none)
plot(und_any ? 1:0, "Undercut + Reclaim", display=display.none)
plot(pullback_depth, "Pullback Depth %", display=display.none)
plot(base_bars, "Bars Since Leg High", display=display.none)
plot(leg_gain, "Leg Gain %", display=display.none)
plot(vg1, "Vertical Gain 30b %", display=display.none)
plot(runs20, "Coils in Last 20b", display=display.none)
plot(chg20, "20-Bar Change %", display=display.none)
plot(chg60, "60-Bar Change %", display=display.none)
plot(rs_outperf, "RS vs Benchmark %", display=display.none)
plot(below_52wh, "% Below 52W High", display=display.none)
plot(sig_hist, "Signals in last 250b", display=display.none)
plot(qual_hist, "Bars Qualifying 250b", display=display.none)
plot(ma_respect, "MA Respect %", display=display.none)
plot(bounce_rate, "MA9 Bounce Rate %", display=display.none)
plot(touch_n, "MA9 Touches 250b", display=display.none)
plot(bounce_21, "MA21 Bounce Rate %", display=display.none)
plot(t21_n, "MA21 Touches 250b", display=display.none)
plot(bounce_50, "MA50 Bounce Rate %", display=display.none)
plot(t50_n, "MA50 Touches 250b", display=display.none)
plot(rev_watch ? 1:0, "REVERSAL WATCH", display=display.none)
plot(rev_hits, "50MA Reversals (6mo)", display=display.none)
plot(rev_seen, "50MA Touches (6mo)", display=display.none)
plot(dist_ma50, "Dist to MA50 %", display=display.none)
plot(under_ma50 ? 1:0, "Undercut MA50 today", display=display.none)
plot(stop_vs_adr, "Stop / ADR20", display=display.none)
plot(g_stopvia ? 1:0, "GATE stop-viable", display=display.none)
plot(gates_ok ? 1:0, "Hard Gates OK", display=display.none)
plot(g_dry ? 1:0, "GATE dry-up", display=display.none)
// ═════════════════════════════════════════════════════════════════════════════
// VISUALS
// ═════════════════════════════════════════════════════════════════════════════
pf = plot(ma_f, color=color.green, linewidth=2, title="MA fast")
pm = plot(ma_m, color=color.blue, linewidth=2, title="MA mid")
plot(ma_s, color=color.orange, linewidth=1, title="MA slow")
fill(pf, pm, color=color.new(color.gray, 85), title="MA Cloud")
plotshape(sig_bar, title="Signal", style=shape.triangleup, location=location.belowbar,
color=color.new(color.blue, 0), size=size.tiny)
if sig_bar
label.new(bar_index, low * 0.98,
"DRYFIRE " + str.tostring(score10, "#.#") + "/10" +
"\nE " + str.tostring(entry_px, format.mintick) +
"\nSL " + str.tostring(sl_px, format.mintick) + " (" + str.tostring(sl_pct, "#.#") + "%)" +
"\nX " + str.tostring(invalid_px, format.mintick),
style=label.style_label_up, color=color.blue, textcolor=color.white, size=size.small)
// ── Entry / stop dot trail ──────────────────────────────────────────────────
var float lvl_entry = na
var float lvl_sl = na
var bool sig_live = false
var int sig_age = 0
if sig_bar
lvl_entry := entry_px
lvl_sl := sl_px
sig_live := true
sig_age := 0
else if sig_live
sig_age := sig_age + 1
// Void on a stop breach, OR simply expire. Checked from the bar AFTER the
// signal: on the signal bar the stop sits below that bar's own high, so a
// bar wider than the stop would void it at once. Expiry stops a signal from
// three weeks ago still drawing levels 19% below price.
if low < lvl_sl or sig_age > trail_max
sig_live := false
lvl_entry := na
lvl_sl := na
plot(sig_live ? lvl_entry : na, "Entry level", color=color.new(color.purple, 0),
style=plot.style_circles, linewidth=1)
plot(sig_live ? lvl_sl : na, "Stop level", color=color.new(color.red, 0),
style=plot.style_circles, linewidth=1)
plot(sig_live ? 1 : 0, "Signal Still Valid", display=display.none)