A Simple Long-Only ES Strategy: Combining RSI and SMA [Free Code]
- FutAlgo
- Dec 22, 2024
- 2 min read
INTRODUCTION
In complex world of futures trading, elegantly simple strategies often prove their worth through consistent performance. Today, we're introducing a straightforward long-only strategy for the E-mini S&P 500 futures (ES) that combines two popular technical indicators: the Relative Strength Index (RSI) and Simple Moving Average (SMA). The strategy aims to capture upward momentum in trending markets while managing risk through systematic entry and exit rules.
STRATEGY CONCEPT
The core idea behind this strategy is to identify potential buying opportunities when the market is in an overall uptrend (using the 200 SMA) but experiencing a short-term pullback (indicated by a low RSI reading). This approach effectively combines trend-following with mean reversion principles.
KEY COMPONENTS
Trend Filter:
200-period Simple Moving Average
Ensures we only take long positions when price is above the long-term trend
Acts as a primary filter to stay aligned with the market's overall direction
Entry Timing:
Short-term RSI period of 4 captures quick market pullbacks
Entry threshold of 40 identifies oversold conditions in an uptrend
Helps time entries during temporary price weakness
Holding Period:
8 sessions
PERFORMANCE ANALYTICS
Overall stats:
Total Net Profit: $208K
Win Rate: 64.68% (163 winning out of 252 trades)
Profit Factor: 2.01
Total Trades: 252
Maximum Drawdown: $17K
Equity Curve

Annual Results

CODE IMPLEMENTATION
Open your TradeStation account and set up a new chart with the following:
@ES.D for a symbol
Daily bars
Select the start date (e.g., 01/01/2000)
Apply the strategy script:
// =================================================
// Simple RSI & SMA-Based Long-Only Strategy For ES
// =================================================
// ---- Inputs ----
Inputs:
RSI_Length(4), // Period for the RSI calculation
SMA_Length(200), // Period for the Simple Moving Average
RSI_Threshold(40), // RSI threshold for entry
Bars_Out(8); // Number of bars to hold the position
// ---- Variables ----
Vars:
rsiValue(0),
smaValue(0);
// ---- Indicator Calculations ----
rsiValue = RSI(Close, RSI_Length);
smaValue = Average(Close, SMA_Length);
// ---- Long Entry Condition ----
// Buy next bar at market if Close is above the SMA and RSI is below the threshold
If (Close > smaValue) and (rsiValue < RSI_Threshold) then
Buy ("Go Long") next bar at market;
// ---- Long Exit Condition ----
// Exit the long position after Bars_Out bars
If BarsSinceEntry(0) = Bars_Out then
Sell ("Exit Long") next bar at market;
Comments