ダイナミック・トラッキング・ストップ・ロスの戦略

作者: リン・ハーンチャオチャン, 日時: 2023-12-21 15:58:54
タグ:

img

概要

この戦略は,日々のキャンドルストイックに基づいてトレンド方向を決定し,ストップ・ロスの価格またはストップ・ロスの価格として15分キャンドルストイックによって形成された新しい高値または低値を使用し,ストップ・ロスを動的に調整し,より多くの利益をロックします.

戦略の論理

  1. 日々のキャンドルストイックの閉じる価格を前回の日々のキャンドルストイックの最高値と最低値と比較してトレンド方向を決定する.閉じる価格が前日の最高価格よりも高くなった場合,それは上向きトレンドとして定義される.閉じる価格が前日の最低価格よりも低い場合,それは下向きトレンドとして定義される.

  2. アップトレンドの場合,15分間のキャンドルストイックの閉じる価格が前回の15分間のキャンドルストイックの最高価格よりも高くなったときにロングします.ダウントレンドの場合,15分間のキャンドルストイックの閉じる価格が前回の15分間のキャンドルストイックの最低価格よりも低いときにショートします.

  3. 前回の15分間のキャンドルストイックの最低価格をロングした後のストップ損失価格として設定します.前回の15分間のキャンドルストイックの最高価格をショートした後のストップ損失価格として設定します.

  4. 15分キャンドルストイックは再び新高または低値に達すると,その Stop Loss 価格をそれに合わせて調整します.ロング後,新低値に調整します.ショート後,新高値に調整します.これはダイナミックなトライリングストップ損失を実現します.

利点分析

この戦略の最大の利点は,ストップ・ロスの価格を動的に調整でき,リスク制御を保証しながら,利益を引き上げ,ストップ・ロスの確率を最小限に抑えるということです.

具体的には,以下のような利点があります.

  1. トレンドオペレーションに基づく判断により 市場の傾向を及ばせ,正しい取引方向を選択できます

  2. 15分間のタイムフレーム取引は,より多くの機会を掴むために頻繁なエントリーと出口を可能にします.

  3. 新しい高値や低値に基づいて動的ストップロスの調整は,ストップロスのリスクを軽減します.

  4. 合理的なストップロスの位置付けは,不必要な損失を大幅に回避します.

リスク分析

この戦略の主なリスクは,動向判断の誤りから生じる.具体的リスクには以下が含まれます.

  1. 日々のトレンド判断が間違っている場合,間違った取引方向に導かれる可能性があります.

  2. 価格が短期間で急激に変動し,15分ストップロスの確率が増加します.

  3. トレンド逆転点の誤った識別は損失につながる可能性があります.

対応する解法:

  1. 総合的な判断のために他の時間枠からの指標を追加し,一つの時間枠だけに依存しないようにします.

  2. 市場変動を評価し,高い変動の際に適切なストップ損失範囲を緩和する.

  3. トレンド逆転点の識別メカニズムを追加して,逆転前にタイミングでポジションを閉じます.

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

更に最適化できる余地があります

  1. トレンドの把握を最適化するために他のタイムフレーム指標を追加します.

  2. 最適なパラメータを見つけるために 異なるストップ損失比設定をテストします

  3. 音量差による誤りを避けるために音量指標を追加する.

  4. エクシートポイントを最適化するためにトレンド逆転メカニズムを追加します

  5. トレイリングストップ価格間隔の拡大を評価し,ストップロスのリスクをさらに削減する.

概要

この戦略の全体的な性能は良好である.論理は明確で理解しやすい.動的ストップ損失調整,頻繁な取引,トレンドに沿った取引などの利点がある.リスクを効果的に制御し,利益をロックすることができ,さらなるテストと最適化に値する.しかし,まだ改善の余地がある.戦略の安定性と収益性をさらに強化するために,複数の角度から包括的な判断,パラメータ最適化,トレンド逆転識別メカニズムを追加などの側面から改善することが推奨される.


/*backtest
start: 2023-12-13 00:00:00
end: 2023-12-15 02:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Anand's Strategy", overlay=true)

// Get the high and low of the previous day's candle
prev_high = request.security(syminfo.tickerid, "D", high[2])
prev_low = request.security(syminfo.tickerid, "D", low[2])

// var float prev_high = na
// var float prev_low = na

prev_close = request.security(syminfo.tickerid, "D", close[1])


getDayIndexedHighLow(_bar) =>
    _indexed_high = request.security(syminfo.tickerid, "D", high[_bar])
    _indexed_low = request.security(syminfo.tickerid, "D", low[_bar])
    [_indexed_high, _indexed_low]

var index = 2

while index >= 0
    [indexed_high_D, indexed_low_D] =  getDayIndexedHighLow(index)
  
    if prev_close > indexed_high_D or prev_close < indexed_low_D
        prev_high := indexed_high_D
        prev_low := indexed_low_D
        break
    // Decrease the index to move to the previous 15-minute candle
    index := index - 1


// Determine the trade direction based on the candle criterion
trade_direction = prev_close > prev_high ? 1 : (prev_close < prev_low ? -1 : 0)

// Get the current close from 15-minute timeframe
current_close = request.security(syminfo.tickerid, "15", close[1])
prev_high_15m = request.security(syminfo.tickerid, "15", high[2])
prev_low_15m = request.security(syminfo.tickerid, "15", low[2])

// var float prev_high_15m = na
// var float prev_low_15m = na

getIndexedHighLow(_bar) =>
    _indexed_high = request.security(syminfo.tickerid, "15", high[_bar])
    _indexed_low = request.security(syminfo.tickerid, "15", low[_bar])
    [_indexed_high, _indexed_low]


// Loop through previous 15-minute candles until the condition is met
var  i = 2

while i >= 2
    [indexed_high_15m, indexed_low_15m] =  getIndexedHighLow(i)
  
    if current_close > indexed_high_15m or current_close < indexed_low_15m
        prev_high_15m := indexed_high_15m
        prev_low_15m := indexed_low_15m
        break
    // Decrease the index to move to the previous 15-minute candle
    i := i - 1



buy_condition = trade_direction == 1 and current_close > prev_high_15m
stop_loss_buy = prev_low_15m

// Sell Trade Criteria in Negative Trend
sell_condition = trade_direction == -1 and current_close < prev_low_15m
stop_loss_sell = prev_high_15m


// Trailing Stop Loss for Buy Trade
// Custom Trailing Stop Function for Buy Trade
var float trail_stop_buy = na
trailing_buy_condition = buy_condition and current_close > trail_stop_buy
if trailing_buy_condition
    trail_stop_buy := current_close

// Custom Trailing Stop Function for Sell Trade
var float trail_stop_sell = na
trailing_sell_condition = sell_condition and current_close < trail_stop_sell
if trailing_sell_condition
    trail_stop_sell := current_close

// Take Buy Trade with Stop Loss
if (buy_condition)
    strategy.entry("Buy", strategy.long)
    strategy.exit("Buy Stop Loss", "Buy", stop=stop_loss_buy)

// Take Sell Trade with Stop Loss
if (sell_condition)
    strategy.entry("Sell", strategy.short)
    strategy.exit("Sell Stop Loss", "Sell", stop=stop_loss_sell)

// Set the background color based on the trade direction
bgcolor(trade_direction == 1 ? color.new(color.green, 90) : trade_direction == -1 ? color.new(color.red, 90) : na)

もっと