This strategy combines mean reversion and trend following approaches, utilizing MA, MACD, and ATR technical indicators for generating trading signals and risk control. The core concept is to capture market reversals when price deviates from moving averages, confirmed by MACD crossover signals, while implementing ATR-based dynamic stop-loss for risk management.
The strategy employs a triple verification mechanism:
This strategy achieves a relatively robust trading system by combining mean reversion and trend following approaches. The multiple indicator verification mechanism enhances trading signal reliability, while ATR dynamic stop-loss effectively controls risk. Despite some room for optimization, it represents a logically sound and practical strategy framework.
/*backtest start: 2024-10-01 00:00:00 end: 2024-10-31 23:59:59 period: 3h basePeriod: 3h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Mean Reversion Strategy with ATR, MACD and MA", overlay=true) // === Настройки для индикаторов === // Параметры скользящей средней (MA) maLength = input.int(30, title="Период скользящей средней (MA)") maType = input.string("EMA", title="Тип скользящей средней", options=["SMA", "EMA"]) // Параметры ATR atrLength = input.int(10, title="Период ATR") atrMultiplier = input.float(10, title="ATR множитель для стоп-лосса") // Параметры MACD macdFastLength = input.int(8, title="Период быстрой EMA для MACD") macdSlowLength = input.int(26, title="Период медленной EMA для MACD") macdSignalLength = input.int(5, title="Период сигнальной линии MACD") // === Рассчёт индикаторов === // Скользящая средняя ma = if maType == "SMA" ta.sma(close, maLength) else ta.ema(close, maLength) // ATR (Средний истинный диапазон) atr = ta.atr(atrLength) // MACD [macdLine, signalLine, _] = ta.macd(close, macdFastLength, macdSlowLength, macdSignalLength) // Условия для входа на покупку и продажу longCondition = ta.crossover(macdLine, signalLine) and close < ma shortCondition = ta.crossunder(macdLine, signalLine) and close > ma // === Управление позициями === if (longCondition) strategy.entry("Buy", strategy.long) // Стоп-лосс на основе ATR stopLossLevel = close - atr * atrMultiplier strategy.exit("Take Profit/Stop Loss", "Buy", stop=stopLossLevel) if (shortCondition) strategy.entry("Sell", strategy.short) // Стоп-лосс на основе ATR stopLossLevel = close + atr * atrMultiplier strategy.exit("Take Profit/Stop Loss", "Sell", stop=stopLossLevel) // Визуализация plot(ma, title="MA", color=color.blue, linewidth=2) plot(macdLine, title="MACD Line", color=color.green) plot(signalLine, title="Signal Line", color=color.red) hline(0, "Zero Line", color=color.gray)