The Dual EMA Golden Cross Long Line strategy is a trend tracking strategy that only opens long positions. The strategy uses three moving averages, short-term EMA, medium-term EMA and long-term EMA. The specific entry rule is: open long when the price is above the long-term EMA and the short-term EMA crosses above the medium-term EMA to form a golden cross.
Calculate short-term EMA, medium-term EMA and long-term EMA using three EMA periods that are configurable.
If the price is above the long-term EMA, it proves that it is currently in a bullish trend.
If the short-term EMA crosses above the medium-term EMA from below to form a golden cross, it further proves that the bullish trend is strengthening.
When both conditions above are met at the same time, open long.
The biggest advantage of this strategy is that it can effectively identify trends by using multi-period EMAs combined judgment to avoid being misled by short-term market noise. At the same time, stop loss is configured as a risk control means to keep losses within a certain range.
The main risk of this strategy is the long position. When the market reverses, it is unable to close positions in time, leading to the risk of expanding losses. In addition, improper EMAs period setting can also lead to frequent trading and increase transaction costs.
Increase position sizing management to reduce positions when drawdowns reach a certain percentage.
Increase stop loss settings when breaking new highs.
Optimize EMAs period parameters to reduce trading frequency.
This strategy is overall a stable high-quality long-term holding strategy. It has strong ability to identify trends with proper risk control. With further optimization, it is expected to obtain better stable returns.
/*backtest start: 2024-01-01 00:00:00 end: 2024-01-31 23:59:59 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Strategia EMA Long con Opzioni di Uscita Avanzate e Periodi EMA Personalizzabili", overlay=true) // Parametri di input generali useVolatilityFilter = input.bool(true, title="Usa Filtro di Volatilità") atrPeriods = input.int(14, title="Periodi ATR", minval=1) atrMultiplier = input.float(1.5, title="Moltiplicatore ATR", step=0.1) useTrailingStop = input.bool(true, title="Usa Trailing Stop") trailingStopPercent = input.float(15.0, title="Percentuale Trailing Stop", minval=0.1, step=0.1) / 100.0 useEMAExit = input.bool(true, title="Usa Uscita EMA Corta incrocia EMA Media al Ribasso") // Parametri di input per periodi EMA personalizzabili emaLongTermPeriod = input.int(200, title="Periodo EMA Lungo Termine", minval=1) emaShortTermPeriod = input.int(5, title="Periodo EMA Breve Termine", minval=1) emaMidTermPeriod = input.int(10, title="Periodo EMA Medio Termine", minval=1) // Calcolo delle EMA con periodi personalizzabili longTermEMA = ta.ema(close, emaLongTermPeriod) shortTermEMA = ta.ema(close, emaShortTermPeriod) midTermEMA = ta.ema(close, emaMidTermPeriod) // Calcolo ATR e soglia di volatilità atr = ta.atr(atrPeriods) atrThreshold = ta.sma(atr, atrPeriods) * atrMultiplier // Condizione di entrata enterLongCondition = close > longTermEMA and shortTermEMA > midTermEMA enterLong = useVolatilityFilter ? (enterLongCondition and atr > atrThreshold) : enterLongCondition if (enterLong) strategy.entry("Enter Long", strategy.long) // Tracking del prezzo di entrata e del massimo prezzo raggiunto per il trailing stop var float entryPrice = na var float maxPriceSinceEntry = na if (strategy.position_size > 0) maxPriceSinceEntry := math.max(na(maxPriceSinceEntry) ? high : maxPriceSinceEntry, high) entryPrice := na(entryPrice) ? strategy.position_avg_price : entryPrice else maxPriceSinceEntry := na entryPrice := na // Calcolo del valore del trailing stop trailStopPrice = maxPriceSinceEntry * (1 - trailingStopPercent) // Implementazione delle condizioni di uscita exitCrossUnder = close < longTermEMA emaCross = ta.crossunder(shortTermEMA, midTermEMA) if (useEMAExit and emaCross) strategy.close("Enter Long", comment="EMA Cross Exit") if (useTrailingStop) strategy.exit("Trailing Stop", from_entry="Enter Long", stop=trailStopPrice) // Visualizzazioni plot(longTermEMA, color=color.yellow, title="EMA Lungo Termine") plot(shortTermEMA, color=color.blue, title="EMA Breve Termine") plot(midTermEMA, color=color.green, title="EMA Medio Termine") plot(useVolatilityFilter ? atrThreshold : na, color=color.purple, title="ATR Threshold") plot(strategy.position_size > 0 ? trailStopPrice : na, color=color.orange, title="Trailing Stop Value", style=plot.style_linebr)template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6