
This strategy is a dual-filter trading system combining RSI (Relative Strength Index) and trend moving average. It operates on daily timeframes by integrating RSI overbought/oversold signals with long-term trend moving averages. The core innovation lies in adding a trend filter to traditional RSI trading signals to enhance accuracy and reliability.
The strategy is based on the following core components: 1. RSI indicator for identifying overbought/oversold areas, default period 14 2. Overbought level set at 70, oversold level at 30 3. 200-period simple moving average as trend filter 4. Buy condition: RSI crosses above oversold level with price above MA 5. Sell condition: RSI crosses below overbought level with price below MA The strategy automatically executes trades at each signal and can be configured with alerts.
This strategy builds a robust trading system by combining RSI and trend moving averages. The design is rational, with clear operational rules and good practicality. Through proper risk management and continuous optimization, this strategy has the potential to achieve stable returns in actual trading.
/*backtest
start: 2025-02-13 00:00:00
end: 2025-02-20 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Binance","currency":"DOGE_USDT"}]
*/
//@version=5
strategy("Leading Indicator Strategy – Daily Signals", overlay=true,
pyramiding=1, initial_capital=100000,
default_qty_type=strategy.percent_of_equity, default_qty_value=100)
/// **Inputs for Customization**
rsiLength = input.int(14, minval=1, title="RSI Period")
oversold = input.float(30.0, minval=1, maxval=50, title="Oversold Level")
overbought = input.float(70.0, minval=50, maxval=100, title="Overbought Level")
maLength = input.int(200, minval=1, title="Trend MA Period")
useTrendFilter = input.bool(true, title="Use Trend Filter (MA)",
tooltip="Require price above MA for buys and below MA for sells")
/// **Indicator Calculations**
rsiValue = ta.rsi(close, rsiLength) // RSI calculation
trendMA = ta.sma(close, maLength) // Long-term moving average
/// **Signal Conditions** (RSI crosses with optional trend filter)
buySignal = ta.crossover(rsiValue, oversold) // RSI crosses above oversold level
sellSignal = ta.crossunder(rsiValue, overbought) // RSI crosses below overbought level
bullCond = buySignal and (not useTrendFilter or close > trendMA) // final Buy condition
bearCond = sellSignal and (not useTrendFilter or close < trendMA) // final Sell condition
/// **Trade Execution** (entries and exits with alerts)
if bullCond
strategy.close("Short", alert_message="Buy Signal – Closing Short") // close short position if open
strategy.entry("Long", strategy.long, alert_message="Buy Signal – Enter Long") // go long
if bearCond
strategy.close("Long", alert_message="Sell Signal – Closing Long") // close long position if open
strategy.entry("Short", strategy.short, alert_message="Sell Signal – Enter Short") // go short
/// **Plotting** (MA and signal markers for clarity)
plot(trendMA, color=color.orange, linewidth=2, title="Trend MA")
plotshape(bullCond, title="Buy Signal", style=shape.labelup, location=location.belowbar,
color=color.green, text="BUY", textcolor=color.white)
plotshape(bearCond, title="Sell Signal", style=shape.labeldown, location=location.abovebar,
color=color.red, text="SELL", textcolor=color.white)
// (Optional) Plot RSI in a separate pane for reference:
// plot(rsiValue, title="RSI", color=color.blue)
// hline(oversold, title="Oversold", color=color.gray, linestyle=hline.style_dotted)
// hline(overbought, title="Overbought", color=color.gray, linestyle=hline.style_dotted)