
This strategy is a trend-following trading system based on multiple technical indicators, combining three classic technical indicators: Exponential Moving Average (EMA), Moving Average Convergence Divergence (MACD), and Relative Strength Index (RSI). It captures market trend changes and momentum through parameter settings including fast EMA (9 periods) and slow EMA (21 periods), MACD (12,26,9), and RSI (14), generating trading signals at indicator crossovers and threshold breakthroughs.
The core logic of the strategy is to identify market trend turning points through the confirmation of multiple technical indicators. It includes three aspects of signal confirmation: 1. EMA Crossover Signal: A long signal is generated when the fast EMA crosses above the slow EMA, and a short signal when it crosses below. 2. MACD Crossover Signal: Long position confirmed when MACD line crosses above the signal line, short position when crossing below. 3. RSI Filter: Trades are allowed when RSI value is between 30-70, avoiding trades in excessive overbought/oversold areas. The strategy executes trades only when all three indicators show synchronized signals.
This strategy captures market trend changes through multiple technical indicator cross-validation, offering good reliability and adaptability. However, in practical application, attention should be paid to signal lag and over-trading issues. It is recommended to optimize through introducing adaptive parameters, stop-loss mechanisms, and market environment recognition to improve strategy stability and profitability. During implementation, it is advised to conduct thorough historical data backtesting and parameter optimization, continuously adjusting and improving based on actual trading results.
/*backtest
start: 2024-02-20 00:00:00
end: 2025-02-17 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA + MACD + RSI Strategy with Long and Short", overlay=true)
// Input parameters for MACD, EMA, and RSI
fast_ema_length = input.int(9, title="Fast EMA Length", minval=1)
slow_ema_length = input.int(21, title="Slow EMA Length", minval=1)
macd_short_length = input.int(12, title="MACD Short Length", minval=1)
macd_long_length = input.int(26, title="MACD Long Length", minval=1)
macd_signal_length = input.int(9, title="MACD Signal Length", minval=1)
rsi_length = input.int(14, title="RSI Length", minval=1)
rsi_oversold_level = input.int(30, title="RSI Oversold Level", minval=1)
rsi_overbought_level = input.int(70, title="RSI Overbought Level", minval=1)
// Calculate the MACD line and Signal line
[macdLine, signalLine, _] = ta.macd(close, macd_short_length, macd_long_length, macd_signal_length)
// Calculate the EMAs
fast_ema = ta.ema(close, fast_ema_length)
slow_ema = ta.ema(close, slow_ema_length)
// Calculate the RSI
rsi = ta.rsi(close, rsi_length)
// Conditions for long entry (bullish)
macd_bullish_crossover = ta.crossover(macdLine, signalLine) // MACD line crosses above Signal line
ema_bullish_crossover = ta.crossover(fast_ema, slow_ema) // Fast EMA crosses above Slow EMA
rsi_above_30 = rsi > rsi_oversold_level // RSI above 30 (not oversold)
long_condition = macd_bullish_crossover and ema_bullish_crossover and rsi_above_30
// Conditions for short entry (bearish)
macd_bearish_crossover = ta.crossunder(macdLine, signalLine) // MACD line crosses below Signal line
ema_bearish_crossover = ta.crossunder(fast_ema, slow_ema) // Fast EMA crosses below Slow EMA
rsi_below_70 = rsi < rsi_overbought_level // RSI below 70 (not overbought)
short_condition = macd_bearish_crossover and ema_bearish_crossover and rsi_below_70
// Execute long trade
if (long_condition)
strategy.entry("Long", strategy.long)
// Execute short trade
if (short_condition)
strategy.entry("Short", strategy.short)
// Plot the EMAs and MACD for visualization
plot(fast_ema, color=color.green, linewidth=2, title="Fast EMA")
plot(slow_ema, color=color.red, linewidth=2, title="Slow EMA")
plot(macdLine, color=color.blue, linewidth=2, title="MACD Line")
plot(signalLine, color=color.red, linewidth=2, title="Signal Line")
hline(30, "RSI 30", color=color.green)
hline(70, "RSI 70", color=color.red)
plot(rsi, color=color.purple, linewidth=2, title="RSI")