MASU+ v12 Conformal Edge — Strategy by Mark_Novak
By Mark_Novak
Performance Metrics
- Author: Mark_Novak
- Symbol: OANDA:XAGUSD
- Timeframe: 1 hour
- Net P&L: +45,917.24 USD (+4.59%)
- Win Rate: 78.9%
- Profit Factor: 1.237
- Max Drawdown: 26,998.58 USD (2.53%)
- Total Trades: 351
Description
█ **Overview****MASU+ v12 Conformal Edge** is a multi-layer trend strategy that combines a confluence-based entry engine with a statistical exit framework built on adaptive Kalman filtering and online conformal prediction. The strategy targets liquid US equities and major crypto pairs on the 1H timeframe.What sets v12 apart is the **exit logic**. Most Pine strategies rely on fixed ATR multiples or trailing stops alone. v12 adds a third dimension: a continuously calibrated 90% prediction band around an adaptive Kalman estimate of the next bar's close. When price breaks outside this band and then returns inside, the strategy interprets it as exhaustion of the move and closes the position — capturing profits that a wider trailing stop would give back, while a hard ATR trail still protects runaway trends.The strategy publishes long and short signals, draws the Kalman trajectory and conformal band on the chart, and manages exits through a layered priority: hard stop loss → ATR trailing → conformal mean-reversion → take profit ceiling.A curated list of symbols selected for their historical performance under this strategy is published separately on our website (see signature).█ **How It Works**The strategy is built from six independent components. Entries fire only when all entry-side components agree; exits use the layered priority described above.▸ **MTF Ribbon Entry Confluence**Trend direction is established by an EMA ribbon on the primary timeframe and confirmed by a higher timeframe filter using strict anti-repaint syntax (`request.security` with `[1]` offset and `lookahead_off`). The ribbon must be aligned, the higher timeframe must agree, ADX must exceed the configured threshold, and a volume spike condition must be present.-----------------------------------------------------------------------------------------------------------------mtf_filter_long = request.security(syminfo.tickerid, mtf_tf, close[1] > ema_filter[1], lookahead = barmerge.lookahead_off)ribbon_bullish = ema_fast > ema_slow and ema_slow > ema_filteradx_ok = adx > adx_thresholdvolume_spike = volume > ta.sma(volume, 20) * volume_mult-----------------------------------------------------------------------------------------------------------------This block defines *whether* the market is in a tradeable trend regime. It does not, on its own, fire entries.▸ **Smart Money Concepts (SMC) Triggers**On top of the trend filter, entries require a structural trigger: order block reaction, fair value gap fill, or a confirmed break of structure. All SMC patterns reference closed bars (`close[1]`, `open[1]`) so they cannot repaint.-----------------------------------------------------------------------------------------------------------------ob_bullish_trigger = close[1] > ob_high[1] and close > ob_highfvg_fill_long = low = fvg_bottombos_up = close > prev_swing_high and barstate.isconfirmedbullish_trigger = ob_bullish_trigger or fvg_fill_long or bos_up-----------------------------------------------------------------------------------------------------------------A trade is taken only when the trend filter, the ribbon, the higher timeframe, ADX, the volume gate, the session filter, and at least one SMC trigger all align on the same confirmed bar.▸ **Adaptive Kalman Filter**A 1D Kalman filter tracks `close`, with adaptive process noise Q that grows when residuals are elevated (chop) and shrinks when residuals are small (clean trends). The prediction for bar *i* is computed from `state[i-1]` and published *before* `close` is observed — meaning the filter's output is causally available at the open of each bar.-----------------------------------------------------------------------------------------------------------------x_pred = k_state // prediction from previous state onlychop_factor = math.min(1.0, residSqEMA / scale_squared)Q = q_base * (1.0 + chop_mult * chop_factor)P_pred = k_P + Qk_pred := x_pred // PUBLISHED — used by exit logic// Update step (consumes close, affects pred[i+1] only)resid = close - x_predK = P_pred / (P_pred + R)k_state := x_pred + K * residk_P := (1.0 - K) * P_pred-----------------------------------------------------------------------------------------------------------------The Kalman line on the chart is the strategy's "fair value" estimate — what price *should* be doing if the recent dynamics persist.▸ **Online Adaptive Conformal Inference (ACI)**The Kalman line alone is a point estimate. To convert it into an actionable interval, the strategy maintains a rolling 100-bar buffer of absolute residuals `|close − k_pred|` and publishes a 90% prediction band:-----------------------------------------------------------------------------------------------------------------q_level = 1.0 - aci_alpha // currently 0.90q_val = array.percentile_linear_interpolation(cal_buf, q_level * 100)k_upper := k_pred + q_valk_lower := k_pred - q_val-----------------------------------------------------------------------------------------------------------------// ACI alpha update — keeps coverage calibrated under regime shiftserr_t = math.abs(close - k_pred) > q_val ? 1.0 : 0.0aci_alpha := aci_alpha + gamma * (alpha_target - err_t)The buffer's residual quantile is fed back through Adaptive Conformal Inference: if recent realized residuals exceeded the band more often than the target rate, alpha shrinks (band widens) on the next bar. The result is a **distribution-free** band that self-calibrates without assuming Gaussianity, fat tails, or any specific volatility model.▸ **Conformal Mean-Reversion Exit**This is the strategy's signature exit. Two state flags — `was_outside_upper` and `was_outside_lower` — track whether price has confirmedly broken outside the band since the position was opened. If a long position is open AND price has been outside the upper band AND the current close has returned inside it AND we are above entry price, the position is closed.-----------------------------------------------------------------------------------------------------------------if barstate.isconfirmed and high > k_upper was_outside_upper := trueconformal_exit_long = use_conformal_exit and was_outside_upper and close entry_priceif conformal_exit_long strategy.close("L", comment = "ConformalExit")------------------------------------------------------------------------------------------------------------------The flags are reset on each new entry, eliminating spurious one-bar exits when an entry signal happens to fire while price is already inside the band.▸ **Risk Module**Risk is layered. A hard ATR-based stop loss is set at entry. A trailing stop arms only after price moves the configured ATR distance in favor of the position; once armed, it follows the peak with a tight ATR offset. A take profit acts as a final ceiling. Trail offsets are converted to integer ticks (`math.round(distance / syminfo.mintick)`) so the engine's order semantics match what gets placed at the broker level.The conformal exit, when enabled, takes priority over the trail and TP — but never over the hard SL. Capital is always protected first.█ **How to Use**▸ **Reading entries**A green triangle below the bar marks a long entry, a red triangle above marks a short. Entries fire only on `barstate.isconfirmed`, so the marker appears at the next bar's open, never mid-bar. If you see no entries for an extended period, the confluence filter is doing its job — it is designed to skip ranging conditions.▸ **Reading the Kalman + Conformal band**The yellow line is the Kalman estimate. The two aqua lines above and below are the conformal band.- **Narrow band** → recent price action is well-explained by the filter; market is in a clean regime- **Wide band** → residuals are large; the filter is in chop adaptation mode- **Price outside band** → unusual move; the position management module starts watching for returnThe band is informational on its own — even outside an active trade, it gives context on whether current price action is "expected" or "extreme" by recent history.▸ **Reading exits**Three exit types appear on the chart with distinct comment tags:- `ConformalExit` — the v12 mean-reversion logic fired- `X-L` / `X-S` filled at the trail level — runaway trend reversed past the trail offset- `X-L` / `X-S` filled at the SL level — hard stop hit; the catastrophic caseIf most of your exits in the strategy tester come back as `ConformalExit`, the band logic is working as intended on the symbol. If most come back as trail or SL, the symbol's volatility profile may not match the band's calibration — either tune the calibration window or move on to a different symbol.▸ **Combining the signals**The strongest setups are when an entry fires *and* the Kalman line is sloping clearly in the trade direction *and* price has just broken structure (BOS or OB reaction). When the entry fires but the Kalman is flat, the trade is more likely to exit by conformal mean-reversion at modest profit rather than ride a trend. Both outcomes are fine — they are encoded in the exit logic — but knowing which you are looking at helps with position sizing.█ **Settings**- **Stop Loss ATR Multiplier** – Hard stop distance in ATR units. Wider values reduce noise-outs on the breakout side; tighter values cap downside per trade. Default is tuned for asymmetric R:R.- **Take Profit ATR Multiplier** – Ceiling on a single trade. Conformal exit usually fires first; this protects the rare cases where the band remains breached.- **Trail Activate ATR** – How far in profit before the trail engages. Lower values lock in earlier; higher values let trends breathe.- **Trailing ATR Multiplier** – Gap from peak to trail. Tight (under 1.0) maximises capture on confirmed trends; wide values reduce premature exits in volatile markets.- **Use Conformal Mean-Reversion Exit** – Master switch for the v12 exit. Disable to A/B test against a pure ATR-trail baseline.- **Kalman Process Noise Q (base)** – Filter responsiveness floor. Higher = filter tracks price closer; lower = filter smoother. Adaptive scaling sits on top of this.- **Kalman Q Chop Multiplier** – How aggressively Q grows under elevated residuals. Higher = filter loosens faster in chop; lower = filter stays tight regardless.- **Conformal Calibration Window** – Number of past bars of residuals used to compute the band. 100 is standard. Shorter windows react faster to regime change at the cost of noise.- **Conformal Alpha Target** – Target miscoverage rate. 0.10 = 90% coverage band. Lower values widen the band.- **ACI Learning Rate** – How fast alpha self-corrects when realized coverage drifts. Higher = faster recalibration; lower = more stable but slower to adapt.- **Plot Kalman + Conformal Band** – Cosmetic toggle. Disable for a cleaner chart in screenshots; the underlying logic still runs.█ **Notes on robustness**The Kalman + Conformal block is **leakage-audited**: predictions and band edges at bar *i* are functions of `close[1..i-1]` only. The current bar's close enters only the *update* step, which influences `pred[i+1]` and the next bar's band — never the current entry/exit decision.The full anti-repaint contract from the underlying MASU Ultimate framework is preserved: `calc_on_every_tick = false`, `process_orders_on_close = true`, all entry/exit conditions gated on `barstate.isconfirmed`, MTF requests use `[1]` inside `request.security` with `lookahead = barmerge.lookahead_off`, SMC patterns reference closed bars only, trail offsets are integer ticks. Validation details and a curated symbol list are maintained on our website.█ **Disclaimer**This script is published for educational and research purposes only. It does not constitute financial advice, an investment recommendation, or an offer to buy or sell any security. Past performance shown by the built-in strategy tester is not indicative of future results. Trading carries significant risk of loss; always test on a paper account, manage position size carefully, and consult a qualified professional before risking real capital.