段階的な利益確定スリッページ戦略


作成日: 2023-11-28 16:05:24 最終変更日: 2023-11-28 16:05:24
コピー: 0 クリック数: 778
1
フォロー
1619
フォロワー

段階的な利益確定スリッページ戦略

概要

この戦略は,スライドストップとスライドストップを組み合わせた段階的なストップを利用した退出戦略である. これは,最初のストップに達した後にストップを損益均衡点に移動し,第二のストップに達した後にストップを損益均衡点に移動し,段階的なストップ・スライドストップの仕組みを実現する. これは,利益の一部をロックしながら,大きな利益の余地を維持する.

戦略原則

この戦略は,以下の部分によって,分段の滑り止め点を実現します.

  1. ストップポイントと3つのストップポイントを設定します.
  2. 現在の利得数とストップ・ローズ価格の計算関数を定義する.
  3. 利益の段階を定義する判断関数
  4. スライドポイントのストップを実現するために,異なる利益の段階においてストップ・ロスの価格を修正する.

具体的には,まず100点のストップ距離と100/200/300点の3つのストップ距離を設定します. そして,現在の価格と開設価格に基づいて,利得数を計算する関数を定義します.curProfitInPtsポイントの距離からストップ・プローストの関数calcStopLossPrice

重要な論理はgetCurrentStage関数,現在のポジションがあるかどうかを判断し,得益数が特定のストップポイントを超えたかどうかを判断し,超えた場合は次の段階へ進みます.例えば,100ポイントストップに達すると第2段階へ進み,200ポイントストップに達すると第3段階へ進みます.

最後に,段階によって異なるストップを修正して,滑点ストップを実現する.第一段階のストップは,元の設定を維持し,第二段階は,利回り均衡に移動し,第三段階は,最初のストップポイントに移動する.

優位分析

この段階的止滑点策には以下の利点があります.

  1. 利益の一部をロックし,その後の大きな利益の余地を残すことができる.
  2. スライドストップを利用して価格を追跡し,PRODIDの撤回や損失の可能性を減らすことができます.
  3. 複数の止まりによって,一度の止まりよりもリスクがコントロールできます.
  4. 戦略の論理は明確で シンプルで 分かりやすい.

リスク分析

この戦略にはいくつかのリスクがあります.

  1. 段階停止は,タイムストップができないことや,出口を逃すのが良いことにつながる可能性があります.ストップポイント数を調整することで最適化できます.
  2. スライド幅が大きすぎると,ストップダメージが早期に発生する可能性があります.異なるスライド幅をテストできます.
  3. 停止できないことも大きな損失のリスクを伴います.特定の状況で迅速な停止を考慮することができます.

最適化の方向

この戦略は以下の方向から最適化できます.

  1. 異なるストップ・ストップダメージ距離をテストし,パラメータを最適化する.
  2. 特別な状況では,迅速な停止のメカニズムを考慮してください.
  3. テクニカル指標の判断と組み合わせて,ストップとストップ・ローズを決定する.
  4. スライドポイント幅を最適化して,停止と停止をバランスする.
ストラテジーソースコード
/*backtest
start: 2023-11-20 00:00:00
end: 2023-11-27 00:00:00
period: 3m
basePeriod: 1m
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/
// © adolgov

// @description
// when tp1 is reached, sl is moved to break-even
// when tp2 is reached, sl is moved to tp1
// when tp3 is reached - exit

//@version=4
strategy("Stepped trailing strategy example", overlay=true)

// random entry condition
longCondition = crossover(sma(close, 14), sma(close, 28))
if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long)

// sl & tp in points
sl = input(100)
tp1 = input(100)
tp2 = input(200)
tp3 = input(300)

curProfitInPts() =>
    if strategy.position_size > 0
        (high - strategy.position_avg_price) / syminfo.mintick
    else if strategy.position_size < 0
        (strategy.position_avg_price - low) / syminfo.mintick
    else
        0
        
calcStopLossPrice(OffsetPts) =>
    if strategy.position_size > 0
        strategy.position_avg_price - OffsetPts * syminfo.mintick
    else if strategy.position_size < 0
        strategy.position_avg_price + OffsetPts * syminfo.mintick
    else
        0
        
calcProfitTrgtPrice(OffsetPts) =>
    calcStopLossPrice(-OffsetPts)

getCurrentStage() =>
    var stage = 0
    if strategy.position_size == 0 
        stage := 0
    if stage == 0 and strategy.position_size != 0
        stage := 1
    else if stage == 1 and curProfitInPts() >= tp1
        stage := 2
    else if stage == 2 and curProfitInPts() >= tp2
        stage := 3
    stage

stopLevel = -1.
profitLevel = calcProfitTrgtPrice(tp3)

// based on current stage set up exit
// note: we use same exit ids ("x") consciously, for MODIFY the exit's parameters
curStage = getCurrentStage()
if curStage == 1
    stopLevel := calcStopLossPrice(sl)
    strategy.exit("x", loss = sl, profit = tp3, comment = "sl or tp3")
else if curStage == 2
    stopLevel := calcStopLossPrice(0)
    strategy.exit("x", stop = stopLevel, profit = tp3, comment = "breakeven or tp3")
else if curStage == 3
    stopLevel := calcStopLossPrice(-tp1)
    strategy.exit("x", stop = stopLevel, profit = tp3, comment = "tp1 or tp3")
else
    strategy.cancel("x")
    
// this is debug plots for visulalize TP & SL levels
plot(stopLevel > 0 ? stopLevel : na, style = plot.style_linebr)
plot(profitLevel > 0 ? profitLevel : na, style = plot.style_linebr)