最良のATR停止多重戦略

作者: リン・ハーンチャオチャン,日付: 2024-02-21 14:24:22
タグ:

img

概要

ベストATRストップマルチプル戦略は,ストップ損失ポイントを設定し,リスクを動的に調整するために平均真数範囲 (ATR) の倍数を使用するトレンドフォロー戦略である.価格傾向が変化すると,大きな損失を避けるために,ポジションをタイムリーに退場することができます.

戦略の論理

この戦略は,まず,高速SMAと遅いSMA期の単純な移動平均を計算する.高速SMAが遅いSMAを横切ると長くなって,高速SMAが遅いSMAを下回ると短くなります.

ATRは,特定のバックバック期間の平均変動を表します.この戦略は,ATR期間 (デフォルト 14) と倍数 (デフォルト 2) を設定することを可能にします.システムは,エントリー時にATR値を計算し,それを停止距離として設定された倍数で倍します.

例えば,エントリー後のATRが50ポイントで,倍数が2に設定されている場合,ストップ距離は100ポイントになります.価格が100ポイント以上移動した場合,ストップ損失オーダーは起動されます.これは過剰な損失を避けるためにタイムリーストップ損失を可能にします.

この戦略はトレンド決定も考慮する.ロングストップ・ロスは,買い信号が上昇傾向に一致するときにのみ有効である.ショートストップ・ロスは下落傾向に一致する.

ストップ・ロスの線はチャートに描かれています リアルタイムで確認できます ストップ・ロスの条件が起動すると 対応するポジションは システムによって自動的に閉鎖されます

利点分析

この戦略の最大の利点は,ストップ損失距離を動的に調整し,市場の変動の変化に基づいてリスク露出を自動的に修正することです. 変動が拡大すると,ストップ損失の発生の可能性を減らすストップ距離も増加します. 変動が低い市場で,ストップ距離は減少します.

固定ストップロスの距離と比較して,このアプローチはトレンドを追跡しながら,取引ごとに損失を効果的に制御します.利益の余地とリスクを管理することを保証します.

さらに,トレンド決定と組み合わせると,そのようなストップ・ロスは,統合ゾーンでウィップソーによって停止される可能性を減らすことができます.

リスク分析

この戦略の主なリスクは,ポジション中に価格が短期的に引き下げられ,ストップ・ロスは引き起こす可能性である.特にATR期間が短すぎると,ストップ距離は短期変動の影響を完全にフィルタリングすることはできません.

またリスクは,価格が暴力的な動きでストップ・ロスのレベルを通過するギャップがあることです.これはより大きなATR倍数値設定を必要としますが,それは利益の可能性も減少することを意味します.

最後に,この戦略は,ATR値に対する時間外取引と市場前の取引の影響を考慮していない.これは,開閉や閉閉時のATRデータの計算が不正確になる可能性があります.

オプティマイゼーションの方向性

戦略は,いくつかの側面で最適化することができます:

  1. ATR 期間パラメータを最適化し,異なる市場のための最良の組み合わせをテストする

  2. 固定と動的ATR倍数を比較する

  3. ATR 計算に時間外データを組み込み,開業のギャップを減らす

  4. ATR条件を設定する: ATRが一定のレベルに達したときに停止するのみを有効にし,低変動環境で不必要な停止を避ける.

  5. より多くのフィルターを組み込む:主要動向,ボリューム/モメント指標など

結論

ベストATRストップマルチプル戦略は,ストップ距離を動的に調整することで,トレンドフォローとリスク制御を効果的にバランスさせます.固定ストップと比較して,損失を効果的に制限しながら利益の可能性を保証します.

価格格差や過度に敏感なストップなどのリスクは残っています. 多次元的なさらなる最適化により 安定性と収益性が向上します.


/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
//@author=Daveatt
//This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/

SystemName = "BEST ATR Stop Multiple Strategy"
TradeId = "BEST"

InitCapital = 100000
InitPosition = 100
InitCommission = 0.075
InitPyramidMax = 1
CalcOnorderFills = true
CalcOnTick = true
DefaultQtyType = strategy.fixed
DefaultQtyValue = strategy.fixed
Precision = 2
Overlay=true


strategy(title=SystemName, shorttitle=SystemName, overlay=Overlay )

fastSMAperiod = input(defval=15, title='Fast SMA', type=input.integer, minval=2, step=1)
slowSMAperiod = input(defval=45, title='Slow SMA', type=input.integer, minval=2, step=1)

src = close
// Calculate moving averages
fastSMA = sma(src, fastSMAperiod)
slowSMA = sma(src, slowSMAperiod)

// Calculate trading conditions
enterLong  = crossover(fastSMA, slowSMA)
enterShort = crossunder(fastSMA, slowSMA)

// trend states
since_buy  = barssince(enterLong)
since_sell = barssince(enterShort)
buy_trend  = since_sell > since_buy
sell_trend = since_sell < since_buy 

is_signal = enterLong or enterShort

// get the entry price
entry_price = valuewhen(enterLong or enterShort, src, 0)

// Plot moving averages
plot(series=fastSMA, color=color.teal)
plot(series=slowSMA, color=color.orange)

// Plot the entries
plotshape(enterLong, style=shape.circle, location=location.belowbar, color=color.green, size=size.small)
plotshape(enterShort, style=shape.circle, location=location.abovebar, color=color.red, size=size.small)



///////////////////////////////
//======[ Trailing STOP ]======//
///////////////////////////////

// use SL?
useSL = input(true, "Use stop Loss")
// ATR multiple Stop
stop_atr_length         = input(14,title="ATR Length", minval=1, type=input.integer)
stop_atr_mult           = input(2,title="ATR Multiple", minval=0.05, step=0.1, type=input.float)

// Global STOP

stop_price = 0.0, stop_price := nz(stop_price[1])

// STOP ATR
var stop_atr      = 0.0
var entry_stop_atr   = 0.0

stop_atr          := nz(atr(stop_atr_length))

if enterLong or enterShort
    entry_stop_atr := stop_atr * stop_atr_mult

// display the ATR value multiple
plotshape(enterLong, title='ATR Long Stop value', style=shape.labelup, 
 location=location.bottom, color=color.green, transp=0, text='', textcolor=color.navy, editable=true, size=size.small, show_last=1, size=size.small)

// var label atr_long_label = na
// var label atr_short_label = na
lapos_y_entry_up = lowest(30)
lapos_y_entry_dn = highest(30)

// text_label = "ATR value: " + tostring(stop_atr, '#.#') + "\n\nATR Multiple value: " + tostring(entry_stop_atr, '#.#')

// if enterLong

//     label.delete(atr_long_label)

//     atr_long_label := label.new(bar_index, lapos_y_entry_up, text=text_label, 
//      xloc=xloc.bar_index, yloc=yloc.price, color=color.green, style=label.style_labelup, textcolor=color.white, 
//      size=size.normal)    

// if enterShort

//     label.delete(atr_short_label)

//     atr_short_label := label.new(bar_index, lapos_y_entry_dn, text=text_label, 
//      xloc=xloc.bar_index, yloc=yloc.price, color=color.red, style=label.style_labeldown, textcolor=color.black, 
//      size=size.normal)    

// Determine trail stop loss prices
longStopPrice = 0.0, shortStopPrice = 0.0

longStopPrice := if useSL and buy_trend
    stopValue = entry_price - entry_stop_atr
else
    0

shortStopPrice := if useSL and sell_trend
    stopValue = entry_price + entry_stop_atr
else
    999999

//////////////////////////////////////////////////////////////////////////////////////////
//*** STOP LOSS HIT CONDITIONS TO BE USED IN ALERTS  ***//
//////////////////////////////////////////////////////////////////////////////////////////

cond_long_stop_loss_hit  = useSL and buy_trend and crossunder(low, longStopPrice[1]) 

cond_short_stop_loss_hit = useSL and sell_trend and crossover(high, shortStopPrice[1]) 


// Plot stop loss values for confirmation
plot(series=useSL and buy_trend and low >= longStopPrice 
 ? longStopPrice : na,
 color=color.fuchsia, style=plot.style_cross,
 linewidth=2, title="Long Trail Stop")

plot(series=useSL and sell_trend and high <= shortStopPrice 
 ? shortStopPrice : na,
 color=color.fuchsia, style=plot.style_cross,
 linewidth=2, title="Short Trail Stop")

close_long  = cond_long_stop_loss_hit
close_short = cond_short_stop_loss_hit

// Submit entry orders
strategy.entry(TradeId + " L", long=true, when=enterLong)
strategy.close(TradeId + " L", when=close_long)

//if (enterShort)
strategy.entry(TradeId + " S", long=false, when=enterShort)
strategy.close(TradeId + " S", when=close_short)


もっと