This strategy is a trend following trading system that combines EMA crossover signals with dynamic risk management. It uses fast and slow Exponential Moving Averages (EMA) to identify market trends and incorporates the Average True Range (ATR) indicator to optimize entry timing. The strategy also integrates three layers of protection: percentage-based stop loss, take profit, and trailing stop.
The core logic is based on the following key elements:
This is a well-designed trend following strategy with clear logic. It captures trends through EMA crossovers, manages risk using ATR, and incorporates multiple stop loss mechanisms to form a complete trading system. The strategy’s main advantages lie in its comprehensive risk control and high customizability, but attention must be paid to false signals and transaction costs in live trading. Through the suggested optimization directions, there is room for further improvement in the strategy’s performance.
/*backtest start: 2024-12-29 00:00:00 end: 2025-01-05 00:00:00 period: 2m basePeriod: 2m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © jesusperezguitarra89 //@version=6 strategy("High Profit Buy/Sell Signals", overlay=true) // Parámetros ajustables fastLength = input.int(5, title="Fast EMA Length") slowLength = input.int(20, title="Slow EMA Length") atrLength = input.int(10, title="ATR Length") atrMultiplier = input.float(2.5, title="ATR Multiplier") stopLossPercent = input.float(1.0, title="Stop Loss %") takeProfitPercent = input.float(5.0, title="Take Profit %") trailingStop = input.float(2.0, title="Trailing Stop %") // Cálculo de EMAs fastEMA = ta.ema(close, fastLength) slowEMA = ta.ema(close, slowLength) // Cálculo del ATR atr = ta.atr(atrLength) // Señales de compra y venta longCondition = ta.crossover(fastEMA, slowEMA) and close > slowEMA + atrMultiplier * atr shortCondition = ta.crossunder(fastEMA, slowEMA) and close < slowEMA - atrMultiplier * atr // Dibujar señales en el gráfico plotshape(series=longCondition, location=location.belowbar, color=color.green, style=shape.labelup, text="BUY") plotshape(series=shortCondition, location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL") // Estrategia de backtesting para marcos de tiempo en minutos if longCondition strategy.entry("Buy", strategy.long) strategy.exit("Take Profit", from_entry="Buy", limit=close * (1 + takeProfitPercent / 100), stop=close * (1 - stopLossPercent / 100), trail_points=atr * trailingStop) if shortCondition strategy.entry("Sell", strategy.short) strategy.exit("Take Profit", from_entry="Sell", limit=close * (1 - takeProfitPercent / 100), stop=close * (1 + stopLossPercent / 100), trail_points=atr * trailingStop) // Mostrar EMAs plot(fastEMA, color=color.blue, title="Fast EMA") plot(slowEMA, color=color.orange, title="Slow EMA")