トレンドトラッキング ブレイクアウト戦略

作者: リン・ハーンチャオチャン,日付: 2024-01-22 17:21:10
タグ:

img

概要

これはトレンド追跡に基づいたブレークアウト戦略です.ブレークアウトが起きたときに強さを買って,トレンドを追跡するために弱さを売ります.

戦略の論理

この戦略は,エントリーとアウトシグナルを決定するために主に2つの指標に依存します. 特定の期間で最も高い価格を決定する最高値と,特定の期間で最も低い価格を決定する最低値です.

閉じる価格が特定の期間の最高価格 (highPeriodパラメータ) を上回ると,上向きトレンドブレイクとみなされ,ロング信号が発行される.閉じる価格が特定の期間の最低価格 (lowPeriodパラメータ) を下げる場合,下向きトレンドブレイクとみなされ,ショート信号が発行される.

この戦略は,移動ストップ損失と固定ストップ損失を設定する.移動ストップ損失は,移動ストップ損失レベルとして一定期間のATR値 (trailingAtrMultiplierパラメータ) を倍したATR指標に基づいて計算される.固定ストップ損失は,ATR指標に基づいて同様の方法で計算される.

ロングまたはショートに行く後,固定ストップロスは最初のバーで有効になります.その後,主に移動ストップロストに切り替えます.この組み合わせはトレンドを追跡しながらいくつかの利益をロックします.

戦略は,ポジションサイズ計算のルールを定める.最大許容可能な損失パーセント,口座資本などに基づいて,適切なポジションサイズを計算する.また,取引機器の数を考慮し,それぞれの機器のポジションサイズを適切に減らす.

概要すると,これは典型的なトレンド追跡ブレイクアウト戦略です.ブレイクアウトが起きたと判断して,利益をロックし,ストップロスを通してトレンドを追跡し,トレンドが逆転すると終了します.

利点分析

この戦略の主な利点は以下の通りです.

  1. トレンドを正確に判断する.トレンドが逆転するかどうかを判断するために最高値と最低値を使用すると,正確性は非常に高く,誤った信号はほとんどありません.

  2. 合理的なポジションサイズとストップ損失. 最大損失パーセント設定,アカウント・エクイティアソシエーション等により,ポジションサイズが合理化され,過剰取引または非効率的な取引が避けられる. 組み合わせたストップ損失は利益をロックし,トレンド動きを追跡する.

  3. シンプルで実用的で 分かりやすく 基本的な指標だけで 論理は分かりやすく シンプルです

  4. 良い拡張性. インディケーターパラメータ,位置サイズ化ルールなど,すべてユーザーが必要に応じて調整するための入力ボックスを提供します.

概要すると これは非常に実用的な脱出戦略です 安全で信頼性の高い判断で 設計はリスク管理と追跡を考慮します 中長期保有に適しています

リスク分析

この戦略の主なリスクは,

  1. トレンド逆転リスク.ブレイクアウト戦略は,トレンド判断に大きく依存しており,もし間違った場合,大きな損失に直面する可能性があります.

  2. 不適切なパラメータリスク. 最高/最低価格サイクルパラメータが正しく選択されていない場合,トレンドが見逃される可能性があります. 不適切なポジションサイズのパラメータは過大損失につながる可能性があります.

  3. 過剰なストップ損失リスク. 移動ストップ損失距離が小さすぎると,市場の騒音はポジションを早急にノックアウトする可能性があります.

主な解決策は以下の通りです

  1. トレンドフィルターを追加します.例えば,誤ったブレイクをチェックするための追加指標です.

  2. 安定性試験を通じてパラメータ選択を最適化する.

  3. 合理的なリトレースに耐えられるようにストップ・ロスの距離を適正に緩める.

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

この戦略の主要な最適化方向は以下の通りである.

  1. 傾向を決定するためにより多くの指標を追加します.最高/最低価格に加えて,動平均のような指標も追加して傾向の決定をより正確にすることができます.

  2. パラメータ設定を最適化します. 最高/最低価格サイクル,ストップ損失倍数因数など,パラメータのための最適な組み合わせをテストし,見つけます.

  3. 市場状況に基づいてポジションサイズアルゴリズムを調整します.例えば,波動性 (例えばVIX) が上昇するときにポジションサイズを小さくします.

  4. 偽の突破を防ぐために 音量フィルターを追加します

  5. 取引手段を選択する際には,スプレッドと相関を考慮する.スプレッドの偏差が小さい,相関が低い手段を選ぶことは,ポートフォリオリスクを減らすことができます.

  6. ストップ・ロスのメカニズムを最適化する.ストップ・ロスを攻撃的でないようにするために,移動および固定ストップ・ロスの異なる組成をテストする.

結論

傾向を追跡するブレイクアウト戦略として,この戦略は判断の正確性,ポジションサイズ&リスク制御,操作の容易さなどでうまく機能します. 傾向を早期に把握し,移動ストップ損失を通じて利益と追跡をバランスします.

もちろん,ブレイクアウト戦略として,トレンド判断に大きく依存し,市場のノイズ干渉に易い.パラメータの調節が不十分であることもパフォーマンスを損なう可能性があります.これらの問題を解決するためにさらなる最適化が必要です.

基本構造は既に量子戦略にとって最も重要な構成要素を含んでいる.継続的な最適化と強化により,それは確実に安定した収益性の高い自動化された戦略になることができます. 量子が研究し参照するのに価値があります.


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

//@version=4
strategy(shorttitle="Trend Surfers - Breakout", title="Trend Surfers - Premium Breakout",
     overlay=true)

// Risk for position and pyramid
maxriskval = input(2, "Max % risk", type = input.float,
     tooltip="Risk % over total equity / Position", group = "Risk Management")
pairnumber = input(title = "How many pairs",type = input.integer, defval= 1,
     tooltip="How many pairs are you trading with the strategy?", group = "Risk Management")

// Emtry Exit
highPeriod = input(title="Highest High Period", type=input.integer, defval=168
     , tooltip="Highest High of X bars - This will trigger a Long Entry when close is above. (Thin Green Line)"
     , group = "Entry Condition")
lowPeriod = input(title="Lowest Low Period", type=input.integer, defval=168,
     tooltip="Lowest low of X bars - This will trigger a Short Entry when close is under. (Thin Red Line)"
     , group = "Entry Condition")
// Stoploss
trailingAtrPeriod = input(title="Trailing ATR Pediod", type=input.integer, defval=10,
     tooltip="Average True Range for the Trailing Stop. (Thick Green Line) "
     , group = "Exit Condition")
trailingAtrMultiplier = input(title="Trailing ATR Multiplier", type=input.float, defval=8
     , group = "Exit Condition")
fixAtrPeriod = input(title="Fix ATR Pediod", type=input.integer, defval=10,
     tooltip="Average True Range for the Fix Stoloss. (Thick Yellow Line)"
     , group = "Exit Condition")
fixAtrMultiplier = input(title="Fix ATR Multiplier", type=input.float, defval=2
     , group = "Exit Condition")
// Pair info 
pair = syminfo.basecurrency + syminfo.currency

// High Low Variable
highestHigh = highest(high, highPeriod)[1]
lowestLow = lowest(low, lowPeriod)[1]
trailingAtr = atr(trailingAtrPeriod) * trailingAtrMultiplier

// Trade Condition
longCondition = crossover(close, highestHigh) 
shortCondition = crossunder(close, lowestLow)

// Risk Variable
fixAtr = atr(fixAtrPeriod) * fixAtrMultiplier
stopvaluelong = close[1] - fixAtr[1]
stopvalueshort = close[1] + fixAtr[1]

// Position size Long
maxpossize = strategy.equity / close 
positionsizelong = ( ( ( (maxriskval/100) * strategy.equity) / (close - stopvaluelong))) 
stopperclong = ((close - stopvaluelong) / close) * 100
leveragelong = max(1, ceil(positionsizelong / maxpossize)) * 2
posperclong =  (((positionsizelong * close) / strategy.equity) *100 / leveragelong) / pairnumber
realposlong = (((posperclong / 100) * strategy.equity) * leveragelong) / close

// Position size Short
positionsizeshort = ( ( ( (maxriskval/100) * strategy.equity) / (stopvalueshort - close))) 
stoppercshort = ((close - stopvalueshort) / close) * 100
leverageshort = max(1, ceil(positionsizeshort / maxpossize)) * 2
pospercshort =  (((positionsizeshort * close) / strategy.equity) *100 / leverageshort) / pairnumber
realposshort = (((pospercshort / 100) * strategy.equity) * leverageshort) / close

// Alert Message
entry_long_message = '\nGo Long for ' + pair + 'NOW!' +
                     '\nPosition Size % =' + tostring(posperclong) +
                     '\nLeverage' + tostring(leveragelong) +
                     '\nStoploss Price =' + tostring(stopvaluelong) +
                     '\nClose any Short position that are open for ' + pair + '!' +
                     '\n\nVisit TrendSurfersSignals.com' +
                     '\nFor automated premium signals (FREE)'

entry_short_message ='\nGo Short for ' + pair + 'NOW!' +
                     '\nPosition Size % =' + tostring(pospercshort) +
                     '\nLeverage' + tostring(leverageshort) +
                     '\nStoploss Price =' + tostring(stopvalueshort) +
                     '\nClose any Long position that are open for ' + pair + '!' +
                     '\n\nVisit TrendSurfersSignals.com' +
                     '\nFor automated premium signals (FREE)'

exit_short_message = '\nExit Short for ' + pair + 'NOW!' +
                     '\n\nVisit TrendSurfersSignals.com' +
                     '\nFor automated premium signals (FREE)'

exit_long_message = '\nExit Long for ' + pair + 'NOW!' +
                     '\n\nVisit TrendSurfersSignals.com' +
                     '\nFor automated premium signals (FREE)'
// Order
if longCondition 
    strategy.entry("Long", strategy.long, stop=highestHigh, comment="Long", qty=realposlong
     , alert_message = entry_long_message)
if shortCondition
    strategy.entry("Short", strategy.short, stop=lowestLow, comment="Short", qty=realposshort
     , alert_message = entry_short_message)

// Stoploss Trailing
longTrailing = close - trailingAtr
shortTrailing = close + trailingAtr

var longTrailingStop = 0.0
var shortTrailingStop = 999999.9

trailingStopLine = 0.0
trailingStopLine := na
fixedStopLine = 0.0
fixedStopLine := na
var inTrade = 0
if longCondition or shortCondition
    if 0 == inTrade
        if longCondition
            inTrade := 1
        else
            inTrade := -1
if 1 == inTrade and (shortCondition or low <= max(fixedStopLine[1], longTrailingStop))
    inTrade := 0
if -1 == inTrade and (longCondition or high >= min(fixedStopLine[1], shortTrailingStop))
    inTrade := 0

longTrailingStop := if (1 == inTrade)
    stopValue = longTrailing
    max(stopValue, longTrailingStop[1])
else
    0

shortTrailingStop := if (-1 == inTrade)
    stopValue = shortTrailing
    min(stopValue, shortTrailingStop[1])
else
    999999

// Fix Stoploss
firstPrice = 0.0
firstFixAtr = 0.0
firstPrice := na
firstFixAtr := na
if 0 != inTrade
    firstPrice := valuewhen(inTrade != inTrade[1] and 0 != inTrade, close, 0)
    firstFixAtr := valuewhen(inTrade != inTrade[1] and 0 != inTrade, fixAtr, 0)
    if 1 == inTrade
        fixedStopLine := firstPrice - firstFixAtr
        trailingStopLine := longTrailingStop
    else
        fixedStopLine := firstPrice + firstFixAtr
        trailingStopLine := shortTrailingStop

if (strategy.position_size > 0)
    strategy.exit(id="L Stop", stop=max(fixedStopLine, longTrailingStop)
     , alert_message = exit_long_message)

if (strategy.position_size < 0)
    strategy.exit(id="S Stop", stop=min(fixedStopLine, shortTrailingStop)
     , alert_message = exit_long_message)
    

// Plot
plot(highestHigh, color=color.green, linewidth=1, transp=0, title='Highest High')
plot(lowestLow, color=color.red, linewidth=1, transp=0, title='Lowest Low')
plot(trailingStopLine, color=color.lime, linewidth=2, transp=0, offset=1, title='Trailing Stop')
plot(fixedStopLine, color=color.orange, linewidth=2, transp=0, offset=1, title='Fixed Stop')

もっと