Стратегия EMA SAR средне- и долгосрочного тренда является количественной торговой стратегией, которая использует комбинацию экспоненциальных скользящих средних (EMAs) и параболического стопа и обратного индикатора (SAR) для захвата средне- и долгосрочных тенденций на рынке. Стратегия определяет текущее направление тренда рынка путем сравнения 20-периодных и 60-периодных EMA и подтверждения с индикатором SAR.
/*backtest start: 2024-04-01 00:00:00 end: 2024-04-30 23:59:59 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("EMA SAR Strategy", overlay=true) // EMA Settings ema_20 = ta.ema(close, 20) ema_60 = ta.ema(close, 60) /// SAR Settings sar = ta.sar(0.02, 0.2, 0.2) sar_value = sar is_trend_up = sar[1] > sar[2] ? true : false // Evaluating the trend direction /// Condition for Buy Signal buy_condition = ta.crossover(ema_20, ema_60) and (sar_value < ema_20) and (is_trend_up) // Condition for Sell Signal sell_condition = ta.crossunder(ema_20, ema_60) and (sar_value > ema_20) and (not is_trend_up) // Define Entry Time entry_time = time + 180000 // Strategy Entry strategy.entry("Buy", strategy.long, when=buy_condition, comment="Buy Signal", stop=high[1]) strategy.entry("Sell", strategy.short, when=sell_condition, comment="Sell Signal", stop=low[1], when=entry_time) // Plot EMAs plot(ema_20, color=#f3e221, linewidth=1, title="EMA 20") plot(ema_60, color=#8724f0, linewidth=1, title="EMA 60") // Plot SAR plotshape(sar_value, style=shape.triangleup, location=location.abovebar, color=color.green, size=size.small, title="SAR Up") plotshape(sar_value, style=shape.triangledown, location=location.belowbar, color=color.red, size=size.small, title="SAR Down") // Plot Buy and Sell Signals plotshape(series=buy_condition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small) plotshape(series=sell_condition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small) // Send Alerts alertcondition(condition=buy_condition, title="Buy Signal", message="Buy Signal - EMA SAR Strategy") alertcondition(condition=sell_condition, title="Sell Signal", message="Sell Signal - EMA SAR Strategy")