Hello everyone,
I’m relatively new and currently trying to build a simple relative strength model based on Levy for the Russell 1000 universe.
My goal is straightforward:
- Use a relative strength metric defined as Close / SMA(130)
- Apply a market filter using SPY with two moving averages to avoid major drawdowns
- Select the Top 10 stocks based on relative strength
- Use a Cast-Out Rank of 20%
- The Russell 1000 stocks are organized in a watchlist, which also includes SPY for the market filter
Unfortunately, I’m currently not getting any results in my backtest.
I’m sharing my code and settings (screenshots) and would really appreciate any help. Feel free to adjust or improve the code as needed.
Thanks in advance for your support!
// ============================================================
// Relative Strength System after Levy (Close / SMA130)
// Universe : Russell 1000 Watchlist (set in AA window)
// Entry : Top 10 stocks by Levy RS score
// Exit 1 : Cast-Out-Rank (rank drops below threshold)
// Exit 2 : Crisis filter - SPY SMA5 < SPY SMA200
// ============================================================
// --- Parameters ---
MaxPositions = 10;
CastOutPct = Optimize( "CastOutPct", 20, 5, 50, 5 );
LevyPeriod = 130;
// --- Levy Relative Strength ---
LevyRS = Close / MA( Close, LevyPeriod );
// --- Cross-sectional Ranking (Rank 1 = strongest) ---
StaticVarSet( "LevyRS_" + Name(), LevyRS );
StaticVarGenerateRanks( "rank_LevyRS_", "LevyRS_", 0, 1 );
CurrentRank = StaticVarGet( "rank_LevyRS_" + Name() );
CastOutThreshold = MaxPositions * ( 1 + CastOutPct / 100 );
// --- Crisis Filter: SPY SMA5 > SMA200 ---
SpyClose = Foreign( "SPY", "C" );
MarketOK = IIf( BarIndex() > 200, MA( SpyClose, 5 ) > MA( SpyClose, 200 ), 0 );
// --- Signals ---
Buy = CurrentRank <= MaxPositions AND MarketOK;
Sell = CurrentRank > CastOutThreshold OR NOT MarketOK;
Short = 0;
Cover = 0;
// --- Execution & Sizing ---
BuyPrice = Open;
SellPrice = Open;
PositionSize = -10;
PositionScore = LevyRS;
// --- Portfolio Settings ---
SetOption( "MaxOpenPositions", MaxPositions );
SetOption( "AllowPositionShrinking", True );






