ATR インディケーターに基づくパラボリック SAR トレイリングストップ戦略

作者: リン・ハーンチャオチャン,日付: 2023-09-13 15:53:00
タグ:

この戦略は,ATR指標に基づくパラボリックSARトレーリングストップ戦略と呼ばれる.この戦略は,市場変動の変化に適応するために,パラボリックSARの加速因子を調整するためにATR指標を使用する.

伝統的なパラボリックSARの加速因子は固定であり,変動の増加に適応できない.この戦略は,ATR値が拡大するにつれてSAR曲線をより速く収縮させるため,変動が上昇するとストップは価格の周りをより早く引き締め,リスクを効果的に制御することができます.

具体的には,価格トレンドを決定した後,アトリ値に基づいて適応加速因子が計算され,パラボリックSARのトレーリングストップ曲線をプロットします.価格がストップレベルを突破すると,ストップ損失が起動します.

この戦略の利点は,市場変動に基づいて従来のパラボリックSARストップをダイナミックにすることです.しかし,ATRパラメータは最適化が必要で,ストップラインは早期に破損する傾向があります.

一般的に,適応ストップは利益を保護しリスクを制限するために重要です.トレーダーは,市場の状況に基づいて適切なストップ指標を選択し,ストップ損失戦略の有用性を最大化するために,パラメータをテストし最適化する必要があります.


/*backtest
start: 2023-08-13 00:00:00
end: 2023-09-12 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy(title="ATR Parabolic SAR Strategy [QuantNomad]", shorttitle="ATR PSAR Strategy [QN]", overlay=true, default_qty_type = strategy.percent_of_equity,  default_qty_value = 100)

atr_length = input(14)
start      = input(0.02)
increment  = input(0.02)
maximum    = input(0.2)
entry_bars = input(1, title = "Entry on Nth trend bar") 

atr = atr(atr_length)

atr := na(atr) ? tr : atr

psar        = 0.0 // PSAR
af          = 0.0 // Acceleration Factor
trend_dir   = 0   // Current direction of PSAR
ep          = 0.0 // Extreme point
trend_bars  = 0

sar_long_to_short = trend_dir[1] == 1  and close <= psar[1] // PSAR switches from long to short
sar_short_to_long = trend_dir[1] == -1 and close >= psar[1] // PSAR switches from short to long

trend_change = barstate.isfirst[1] or sar_long_to_short or sar_short_to_long

// Calculate trend direction
trend_dir    :=  barstate.isfirst[1] and close[1]  > open[1] ?  1 : 
                 barstate.isfirst[1] and close[1] <= open[1] ? -1 : 
                 sar_long_to_short ? -1 : 
                 sar_short_to_long ?  1 : nz(trend_dir[1])

trend_bars := sar_long_to_short ? -1 : 
              sar_short_to_long ?  1 : 
              trend_dir ==  1   ? nz(trend_bars[1]) + 1 : 
              trend_dir == -1   ? nz(trend_bars[1]) - 1 : 
              nz(trend_bars[1])

// Calculate  Acceleration Factor
af := trend_change ? start : 
   (trend_dir == 1 and high > ep[1]) or  
   (trend_dir == -1 and low < ep[1]) ? 
   min(maximum, af[1] + increment) : 
   af[1]

// Calculate extreme point
ep := trend_change and trend_dir == 1 ? high :  
   trend_change and trend_dir == -1 ? low : 
   trend_dir == 1 ? max(ep[1], high) : 
   min(ep[1], low)

// Calculate PSAR
psar :=  barstate.isfirst[1] and close[1]  > open[1] ? low[1]  : 
         barstate.isfirst[1] and close[1] <= open[1] ? high[1] : 
         trend_change ? ep[1] :    
         trend_dir == 1 ? psar[1] + af * atr : 
                          psar[1] - af * atr

plot(psar, style=plot.style_cross, color=trend_dir == 1 ? color.green : color.red,  linewidth = 2)


// Strategy 
strategy.entry("Long",  true,  when = trend_bars ==  entry_bars)
strategy.entry("Short", false, when = trend_bars == -entry_bars)

もっと