部分的な利益を取る戦略でステップアップトラッキングストップ

作者: リン・ハーンチャオチャン開催日:2023年11月28日 16:05:24
タグ:

img

概要

これは,部分的な利益を取ることによる段階的なトレーリングストップを使用する出口戦略である.最初の利益を取ったレベルに達した後,ストップロスをブレイクイブンに移動し,第2レベルに達した後,最初の利益を取ることに移動する.これは利益の可能性を維持しながら一部の利益をロックすることができます.

戦略の論理

この戦略の主な要素は次のとおりです.

  1. ストップ・ロスの設定と3は ポイントで利益レベルを取ります
  2. ポイントで現在の利益とストップ損失価格を計算するための関数を定義します.
  3. 現在の利益段階を決定する関数を定義します
  4. ストップ・ロスの価格を利益段階からトレイル価格に変更する.

まず,ストップ・ロスは100ポイントで,利益は100/200/300ポイントに設定します.curProfitInPtsこの関数は,現在の価格とエントリー価格に基づいて現在の利益を計算します.calcStopLossPriceこの関数は,点距離に基づいてストップ損失価格を計算します.

鍵となる論理はgetCurrentStageポジションがあるかどうか,利益が各取利益レベルを超えたかどうかをチェックする関数で,真である場合はステージを前進します.例えば,ステージ2は100ポイントの利益,ステージ3は200ポイントの利益後に達成されます.

最後に,ストップ・ロスはステージに応じて変更されます.ステージ1は元のストップ,ステージ2はブレイク・エヴェン,ステージ3は最初の取利益レベルを使用します.

利点分析

この段階的なストップ戦略の利点:

  1. 利益の一部を保持し 利益の可能性を保つことができます
  2. ストップ・ロスは価格を追って引き下げの確率を減らす
  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)

もっと