This is a trend-following strategy that combines moving average crossovers with the Relative Strength Index (RSI). The strategy determines market trend direction through short-term and long-term moving average crossovers, while using RSI as a momentum filter to confirm trend strength, thereby improving the reliability of trading signals. The strategy also incorporates percentage-based stop-loss and take-profit for risk management.
The strategy employs 9-period and 21-period Simple Moving Averages (SMA) as primary trend indicators. Long signals are generated when the short-term MA crosses above the long-term MA and RSI is above 50, while short signals occur when the short-term MA crosses below the long-term MA and RSI is below 50. This design ensures trade direction aligns with both market trend and momentum. The system controls risk-reward ratio through 1% stop-loss and 2% take-profit levels.
This is a well-structured trend-following strategy with clear logic. It provides basic trend direction through MA crossovers, momentum confirmation through RSI, combined with risk management mechanisms to form a complete trading system. While it has some inherent limitations, through continuous optimization and adjustment, the strategy has the potential to maintain stable performance across different market environments. The key to success lies in parameter optimization and risk control execution.
/*backtest start: 2019-12-23 08:00:00 end: 2024-12-10 08:00:00 period: 1d basePeriod: 1d exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Moving Average Crossover + RSI Strategy", overlay=true, shorttitle="MA RSI Strategy") // --- Input Parameters --- shortMA = input.int(9, title="Short MA Period", minval=1) longMA = input.int(21, title="Long MA Period", minval=1) rsiLength = input.int(14, title="RSI Length", minval=1) rsiOverbought = input.int(70, title="RSI Overbought Level", minval=50, maxval=100) rsiOversold = input.int(30, title="RSI Oversold Level", minval=0, maxval=50) stopLossPercent = input.float(1, title="Stop Loss Percentage", minval=0.1, maxval=10.0) / 100 takeProfitPercent = input.float(2, title="Take Profit Percentage", minval=0.1, maxval=10.0) / 100 // --- Calculate Moving Averages --- shortMA_value = ta.sma(close, shortMA) longMA_value = ta.sma(close, longMA) // --- Calculate RSI --- rsi_value = ta.rsi(close, rsiLength) // --- Buy and Sell Conditions --- longCondition = ta.crossover(shortMA_value, longMA_value) and rsi_value > 50 shortCondition = ta.crossunder(shortMA_value, longMA_value) and rsi_value < 50 // --- Plot Moving Averages --- plot(shortMA_value, color=color.blue, linewidth=2, title="Short MA") plot(longMA_value, color=color.red, linewidth=2, title="Long MA") // --- Plot RSI (Optional) --- hline(rsiOverbought, "Overbought", color=color.red) hline(rsiOversold, "Oversold", color=color.green) plot(rsi_value, color=color.purple, title="RSI") // --- Strategy Execution --- if (longCondition) strategy.entry("Long", strategy.long) if (shortCondition) strategy.entry("Short", strategy.short) // --- Risk Management (Stop Loss and Take Profit) --- longStopLoss = close * (1 - stopLossPercent) longTakeProfit = close * (1 + takeProfitPercent) shortStopLoss = close * (1 + stopLossPercent) shortTakeProfit = close * (1 - takeProfitPercent) // Set the stop loss and take profit for long and short positions strategy.exit("Long Exit", from_entry="Long", stop=longStopLoss, limit=longTakeProfit) strategy.exit("Short Exit", from_entry="Short", stop=shortStopLoss, limit=shortTakeProfit)