OPEN-SOURCE SCRIPT
Updated Xer0's Dual Engine Ladder Allocator

Overview
This indicator is designed for long-term investors using a "Dual Engine" portfolio strategy on M1 Finance — mixing a broad-market index fund with a leveraged counterpart in the same Pie. Instead of guessing when to buy the dip, this script provides a systematic, step-by-step roadmap for increasing your leveraged allocation as the market falls, and resetting it as the market recovers.
How It Works
The strategy is built on "Sticky All-Time High" logic. It tracks the highest close price and calculates the current drawdown from that peak, then responds with one of three scenarios:
Ladder Down (Risk On): For every defined drop step (e.g. every -5%), the indicator signals a RISK UP event — automatically calculating your new target allocation to the leveraged slice of your Pie. This forces systematic, disciplined buying at lower prices.
Recovery Reset (Risk Off): Once the market recovers by a set percentage from the bottom, the script signals a RESET — returning your allocation to the base level and locking in the gains from the dip-buying phase.
Bull Step: When the market pushes into new high territory, the script tracks each new leg up and keeps your reference point current.
Key Features
Sticky ATH Tracking: Automatically calculates true drawdown from the cycle peak
Customizable Ladder Steps: Define your own drop trigger percentage and leverage increase per step
Max Cap: Hard ceiling on leverage exposure to protect against catastrophic drawdowns
Bar Confirmation: All signals fire on daily close to avoid intraday false triggers
Visual Dashboard: Bottom-right table showing current mode, target leverage, drawdown, and recovery price target
Alert Conditions: Built-in RISK UP and RESET alerts compatible with TradingView's "Once Per Bar Close" setting
Backtested Performance (Simulated — Read Carefully)
The following results are from a Python backtest covering approximately 30 years (1996–2026), using $923/week in contributions every Friday. The strategy used two M1 Pies: Pie 1 (S&P 500 index fund / 3× S&P 500 ETF, base leverage 35%) and Pie 2 (Nasdaq-100 index fund / 3× Nasdaq-100 ETF, base leverage 25%). Tax assumptions reflect California state + federal rates for a $47K–$100K income bracket. Data prior to 2010 is synthetic, modeled from underlying index returns.
Results are hypothetical and do not represent actual trading. Past performance does not guarantee future results.
Ladder Strategy | VOO Benchmark
Total Contributed $1,395,576 | $1,395,576
Final Value (after-tax) $25,286,879 | $9,025,443
Total Return 1,711.9% | 546.7%
CAGR (on contributions) 10.1% | 6.4%
Max Drawdown -91.8% | -50.5%
Taxes Paid (CA) $5,358,907 | N/A (buy & hold)
Cash After Full Liquidation $23,500,189 | $7,171,385
The ladder strategy produced approximately 227.7% more after-tax cash than buy-and-hold VOO after full liquidation. However, the strategy experienced a maximum drawdown of -91.8% — meaning at its worst point, the portfolio lost nearly all of its value on paper. This level of volatility is not suitable for most investors and requires strong conviction and a long time horizon to hold through.
How to Use
Add this indicator to a Daily (1D) chart of your chosen index. Configure the inputs to match your risk tolerance — Base Leverage %, Drop Step %, and Max Cap %. Enter your M1 Pie name in the input field so alerts reference it by name. Set alerts using "Once Per Bar Close" and adjust your Pie allocation whenever a signal fires.
Disclaimer
This script is for informational and educational purposes only. It does not constitute financial advice. Backtested results are simulated and hypothetical — they do not account for all real-world frictions and should not be interpreted as a guarantee of future performance. Trading leveraged instruments involves significant risk, including the potential loss of your entire investment, and is not suitable for all investors.
This indicator is designed for long-term investors using a "Dual Engine" portfolio strategy on M1 Finance — mixing a broad-market index fund with a leveraged counterpart in the same Pie. Instead of guessing when to buy the dip, this script provides a systematic, step-by-step roadmap for increasing your leveraged allocation as the market falls, and resetting it as the market recovers.
How It Works
The strategy is built on "Sticky All-Time High" logic. It tracks the highest close price and calculates the current drawdown from that peak, then responds with one of three scenarios:
Ladder Down (Risk On): For every defined drop step (e.g. every -5%), the indicator signals a RISK UP event — automatically calculating your new target allocation to the leveraged slice of your Pie. This forces systematic, disciplined buying at lower prices.
Recovery Reset (Risk Off): Once the market recovers by a set percentage from the bottom, the script signals a RESET — returning your allocation to the base level and locking in the gains from the dip-buying phase.
Bull Step: When the market pushes into new high territory, the script tracks each new leg up and keeps your reference point current.
Key Features
Sticky ATH Tracking: Automatically calculates true drawdown from the cycle peak
Customizable Ladder Steps: Define your own drop trigger percentage and leverage increase per step
Max Cap: Hard ceiling on leverage exposure to protect against catastrophic drawdowns
Bar Confirmation: All signals fire on daily close to avoid intraday false triggers
Visual Dashboard: Bottom-right table showing current mode, target leverage, drawdown, and recovery price target
Alert Conditions: Built-in RISK UP and RESET alerts compatible with TradingView's "Once Per Bar Close" setting
Backtested Performance (Simulated — Read Carefully)
The following results are from a Python backtest covering approximately 30 years (1996–2026), using $923/week in contributions every Friday. The strategy used two M1 Pies: Pie 1 (S&P 500 index fund / 3× S&P 500 ETF, base leverage 35%) and Pie 2 (Nasdaq-100 index fund / 3× Nasdaq-100 ETF, base leverage 25%). Tax assumptions reflect California state + federal rates for a $47K–$100K income bracket. Data prior to 2010 is synthetic, modeled from underlying index returns.
Results are hypothetical and do not represent actual trading. Past performance does not guarantee future results.
Ladder Strategy | VOO Benchmark
Total Contributed $1,395,576 | $1,395,576
Final Value (after-tax) $25,286,879 | $9,025,443
Total Return 1,711.9% | 546.7%
CAGR (on contributions) 10.1% | 6.4%
Max Drawdown -91.8% | -50.5%
Taxes Paid (CA) $5,358,907 | N/A (buy & hold)
Cash After Full Liquidation $23,500,189 | $7,171,385
The ladder strategy produced approximately 227.7% more after-tax cash than buy-and-hold VOO after full liquidation. However, the strategy experienced a maximum drawdown of -91.8% — meaning at its worst point, the portfolio lost nearly all of its value on paper. This level of volatility is not suitable for most investors and requires strong conviction and a long time horizon to hold through.
How to Use
Add this indicator to a Daily (1D) chart of your chosen index. Configure the inputs to match your risk tolerance — Base Leverage %, Drop Step %, and Max Cap %. Enter your M1 Pie name in the input field so alerts reference it by name. Set alerts using "Once Per Bar Close" and adjust your Pie allocation whenever a signal fires.
Disclaimer
This script is for informational and educational purposes only. It does not constitute financial advice. Backtested results are simulated and hypothetical — they do not account for all real-world frictions and should not be interpreted as a guarantee of future performance. Trading leveraged instruments involves significant risk, including the potential loss of your entire investment, and is not suitable for all investors.
Release Notes
The max leverage cap has been raised from 80% to 90%, based on Monte Carlo simulation results showing an 83% win rate over the original parameters. The contribution split has also been updated to 40% SPX Pie / 60% NDX Pie, which showed a 72% win rate over the previous 50/50 split with a significant improvement in median after-tax outcome over 30 years.Release Notes
Looking at your actual v2 code, the biggest things I caught that needed updating in the research doc:Things v2 already had right (kept in v3):
40/60 split (you already had this)
+5% increment per step (kept — exhaustive testing confirmed flat wins)
5% recovery trigger (similar concept to R5)
5% bull step concept (refined into B4)
Things v3 changes:
Max cap: 90% → 80% — counterintuitive but data-backed; deep drawdowns sit for 2.6 years and 90% TQQQ bleeds decay during that time
Drop steps: every -5% → Fibonacci [-5, -8, -13, -21, -34, -55%] — matches real market correction patterns
Recovery anchor: trough+5% → ATH+5% — prevents premature reset on dead-cat bounces (bigger change than it sounds)
Bull step: ambiguous → explicit B4 rule with NDX-internal rebal — this is the single biggest performance contributor (+50% median alone)
NEW: DRIFT10 cross-pie — only fires when NDX > 70% of total, ~3 events per 30y vs ~41 if you cross-pie at every bull event
Performance delta vs your v2:
Median: $13.06M → $19.96M (+53%)
P10 downside: $4.84M → $7.62M (+57%)
P99 right tail: $65.67M → $134.73M (+105%)
CAGR: 7.63% → 9.16% (+1.53pp)
Release Notes
Release Notes — Dual Engine v4This version adds a new rule to the strategy and rebuilds the backtest with more accurate data and contribution logic.
What's new — REV-DRIFT46:
The original DRIFT10 rule fires when NDX outperforms so heavily it drifts above 70% of the total portfolio. v4 adds the symmetric counterpart: if the SPX pie ever drifts above 46% of the total portfolio — meaning NDX has significantly underperformed — rebalance back to 40/60. Tested all thresholds from 41% to 50% in 1% increments. 46% was selected as the conservative pick: fires roughly once per decade, catches the 2008 scenario that tighter thresholds miss, and produces the same terminal value as less conservative options with fewer disruptions. Like DRIFT10, this is a manual check in M1 since Pine Script cannot track cross-pie ratios. Historical fire dates: 1998, 2005, 2012, 2019.
What changed in the backtest:
Previous validation used Monte Carlo simulations with stylized index statistics. This update rebuilds the backtest using 30 years of synthetic daily returns derived directly from real ^NDX and ^GSPC price data, with TQQQ and UPRO constructed as 3x daily index returns minus actual expense ratio drag. Contribution logic was also corrected to match how M1 Finance actually handles deposits — rather than splitting every contribution 40/60, the model checks each pie's current value against its target weight before each deposit and routes money toward the underweight pie, exactly as M1's smart deposit system works.
Simulation parameters: $0 starting balance, $1,000/week, 30-year period (1994–2024), total contributed ~$1,559,000.
Optimal base leverage (pending next reset):
A 64-combination grid search across SPX base (20–55%) and NDX base (20–55%) scored each combination equally on CAGR, Sharpe, Calmar ratio, and max drawdown control. Optimal balance point: SPX 55% UPRO / NDX 40% TQQQ. Will be implemented on the next drawdown reset — script retains 35%/25% until then.
Performance vs prior versions ($0 start, $1,000/week, ~30 years, $1.56M contributed):
Version | End Value | Gain on Contributions | vs QQQ
v2 original ~$13.1M ~740% 1.0x
v3 (Fibonacci + B4 + DRIFT10) $19.96M* — ~1.5x
v3 revised — current base (35%/25%) $39.0M +2,403% 3.0x
v4 — optimal base (55%/40%) $53.0M +3,300% 4.0x
100%QQQ benchmark $13.1M +740% 1.0x
60/40 QQQ+VOO benchmark $11.0M +606% 0.8x
*v3 original from Monte Carlo median, different simulation parameters
The corrected M1 contribution logic, REV-DRIFT46, and weekly DCA together drive the jump from prior reported figures. The pending base leverage update adds a further ~$14M in terminal value on the same contributions, pushing the total improvement to 4x QQQ.
Release Notes
Base starting leverage were increased for both PiesQQQ/TQQQ: 55/45
VOO/UPRO: 45/55
Release Notes
Clarity with step up tagsRelease Notes
Release Notes — Dual Engine v5v5 adds the biggest risk control the strategy was missing — a trend-based cash gate — and rebuilds the backtest with leverage financing cost included, which materially changes the honest return picture. Everything from v4 (the Fibonacci ladder, R5 reset, B4 bull step, DRIFT10 / REV-DRIFT46 cross-pie rules, M1 smart-deposit logic) is unchanged and still runs underneath.
1) New — 50/200 Dual-Cross Cash Gate (the headline addition)
An always-on trend filter sits on top of the ladder. When the 50-day MA crosses below the 200-day MA, the pie flags RISK-OFF and moves entirely to cash (your broker's settlement cash — no T-bills or bond fund needed). When the 50 reclaims the 200, it flags RISK-ON and redeploys per the ladder. It trades ~once a year. This is what protects the leveraged sleeve through sustained bears — the one thing v1–v4 never had.
2) Changed — backtest now includes leverage financing cost
Prior versions modeled the 3× ETFs as 3× index − expense ratio only. Leveraged ETFs also pay financing on their ~2× borrowed notional (via the swaps that create the leverage) — ~0%/yr in zero-rate eras but ~9%/yr at today's 4% rates, averaging ~5.4%/yr. This is separate from the expense ratio and was previously omitted. Validated against the real fund: over 2022–2024 the financing-adjusted synthetic matched actual TQQQ (+33%), while the old expense-ratio-only model overstated it nearly 2× (+67%). Including it lowers synthetic TQQQ's 30-yr CAGR from ~14.8% to ~8.8% and roughly halves prior reported terminal values. This is why the figures below are lower than earlier releases — they're the corrected, realistic numbers.
3) Changed — RISK-OFF is plain cash (not T-bills)
Keeps it dead simple: sell to cash, nothing to buy. (Parking in T-bills/SGOV instead would recover ~+1.2pp/yr, but plain cash still beats both no-gate and QQQ.)
4) UI — redesigned status table
Cleaner, sectioned panel: a single green/red RISK-ON / RISK-OFF banner, a plain-English "Do now" action line, grouped ALLOCATION and MARKET sections, a muted palette, and a configurable position. Replaces the old 13-row rainbow layout.
Performance — Cash Gate vs No Gate (real ^NDX/^GSPC 1995–2025, $70k start + $2k/mo, base 55/40, financing-adjusted, RISK-OFF in plain cash, money-weighted IRR):
No Gate (v4) + Cash Gate (v5) 100% QQQ
Final value $15.0M $44.9M $10.5M
IRR 14.8% 19.7% 13.2%
Max drawdown −97% −58% −80%
Trades/yr — ~1 0
Monte Carlo — how the gate shifts the distribution (400 paths, randomized crash timing, base 65/70, cash-only):
No Gate median + Gate median QQQ median Gate win-rate vs QQQ
Trending market $7.9M $14.1M $10.2M 63%
Choppy market $7.7M $6.8M $10.5M 39%
The gate's drawdown protection is unconditional (−58% vs −97% in every regime). The return edge is conditional — it beats QQQ ~63% of the time when markets trend, but in choppy/mean-reverting markets a plain index fund wins.
Also tested and rejected (so you don't have to):
Rate-conditional gate (turn it off when rates are low) → worse (−90% drawdowns; 2008 and 2020 were low-rate crashes). The gate stays always on.
Rate-scaled leverage → no improvement over a fixed base; it just under-invested high-rate bull markets.
Single 200-DMA + band → the 50/200 dual-cross beat it on every metric with fewer whipsaws.
Honest risk notes:
Expect ~60–70% drawdowns even with the gate, ~−85% in the tail.
Edge is conditional on trend persistence; ~5–11% of simulated 30-yr paths still end below total contributions.
Earlier "$28M / −78.7% DD" headline figures were too optimistic (no financing cost, stylized data). These are the corrected numbers.
Size the leveraged sleeve as money you can afford to see cut ~60%, in a tax-advantaged account, with a broad index fund as your core.
Base leverage remains your risk dial: 55/40 for the calmer profile above, up to 65/70 for the max-wealth tilt.
Release Notes
Reverted back to v4 — removed the 50/200 cash gate.On paper it backtested better (lower drawdown, higher risk-adjusted return), but in practice it threw too many false signals to move to cash — pullbacks inside an ongoing uptrend that whipsawed into selling low and buying back higher. A risk rule only works if you'll actually follow it in real time, and I didn't trust this one enough to execute it consistently. Better to run a clean strategy I'll stick with than a "better on paper" one I'll second-guess at the worst moment.
Back to the core v4 engine: Fibonacci drawdown ladder, R5 reset, B4 bull step, and the DRIFT10 / REV-DRIFT46 cross-pie rules. No changes to that logic.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.