Strategies KB.ZH
Strategies

抛物线转向SAR策略Parabolic-SAR-Reversal-Strategy

ChaoZhang · PineScript · Trend Following · 2023-09-18 21:59:08

All strategies →

Overview

This strategy trades based on Parabolic SAR indicator which identifies potential reversal points in trends. Entry signals are generated when SAR flips above or below price.

Principle

Parabolic SAR is a trend following indicator that mainly identifies trend reversals. When SAR is below price, it represents uptrend. SAR flipping above price gives short signal. When SAR is above price, it represents downtrend. SAR flipping below price gives long signal. The strategy simply trades the SAR flip as signal direction, with SAR as stop loss.

Advantages

  1. SAR accurately locates potential reversal points.
  2. Trend following mechanism reduces false signals.
  3. SAR acts as trailing stop, avoiding being trapped.
  4. No other indicators or filters required.
  5. Easy parameter optimization, defaults often work.

Summary

The strategy trades potential reversal points identified by SAR, taking trades when SAR flips price. Benefits include trailing stops to avoid traps. But SAR timing may be inaccurate and needs refinement. Overall the SAR reversal concept is worth learning. [/trans]

Other

  1. SAR may whipsaw in ranging markets. Trend filter can be added.
  2. SAR too close to price risks being hit. Wider stops needed.
  3. Volume is ignored, risk of divergence. Volume indicators can help.
  4. Drawdowns may be significant. Appropriate position sizing is key.
  5. Reversals do not always succeed. Confirmation may be needed.
  6. Test if SAR parameters can be improved.
  7. Add indicators like MACD to confirm reversal probability.
  8. Build dynamic trailing stop mechanism.
  9. Optimize entry position sizing to capitalize on SAR signals.
  10. Research adding reversal confirmation logic.

Parameters

ParametersDefaultDescription
v_input_10.02start
v_input_20.02increment
v_input_30.2maximum
v_input_4trueFrom Day
v_input_5trueFrom Month
v_input_62018From Year
v_input_7trueTo Day
v_input_8trueTo Month
v_input_92019To Year
Source code (63 lines)
/*backtest
start: 2023-08-18 00:00:00
end: 2023-09-17 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
strategy("Parabolic SAR Strategy", overlay=true)

// 
// author: Kozlod
// date: 2018-09-03
// https://www.tradingview.com/u/Kozlod/
// 

start = input(0.02)
increment = input(0.02)
maximum = input(0.2)

////////////////////////////////////////////////////////////////////////////////
// BACKTESTING RANGE
 
// From Date Inputs
fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
fromYear = input(defval = 2018, title = "From Year", minval = 1970)
 
// To Date Inputs
toDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
toMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
toYear = input(defval = 2019, title = "To Year", minval = 1970)
 
// Calculate start/end date and time condition
startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)
finishDate = timestamp(toYear, toMonth, toDay, 00, 00)
time_cond = true
 
////////////////////////////////////////////////////////////////////////////////

psar = sar(start, increment, maximum)

// Signals
psar_long  = high[1] < psar[2] and high > psar[1] 
psar_short = low[1]  > psar[2] and low  < psar[1] 

// Plot PSAR
plotshape(psar, location = location.absolute, style = shape.cross, size = size.tiny, color = low < psar[1] and not psar_long ? green : red)


if (psar >= high and time_cond)
    strategy.entry("ParLE", strategy.long, stop=psar, comment="ParLE")
else
    strategy.cancel("ParLE")

if (psar <= low and time_cond)
    strategy.entry("ParSE", strategy.short, stop=psar, comment="ParSE")
else
    strategy.cancel("ParSE")

if (not time_cond)
    strategy.close_all()