ダイナミックトレーリングストップロス戦略


作成日: 2023-12-29 10:42:27 最終変更日: 2023-12-29 10:42:27
コピー: 0 クリック数: 872
1
フォロー
1617
フォロワー

ダイナミックトレーリングストップロス戦略

概要

ダイナミック・トラッキング・ストップ・ストラスト戦略は,トラッキング・ストップ・メカニズムを利用した量化取引戦略である.この戦略は,トレンド・トラッキング理論に基づいて,ストップ・ストラストラインを設定し,ストップ・ストラストの確認とトラッキング・ストップ・ストラストの調整を実現する.主に,単一取引のストップ・ストラストを制御し,利益を最大限にロックし,取引リスクを低減するために使用される.

戦略原則

ダイナミック・トラッキング・ストップ・ストープ戦略の核心は,3つの重要なパラメータを設定することにある. 初期ストップ・距離,トラッキング・ストップ・距離,トラッキング・ストップ・トラッキング・距離. 買取信号が触発されると,買取価格と設定された初期ストップ・距離に基づいて初期ストップ・価格が計算される. その後,各K線は,トラッキング・ストップ・トラッキングの条件が満たされているかどうかを判断し,それが満たされた場合,新しいトラッキング・ストップ・価格が設定される.

この戦略には,追跡停止が起動されるかどうかにかかわらず,低位停止が設定され,価格が低いストップに達した場合,直接停止されます.低位停止は,突発的な出来事を防ぐための価格の飛躍を防ぐために使用されます.したがって,ダイナミック・トラッキング・ストップ戦略は,上下双線形式のダイナミック・ストップメカニズムを使用して,ストップラインを自動的に有利な動きを追跡させ,過大な損失を防ぐことができます.

戦略的優位性

  1. ストップ・ローズを追跡し,利益を固定し,過剰な返済機会を回避する.

  2. 上下双線ストップ構造を採用し,ストップラインが間に合うように確保し,過度の損失を防ぐ.

  3. 継続判断メカニズムを利用して,ストップ・ローズ調整を行う.操作はシンプルで,容易に実現する.

  4. 市場と個々の株の特徴に応じてパラメータを調整して,ストップ・ロスを最適化できます.

  5. 市場を予測する必要なく,トレンドに合わせて行動する.

戦略リスク

  1. パラメータを正しく設定しないことにより,ストップが過度に緩やかまたは過度に緊迫する可能性があります.過度に緩やかであれば,効率的なストップができません.過度に緊迫すると,価格の通常の変動に容易く打たれます.

  2. 突発的な事件が価格を飛躍的に下落させると,ストップダメージが無効になる可能性があり,他の防護措置と併用すべきである.

  3. 取引手数料とスライドポイントは,ストップラインが触発された後の実際の販売価格に影響を与える可能性があります.

  4. 適応性が薄いため,地震などの特定の時期にはあまり効果的ではない.

対策として

  1. テストと実盤の結果に基づいてパラメータを継続的に最適化することをお勧めします.
  2. より広い低位止まりを設定して防空跳びを行う.
  3. 取引費用とスライドポイントの影響を考慮してストップ・ロスを計算する.
  4. トレンドと波動判断指標を組み合わせて使用する.

戦略最適化の方向性

  1. ストップラインを追跡するストップラインをパーセンテージ・チェンジに調整することで,異なる価格レベルでの株価の変化をよりよく追跡することができる.

  2. 波動率指標を追加し,大きな波動を判断すると,ストップを追跡を一時停止し,通常の波動がストップを誘発することを避ける.

  3. 機械学習によるパラメータの自動最適化. 訓練サンプルが,最近の一連のパラメータの収益率を選択する.

  4. ポジション開設条件の判断を増加させ,トレンド,サポートレジスタンスなどの指標を組み合わせ,震動の状況でポジション開設を避ける.

要約する

ダイナミック・トラッキング・ストップ・ストラトジーは,双線ストップ・メカニズム,トラッキング・ストップ・ラインの設定,ストップ・確認とトラッキング・ストップ・調整を実現する.価格変化に応じてストップ・ストレスを自動的に調整し,利益をロックし,反転を軽減し,損失を制御する.この戦略は,操作がシンプルで,実装が簡単で,市場状況に応じてパラメータを最適化し,他の戦略の組み合わせで使用効果が優れている.しかし,一定の制限も存在し,調整を完了して実用化して投入することを推奨する.

ストラテジーソースコード
/*backtest
start: 2023-11-28 00:00:00
end: 2023-12-17 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

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

/////////////////////////////////////////////////////////////////////////////////////////////
// Comment out Strategy Line and remove // from Indicator line to turn into Indicator  //////
// Do same for alertConidction at bottom                                               //////
/////////////////////////////////////////////////////////////////////////////////////////////
strategy("PCT Trailing Stoploss-Strategy", shorttitle="PCT Trailing Stoploss- Strategy", overlay=true)
//indicator(title="PCT Trailing Stoploss- Indicator", shorttitle="PCT Trailing Stoploss - Indicator", timeframe="", timeframe_gaps=true, overlay=true)//

sellLow=input.float(.035, minval=0, title="Stop Loss Loss: 1% = .01", group="Sell Settings")
trailStopArm=input.float(.0065, minval=0, title="Trailing Stop Arm: 1%=.01", group="Sell Settings")
trailStopPct=input.float(.003, minval=0, title="Trailing Stop Trigger: 1%=.01 ", group="Sell Settings")

/////////////////////////////////////////////////
//               Indicators                    //
/////////////////////////////////////////////////
ema1Len = input.int(14, minval=1, title=" ema 1 Length", group="Trend Line Settings")
ema1Src = input(close, title="ema 1 Source", group="Trend Line Settings")
ema1 = ta.ema(ema1Src, ema1Len)
plot(ema1, title="EMA", color=color.blue)

ema2Len = input.int(22, minval=1, title=" ema 2 Length", group="Trend Line Settings")
ema2Src = input(close, title="ema 2 Source", group="Trend Line Settings")
ema2 = ta.ema(ema2Src, ema2Len)
plot(ema2, title="EMA", color=color.orange)

ema3Len = input.int(200, minval=1, title=" ema 3 Length", group="Trend Line Settings")
ema3Src = input(close, title="ema 2 Source", group="Trend Line Settings")
ema3 = ta.ema(ema3Src, ema3Len)
plot(ema3, title="EMA", color=color.gray)


/////////////////////////////
////   Buy Conditions    ////
/////////////////////////////

alertBuy = ta.crossover(ema1,ema2) and close>ema3

////////////////////////////////////////////////////////////////////
////   Filter redundant Buy Signals if Sell has not happened    ////
////////////////////////////////////////////////////////////////////
var lastsignal = 0
showAlertBuy = 0
if(alertBuy and lastsignal !=1)
    showAlertBuy  := 1
    lastsignal      := 1
buyAlert= showAlertBuy > 0


//////////////////////////////////////////////////////////////////
////          Track Conditions at buy Signal                  ////
//////////////////////////////////////////////////////////////////

alertBuyValue = ta.valuewhen(buyAlert, close,0)
alertSellValueLow = alertBuyValue - (alertBuyValue*sellLow)

////////////////////////////////////////////////////////////
/////            Trailing Stop                         /////
////////////////////////////////////////////////////////////
var TSLActive=0         //Check to see if TSL has been activated
var TSLTriggerValue=0.0 //Initial and climbing value of TSL
var TSLStop = 0.0       //Sell Trigger
var TSLRunning =0       //Continuously check each bar to raise TSL or not

//  Check if a Buy has been triggered and set initial value for TSL //
if buyAlert
    TSLTriggerValue := alertBuyValue+(alertBuyValue*trailStopArm)
    TSLActive := 0
    TSLRunning :=1
    TSLStop := TSLTriggerValue - (TSLTriggerValue*trailStopPct)
    

//  Check that Buy has triggered and if Close has reached initial TSL//  
//  Keeps from setting Sell Signal before TSL has been armed w/TSLActive//
beginTrail=TSLRunning==1 and TSLActive==0 and close>alertBuyValue+(alertBuyValue*trailStopArm) and ta.crossover(close,TSLTriggerValue)
if beginTrail
    TSLTriggerValue :=close
    TSLActive :=1
    TSLStop :=TSLTriggerValue - (TSLTriggerValue*trailStopPct)
    
//  Continuously check if TSL needs to increase and set new value //    
runTrail= TSLActive==1 and (ta.crossover(close,TSLTriggerValue) or close>=TSLTriggerValue)
if runTrail
    TSLTriggerValue :=close
    TSLStop :=TSLTriggerValue - (TSLTriggerValue*trailStopPct)
    
//  Verify that TSL is active and trigger when close cross below TSL Stop//
TSL=TSLActive==1 and (ta.crossunder(close,TSLStop) or (close[1]>TSLStop and close<TSLStop)) 

// Plot point of inital arming of TSL//
TSLTrigger=TSLActive==1 and TSLActive[1]==0
plotshape(TSLTrigger, title='TSL Armed', location=location.abovebar, color=color.new(color.blue, 0), size=size.small, style=shape.cross, text='TSL Armed')


////////////////////////////////////////////////////////////
// Plots used for troubleshooting and verification of TSL //
////////////////////////////////////////////////////////////
//plot(TSLActive,"Trailing Stop", color=#f48fb1)
//plot(TSLRunning,"Trailing Stop", color=#f48fb1)
//plot(TSLTriggerValue,"Trailing Stop Trigger", color.new(color=#ec407a, transp = TSLRunning==1 ? 0 : 100))
//plot(TSLStop,"Trailing Stop", color.new(color=#f48fb1, transp = TSLRunning==1 ? 0 : 100))//


////////////////////////////////////////////////////////////
/////             Sell Conditions                    ///////
////////////////////////////////////////////////////////////
Sell1 = TSL
Sell2 = ta.crossunder(close,alertSellValueLow)

alertSell= Sell1 or Sell2
////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////
////        Remove Redundant Signals                    ////
////////////////////////////////////////////////////////////
showAlertSell = 0
if(alertSell and lastsignal != -1)
    showAlertSell := 1
    lastsignal      := -1
sellAlert= showAlertSell > 0

if sellAlert
    TSLActive :=0
    TSLRunning :=0

/////////////////////////////////////////
//  Plot Buy and Sell Shapes on Chart  //
/////////////////////////////////////////
plotshape(buyAlert, title='Buy', location=location.belowbar, color=color.new(color.green, 0), size=size.small, style=shape.triangleup, text='Buy')
plotshape(sellAlert, title='Sell', location=location.abovebar, color=color.new(color.red, 0), size=size.small, style=shape.triangledown, text='Sell')

/////////////////////////////////////////////////////////////////////////////////////////////
//                        Remove // to setup for Indicator                                 //
/////////////////////////////////////////////////////////////////////////////////////////////
//Alerts
//alertcondition(title='Buy Alert', condition=buyAlert, message='Buy Conditions are Met')
//alertcondition(title='Sell Alert', condition=sellAlert, message='Sell Conditions are Met')
/////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////
////  Comment out this section if setup as Indicator    ////
////////////////////////////////////////////////////////////
longCondition = buyAlert
if (longCondition)
    strategy.entry("Buy", strategy.long)
    alert(message='Buy', freq=alert.freq_once_per_bar_close)
    
shortCondition = sellAlert
if (shortCondition)
    strategy.close_all(sellAlert,"Sell")
    alert(message='Sell', freq=alert.freq_once_per_bar_close)
/////////////////////////////////////////////////////////////