
This strategy is a quantitative trading system that combines the Moving Average Convergence Divergence (MACD) and Relative Strength Index (RSI) indicators. The strategy identifies market trend reversal points by analyzing the crossover signals of these two technical indicators and overbought/oversold levels to make trading decisions. The system executes trades programmatically, automatically capturing market opportunities.
The core logic is based on two main technical indicators: MACD and RSI. The MACD indicator calculates the difference between fast (12-period) and slow (26-period) moving averages, comparing it with a signal line (9-period moving average) to determine trend direction. The RSI indicator calculates the relative strength over 14 periods to determine if the market is overbought or oversold.
Buy signals are generated when the MACD line crosses above the signal line and RSI is below 70 (overbought level). Sell signals are generated when the MACD line crosses below the signal line and RSI is above 30 (oversold level). This dual confirmation mechanism effectively filters out false signals.
The MACD-RSI Dynamic Crossover Quantitative Trading System is an automated trading strategy combining classic technical analysis indicators. Through the dual mechanism of MACD trend judgment and RSI overbought/oversold confirmation, it effectively captures market turning points. The strategy offers high reliability and strong adaptability, but traders must be mindful of choppy market and signal lag risks. There is significant room for improvement through the introduction of additional technical indicators and signal confirmation optimization. In practical application, investors should adjust parameters based on specific market conditions and combine with other analysis methods.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-03 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("MACD + RSI Strategy", overlay=true)
// MACD settings
fastLength = input.int(12, title="MACD Fast Length")
slowLength = input.int(26, title="MACD Slow Length")
signalSmoothing = input.int(9, title="MACD Signal Smoothing")
// RSI settings
rsiLength = input.int(14, title="RSI Length")
rsiOverbought = input.float(70, title="RSI Overbought Level")
rsiOversold = input.float(30, title="RSI Oversold Level")
// Calculate MACD
[macdLine, signalLine, _] = ta.macd(close, fastLength, slowLength, signalSmoothing)
// Calculate RSI
rsi = ta.rsi(close, rsiLength)
// Generate buy and sell signals
buySignal = ta.crossover(macdLine, signalLine) and rsi < rsiOverbought
sellSignal = ta.crossunder(macdLine, signalLine) and rsi > rsiOversold
// Plot buy and sell signals on chart
plotshape(series=buySignal, location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=sellSignal, location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
// Strategy entry and exit
if buySignal
strategy.entry("Buy", strategy.long)
if sellSignal
strategy.close("Buy")
// Plot MACD and Signal Line
plot(macdLine, color=color.blue, title="MACD Line")
plot(signalLine, color=color.orange, title="Signal Line")
// Plot RSI
hline(rsiOverbought, "Overbought", color=color.red)
hline(rsiOversold, "Oversold", color=color.green)
plot(rsi, color=color.purple, title="RSI")