OPEN-SOURCE SCRIPT
Updated Leveraged ETF Strategy Tester

A comprehensive backtesting tool for comparing three distinct leveraged ETF investment strategies with customizable parameters, visual indicators, and risk metrics.
Features:
Strategy 1: Stars (Lee Ekholm)
A rebalancing strategy that maintains a conservative 20% TQQQ / 80% SPY base allocation with an automatic risk-on mechanism during severe drawdowns.
How it works:
Strategy 2: BD Collins 80/20 DCA
A four-tier dollar-cost averaging strategy that deploys cash more aggressively as drawdowns deepen, automatically buying more during corrections.
How it works:
Strategy 3: Henrique Centieiro's Strategy (1/3 Cash)
A simplified three-tier approach with clear escalating deployment levels based on drawdown severity.
How it works:
Color-Coded Buy Signals:
Strategy 1: Aqua (normal) | Orange (40% trigger active)
Strategy 2: Green (20%) | Yellow (40%) | Orange (60%) | Red (80%)
Strategy 3: Green (20-33%) | Orange (67%) | Red (100%)
Note: This indicator is for educational and backtesting purposes. Past performance does not guarantee future results. Leveraged ETFs carry significant risk and may not be suitable for all investors.
Features:
- Test three proven strategies side-by-side
- Fully customizable parameters via settings
- Visual buy signals color-coded by deployment tier
- ATH tracking and drawdown bands
- Monthly contribution support
- Sharpe and Sortino ratios for risk assessment
- Separate tables for statistics and strategy descriptions
Strategy 1: Stars (Lee Ekholm)
A rebalancing strategy that maintains a conservative 20% TQQQ / 80% SPY base allocation with an automatic risk-on mechanism during severe drawdowns.
How it works:
- Annual rebalancing at 20/80 allocation
- When TQQQ drops 40%+, shifts to 40% TQQQ at next rebalance
- Skips rebalancing for 1 year after market bottoms
- Resets to base allocation after TQQQ recovers to new ATH
- Monthly contributions accumulate and deploy during rebalances
- Best for: Long-term investors seeking systematic exposure increase during crashes
Strategy 2: BD Collins 80/20 DCA
A four-tier dollar-cost averaging strategy that deploys cash more aggressively as drawdowns deepen, automatically buying more during corrections.
How it works:
- Accumulates monthly contributions as cash reserves
- Deploys at quarterly intervals (customizable)
- 4 deployment tiers based on drawdown from ATH:
- 0-15%: Deploy 20% of cash
- 15-25%: Deploy 40% of cash
- 25-35%: Deploy 60% of cash
- 35%+: Deploy 80% of cash
- Best for: Investors wanting automated "buy the dip" behavior with increasing aggression
Strategy 3: Henrique Centieiro's Strategy (1/3 Cash)
A simplified three-tier approach with clear escalating deployment levels based on drawdown severity.
How it works:
- Baseline: 20% deployment near ATH
- 20% drop: 33% deployment (1/3)
- 40% drop: 67% deployment (2/3)
- 60% drop: 100% deployment (full cash)
- Monthly contributions accumulate and deploy at chosen cadence
- Best for: Investors preferring a simpler, more aggressive deployment schedule with clear trigger points
Color-Coded Buy Signals:
Strategy 1: Aqua (normal) | Orange (40% trigger active)
Strategy 2: Green (20%) | Yellow (40%) | Orange (60%) | Red (80%)
Strategy 3: Green (20-33%) | Orange (67%) | Red (100%)
Note: This indicator is for educational and backtesting purposes. Past performance does not guarantee future results. Leveraged ETFs carry significant risk and may not be suitable for all investors.
Release Notes
Release Notes - Strategy 4: BD Collins 14-week SMANew Strategy added:
Strategy 4: BD Collins 14-week SMA (Advanced)
Weekly trend-following strategy based on the 14-week Simple Moving Average with trailing stop loss protection.
Key Features:
Non-repainting signals: Uses confirmed weekly data to avoid look-ahead bias
Entry rules:
- Enters TQQQ at Monday open when:
- Weekly close is ABOVE the 14-week SMA
- Weekly candle is green (close > open)
Exit rules:
- Exits TQQQ at Monday open when weekly close drops below trailing stop threshold
- Trailing stop: 40% drop from highest point since entry (customizable)
- Violent break exception: If weekly close falls >10% below exit threshold, exits at Friday close instead of waiting for Monday
Cash asset allocation: Holds a cash alternative (VDST, SGOV, BIL, SHV) when out of TQQQ
Monthly contributions: Automatically invests contributions in current position (TQQQ or cash asset)
Full backtest metrics: Win rate, number of trades, max drawdown tracking
Visual Indicators:
- Purple line: 14-week SMA
- Green line: Trailing high (when in position)
- Red line: Exit threshold (when in position)
- Background color: Green (in TQQQ) / Red (in cash)
- Green triangle: Buy signal (Monday open)
- Red triangle: Sell signal (Monday open or Friday close)
Customizable Parameters:
- SMA length (default: 14 weeks)
- Exit drawdown % (default: 40%)
- Cash asset ticker (default: VDST)
- Violent-break exception toggle
- Violent-break margin % (default: 10%)
Statistics Display:
- Current position (IN TQQQ or IN [cash ticker])
- Total trades with win rate percentage
- Standard metrics: portfolio value, total return, Sharpe ratio, Sortino ratio
Release Notes
All fixes are working correctly:✅ Exit logic reordering - Checks exit condition BEFORE updating trailing high (lines 459-499, then 502-504)
✅ Cash price fallback - Uses $1.00 default when VDST data unavailable (lines 476, 514)
✅ Pine Script syntax - Sequential if statements instead of problematic ternary (lines 471-479)
Release Notes
Strategy 4 v2.0 Release Notes🎯 Overview
Major update adding extensive configurability and alignment with BD Collins' published rules. Strategy 4 is now a flexible testing framework rather than a fixed implementation.
✨ New Features (5 Parameters)
1. Exit Trigger - Choose detection method:
Intraweek touch (book) - exits when weekly LOW touches threshold
Weekly close below (original) - exits only on close below threshold
2. Trailing Peak Source - Choose what to track:
Weekly high/wick (book) - full volatility capture
Weekly close - smoother behavior
3. Start Invested - Control initial position:
OFF (default) - wait for first signal
ON (original) - invested from bar 0
4. Require Green Candle - Toggle entry condition:
OFF (default) - only above SMA needed
ON (original) - requires green candle + above SMA
5. Transaction Costs - Model realistic costs:
Default: 0.10% per leg (0.20% round-trip)
Configurable 0% to 5%
🐛 Critical Fixes
Trailing Peak Timing: Now updates BEFORE exit check (was after), ensuring threshold reflects current week's data. Provides more responsive exits.
Cash Pricing: Eliminated $1.00 fallback. Now tracks cash as ticker shares OR USD with gap warnings displayed in stats table.
🔄 Breaking Changes
New Defaults:
Start Invested: OFF (was always ON)
Green Candle: OFF (was always ON)
Exit Trigger: Intraweek touch (was close only)
To restore v1.x behavior: Enable Start Invested + Require Green Candle, select "Weekly close below (original)"
🎯 Quick Start Configs
Book-Accurate (recommended):
Exit: Intraweek touch | Peak: Weekly high
Start: OFF | Green: OFF | VB: OFF | Cost: 0.10%
Conservative:
Exit: Weekly close | Peak: Weekly close
Start: OFF | Green: ON | VB: OFF | Cost: 0.20%
Aggressive:
Exit: Intraweek touch | Peak: Weekly high
Start: ON | Green: OFF | VB: ON | Cost: 0.05%
📊 Enhanced Stats
Row 11: Shows active mode config + cash gap warnings
Position: Now distinguishes IN TQQQ / IN VDST / IN CASH
Descriptions: Dynamic text reflects your actual settings
⚠️ Known Issues
Some cash tickers (VDST, SGOV) have limited historical data before 2022
Consider SHV or BIL for longer backtests
📈 Performance Impact
Transaction costs: 0.10% per leg ≈ 2-5% total return reduction over 15 years
Intraweek touch: Exits 1-3 days earlier in crashes (5-15% less drawdown)
Weekly close: More stable, fewer whipsaws
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.
Hedge Fund Manager at Maverick Capital | Wealth Educator | 20+ yrs investing | Stocks, ETFs & Crypto alerts | Join Henrique Wealth Academy for trade alerts & indicators → skool.com/be-limitless/
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.
Hedge Fund Manager at Maverick Capital | Wealth Educator | 20+ yrs investing | Stocks, ETFs & Crypto alerts | Join Henrique Wealth Academy for trade alerts & indicators → skool.com/be-limitless/
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.