OPEN-SOURCE SCRIPT

Magnet Compass Phase 3

340
MAGNET COMPASS
An intraday scalping system for NQ, ES, and GC futures, designed for a 30-second chart. It identifies 15-minute "magnet" candles at key session times — moments when one extreme of the candle has a measurable empirical bias to get tagged within the next 15 minutes — and arms trades only when live conditions agree with that bias.
═══════════════════════════════
THE IDEA IN ONE LINE
At each 15-minute close in a known magnet bucket, the indicator checks whether live features (close location, VWAP side, HTF trend) agree with the historical first-hit bias for that bucket. If they agree and the close sits in the mid-band of its range, it arms a trade toward the bias-side extreme.
═══════════════════════════════
WHY TWO LAYERS (PRIOR + LIVE)
The historical bias alone gives a 5–19 percentage-point edge on which extreme gets tagged first — real, but too small to trade on. A live-feature filter that vetoes the days when current conditions argue the other way is what turns the prior into a tradable setup.
From the underlying feature analysis:

Close location only matters in the middle of the range. At the extremes it's geometric noise ("close at the high → high gets hit trivially").
VWAP side and the bucket prior carry the real signal. HTF EMA trend is near-noise but kept as a tiebreaker.

So an entry fires only when: armed bucket + prior agrees with live score + close in mid-band + |score| ≥ 2.
═══════════════════════════════
SYMBOL COVERAGE
Auto-detects from chart symbol — no input changes needed.

NQ1! — 16 buckets (London 03:45, RTH 09:30–14:00, Asia 20:00–21:15)
ES1! — 19 buckets (London 03:00–04:00, RTH 09:30–14:00, Asia 20:00–21:15)
GC1! — 12 buckets (RTH 09:30–15:00, no London/Asia)

All times ET.
═══════════════════════════════
HOW TO READ THE CHART
Every 15 minutes an info label appears on the magnet candle:
Bkt 11:30 AM ARM ↑HIGH
Prior HIGH +19.3 | clLoc 0.42 | vwap +1 | htf +1 | score +4

Bkt — the 15-minute close time
ARM / SKIP — armed direction, or skip reason
Prior — bias side and signed edge (percentage points)
clLoc — close location in the candle (0 = low, 1 = high). Tradable band is 0.30–0.70.
vwap / htf — feature scores (−1, 0, or +1, signed toward HIGH-first)
score — sum of features. Need |score| ≥ 2 and same sign as prior to arm.

Lines drawn at each armed window:

Aqua solid — magnet high and low (anchored to the actual bars that made the extremes)
Gray dashed — midline (50% of magnet range)
On entry: yellow entry, lime target, red stop
WIN / LOSS labels at exit

The execution window is background-shaded only when the system armed for that bucket.
═══════════════════════════════
ARM CONDITIONS
All must hold at the confirmed 15-minute close:

Bucket has a non-zero prior
Prior and live features agree (same sign)
clLoc is between 0.30 and 0.70
|live score| ≥ 2
If "NY only" mode is on, bucket falls between 09:30 and 15:45 ET

═══════════════════════════════
ENTRY AND EXIT
Entry fires on the first confirmed 30-second bar after the 15-minute close (~30 seconds after). Skipped if that bar already wicks the bias-side extreme.
Stop styles (5 options):

Opposite extreme (default) — widest stops, ≈1:1 R:R, highest win-rate
Midline — half the loss size, but more stop-outs
Fixed ticks — entry ± N ticks
ATR — k × 15-minute ATR
Nearest unswept swing — closest swing past entry that hasn't been violated since forming; falls back to opposite extreme if none available

Target: bias-side magnet extreme by default, or midline (toggle).
Window close: if the trade is still open at the next 15-minute close, it's classified by the last 30-second close vs entry. Past entry = WIN, otherwise LOSS. Ties count as LOSS.
═══════════════════════════════
SCALP MODE (SETUP A — SWEEP FADE)
Optional toggle that flips the model for fade-style scalps. Instead of trading toward the bias-side magnet, it fades it: bias HIGH → resting SHORT limit at magnet high + buffer, targeting the midline. Fixed point-based stops/targets (default 12/12). Optional half-off at 1R, breakeven shift, and runner scale.
Backed by an extended-stat finding that the midpoint mean-reverts ~79% of the time after the magnet candle.
═══════════════════════════════
NON-REPAINTING
Uses request.security with [1] and lookahead_on — the canonical non-repainting pattern for HTF data. All state changes are gated to barstate.isconfirmed. Signals are identical in historical and real-time/replay.
Trade-off: entries fire on the first confirmed 30-second bar after the 15-minute close (~30s later) rather than instantly.
═══════════════════════════════
CUSTOMIZATION

Every visible element has its own color picker (magnet lines, midline, entry/stop/target, ARM/SKIP backgrounds, label text, table colors).
Both tables — live stats and reference bucket list — have 8-position placement dropdowns.
Toggles for every visual: lines, info labels, WIN/LOSS labels, window shading, both tables.

═══════════════════════════════
HONEST CAVEATS

This is a win-rate-dependent system with ~1:1 R:R, not a payoff-dependent one. A small drop in win-rate kills the edge.
The leaderboard priors are snapshots from a specific data window. They need periodic refresh as more data accumulates.
Window-close reclassification slightly understates loss magnitude when the exit lands near entry (fees and slippage not modeled).
Forward-test on sim until you've logged 50+ resolved trades. Small samples don't tell you much.

═══════════════════════════════
DISCLAIMER
For educational and research purposes only. Not financial advice. Past performance of any backtested setup does not guarantee future results. Trade your own account.

Wyłączenie odpowiedzialności

Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.