Strategi ini menggabungkan Average True Range (ATR) trailing stop dan garis retracement Fibonacci untuk merancang strategi trend following dengan perlindungan stop loss. Ketika harga menembus garis stop trailing ATR, strategi mulai mengikuti tren. Pada saat yang sama, garis retracement Fibonacci digunakan untuk menetapkan target harga, mencapai kombinasi organik trend following, stop loss dan take profit.
Strategi ini mengintegrasikan dua metode analisis teknis penting
/*backtest start: 2023-02-21 00:00:00 end: 2024-02-27 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("ATR TrailStop with Fib Targets", overlay=true) // Input parameters atrPeriod = input(5, title="ATR Period") ATRFactor = input(3.5, title="ATR Factor") Fib1Level = input(61.8, title="Fib1 Level") Fib2Level = input(78.6, title="Fib2 Level") Fib3Level = input(88.6, title="Fib3 Level") // ATR Calculation atrValue = ta.atr(atrPeriod) // ATR TrailStop Calculation loss = ATRFactor * atrValue trendUp = close[1] > close[2] ? (close - loss > close[1] ? close - loss : close[1]) : close - loss trendDown = close[1] < close[2] ? (close + loss < close[1] ? close + loss : close[1]) : close + loss trend = close > close[2] ? 1 : close < close[2] ? -1 : 0 trailStop = trend == 1 ? trendUp : trendDown // Fibonacci Levels Calculation ex = trend > trend[1] ? high : trend < trend[1] ? low : na fib1 = ex + (trailStop - ex) * Fib1Level / 100 fib2 = ex + (trailStop - ex) * Fib2Level / 100 fib3 = ex + (trailStop - ex) * Fib3Level / 100 // Plotting plot(trailStop, title="TrailStop", color=color.red) plot(fib1, title="Fib1", color=color.white) plot(fib2, title="Fib2", color=color.white) plot(fib3, title="Fib3", color=color.white) // Buy and Sell Signals longCondition = close > trailStop and close[1] <= trailStop shortCondition = close < trailStop and close[1] >= trailStop if (longCondition) strategy.entry("Long", strategy.long) if (shortCondition) strategy.entry("Short", strategy.short)