
This strategy is a trading system based on divergence relationships between the Parabolic SAR indicator and price movement. By monitoring divergence phenomena between SAR indicator and price trends, it identifies potential trend reversal points to capture market turning opportunities. The strategy employs the classic Parabolic SAR indicator as its core technical indicator, combined with divergence analysis methods to construct a complete trend-following trading system.
The core logic includes several key elements: 1. Uses Parabolic SAR indicator to track price trends, featuring dynamic adjustment of acceleration factors 2. Detects divergence between price and SAR indicator through a set lookback period 3. Triggers long signals when bullish divergence occurs (price makes new lows while SAR doesn’t) 4. Triggers short signals when bearish divergence occurs (price makes new highs while SAR doesn’t) 5. Marks trading signals on charts using shape.triangleup and shape.triangledown 6. Integrates alert functionality to notify traders of trading signals promptly
This is a trend-following strategy based on classic technical indicators, capturing market turning points through divergence analysis. The strategy design is clear, implementation methods are concise, and it has good operability. However, in practical application, it still needs optimization according to specific market characteristics, especially in risk control aspects. Through adding filtering mechanisms and improving the risk control system, this strategy has the potential to achieve more stable trading performance.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-11 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("SAR Divergence Strategy", overlay=true)
// --- Inputs ---
length = input.int(14, title="SAR Length", minval=1)
accelerationFactor = input.float(0.02, title="Acceleration Factor", minval=0.01)
maximumFactor = input.float(0.2, title="Maximum Factor", minval=0.01)
// --- SAR Calculation ---
sar = ta.sar(length, accelerationFactor, maximumFactor)
// --- Divergence Detection ---
lookback = 5
// Bullish Divergence
bullCond = close[lookback] < close[lookback + 1] and sar[lookback] > sar[lookback + 1]
// Bearish Divergence
bearCond = close[lookback] > close[lookback + 1] and sar[lookback] < sar[lookback + 1]
// --- Strategy Logic ---
if (bullCond)
strategy.entry("Long", strategy.long)
if (bearCond)
strategy.entry("Short", strategy.short)
// --- Plotting ---
plot(sar, color=color.blue, linewidth=2, title="Parabolic SAR")
plotshape(bullCond, style=shape.triangleup, color=color.green, size=size.small, title="Bullish Divergence")
plotshape(bearCond, style=shape.triangledown, color=color.red, size=size.small, title="Bearish Divergence")
// --- Alerts ---
alertcondition(bullCond, title="Bullish SAR Divergence", message="Bullish Divergence detected")
alertcondition(bearCond, title="Bearish SAR Divergence", message="Bearish Divergence detected")