この戦略は,ATR指数に基づくパラロイドストップ戦略と呼ばれる.この戦略は,ATR指数を使用して,パラロイドストップ曲線の収縮速度を調整し,市場変動率の変化に自律的に適応できるようにする.
伝統的なパラレルラインのストップの加速因子は固定され,波動率の増加に対応することはできません.この戦略は,パラレルラインの収縮速度をATR値の拡大とともに加速させ,波動が拡大したときにストップ・カーブはより早く価格に近づき,リスクを効果的に制御することができます.
具体的には,戦略は,価格のトレンド方向を判断した後,ATR値に基づいて自律的な加速因子を計算し,それに基づいてパラロージュラインのストップ・プロースト曲線を描きます.価格がストップ・プローストラインを破るとき,ストップ・プリーズ・ポジションを実行します.
この戦略の利点は,従来のパラロージュ・ライン・ストップが市場の変動率に基づいて動的に調整できるようにすることである。しかし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)