This strategy is a trend-following system based on four Exponential Moving Averages (EMAs), using the crossovers and alignments of 9, 21, 50, and 200-period EMAs to identify market trends, combined with percentage-based stop-loss for risk control. The strategy determines market trend direction by checking the alignment order of four moving averages, entering long positions when shorter-period EMAs are above longer-period EMAs, and vice versa for short positions, while implementing a fixed percentage stop-loss for risk management.
The strategy employs four EMAs with different periods (9, 21, 50, 200) to assess market trends. A buy signal is generated when the 9-day EMA is above the 21-day EMA, which is above the 50-day EMA, which in turn is above the 200-day EMA, indicating a strong uptrend. Conversely, the opposite alignment generates sell signals. A 2% stop-loss is implemented to control maximum loss per trade.
This is a comprehensive trend-following trading system that provides reliable trend identification through multiple EMAs while implementing fixed percentage stop-loss for risk control. Although the system has some inherent lag, it can be further enhanced through proper parameter optimization and additional indicator integration. The strategy is particularly suitable for highly volatile markets and medium to long-term trend-following trading.
/*backtest start: 2019-12-23 08:00:00 end: 2024-11-23 08:00:00 period: 1d basePeriod: 1d exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("4 EMA Strategy with Stop Loss", overlay=true) // Define the EMA lengths ema1_length = input(9, title="EMA 1 Length") ema2_length = input(21, title="EMA 2 Length") ema3_length = input(50, title="EMA 3 Length") ema4_length = input(200, title="EMA 4 Length") // Calculate the EMAs ema1 = ta.ema(close, ema1_length) ema2 = ta.ema(close, ema2_length) ema3 = ta.ema(close, ema3_length) ema4 = ta.ema(close, ema4_length) // Plot EMAs on the chart plot(ema1, color=color.blue, title="EMA 9") plot(ema2, color=color.orange, title="EMA 21") plot(ema3, color=color.green, title="EMA 50") plot(ema4, color=color.red, title="EMA 200") // Define conditions for Buy and Sell signals buy_condition = (ema1 > ema2 and ema2 > ema3 and ema3 > ema4) sell_condition = (ema1 < ema2 and ema2 < ema3 and ema3 < ema4) // Input stop loss percentage stop_loss_perc = input(2.0, title="Stop Loss %") // Execute buy signal if (buy_condition) strategy.entry("Buy", strategy.long) // Set stop loss at a percentage below the entry price strategy.exit("Sell", "Buy", stop=strategy.position_avg_price * (1 - stop_loss_perc / 100)) // Execute sell signal if (sell_condition) strategy.entry("Sell", strategy.short) // Set stop loss at a percentage above the entry price strategy.exit("Cover", "Sell", stop=strategy.position_avg_price * (1 + stop_loss_perc / 100))