
This strategy is an automated trading system based on multiple Exponential Moving Averages (EMAs), establishing trading signals through hierarchical analysis of 5-period, 20-period, and 50-period EMAs. The system’s unique design incorporates multiple EMAs based on high, low, and closing prices, combined with dynamic stop-loss and trailing profit mechanisms to effectively control risk while securing profits.
The strategy bases trading decisions on multiple timeframe EMA crossovers and positional relationships. Specifically: 1. Utilizes 5-period, 20-period (based on high, low, and closing prices), and 50-period EMAs 2. Entry conditions require all indicators to show clear bullish alignment: 50EMA < 20EMA(Low) < 20EMA(Close) < 20EMA(High) < 5EMA 3. Requires current price to be above all EMAs, confirming strong trend 4. Exit uses dual mechanism: profit-taking when price breaks below 5-period EMA, or stop-loss when touching 20-period low EMA
This is a rigorously designed multiple moving average trading system that effectively controls risk through hierarchical filtering and dynamic stop-loss. While it may miss some rapid market movements, it performs consistently in trending markets. It’s recommended to adjust parameters according to different market characteristics and consider adding volume and other auxiliary indicators to improve reliability. This strategy is suitable for investors seeking stable returns in medium to long-term investments.
/*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("Automated EMA Strategy with Hierarchical Conditions", overlay=true)
// Inputs for EMA lengths
length_5 = 5
length_20 = 20
length_50 = 50
// Calculating EMAs
ema_5 = ta.ema(close, length_5)
ema_20_high = ta.ema(high, length_20)
ema_20_low = ta.ema(low, length_20)
ema_20_close = ta.ema(close, length_20)
ema_50 = ta.ema(close, length_50)
// Buy condition: 50 EMA < 20 EMA (Close) < 20 EMA (High) < 20 EMA (Low) < 5 EMA
// and LTP above all EMAs
buy_condition = ema_50 < ema_20_low and ema_20_low < ema_20_close and ema_20_close < ema_20_high and ema_20_high < ema_5 and close > ema_5 and close > ema_20_close and close > ema_20_high and close > ema_20_low and close > ema_50
// Stop-loss and target levels
stop_loss = ema_20_low
// Target condition: Close below 5 EMA
target_condition = close < ema_5
// Check if there's an open position
is_in_position = strategy.position_size > 0
// Execute Buy Signal only if no position is open
if (buy_condition and not is_in_position)
strategy.entry("Buy", strategy.long)
// Exit conditions: Stop-loss or target (close below 5 EMA)
if (is_in_position and (target_condition or close < stop_loss))
strategy.close("Buy")
// Plotting the EMAs
plot(ema_5, color=color.blue, title="5 EMA")
plot(ema_20_high, color=color.green, title="20 EMA (High)")
plot(ema_20_low, color=color.red, title="20 EMA (Low)")
plot(ema_20_close, color=color.purple, title="20 EMA (Close)")
plot(ema_50, color=color.orange, title="50 EMA")