ATRとブレイクアウトに基づくETF取引戦略

作者: リン・ハーンチャオチャン開催日:2023年12月26日16時05分55秒
タグ:

img

概要

これは,平均真差 (ATR) と価格ブレイクアウトをベースとしたETFアルゴリズム取引戦略である.これは,ストップ・ロストと利益レベルを計算し,価格が特定の期間の最高または最低価格を突破するとロングまたはショートポジションを開くためにATRを使用する.

戦略の論理

この戦略は主に以下の原則に基づいています.

  1. 特定の期間の最高値と最低値 (例えば20個のキャンドル) を用いて価格の傾向と方向性を決定する.価格が期間の最高値を突破するとロング,価格が最低値を突破するとショート.

  2. ストップ・ロスのレベルを動的に計算するためにATRを使用します.ストップ・ロスは,エントリー価格からATR値と係数 (例えば2) を掛け合わせたATR期間間の距離に置きます.

  3. ATR を使って取利益レベルを決定する.取利益は,入場価格から ATR 値と係数 (例えば 1) を掛ける距離に置く.

  4. ATRトレーラーマルチプリキュアを使用してストップ損失を追跡します.価格がトレーラーストップ損失レベルを不利な方向に突破したとき,ストップ損失でポジションを閉じます.

戦略はシンプルで信頼性があり, 価格動向のタイミングを把握するために価格動向の方向を考慮し, 利益とリスク管理のためにストップ・ロストとテイク・プロフィートを設定します.

利点分析

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

  1. 戦略の論理は シンプルで明快で 分かりやすく実行できます

  2. ATRを使用して,適応型ストップ損失と取利益レベルを計算すると,柔軟なポジションサイズとリスク管理ができます.

  3. ブレイクアウト戦略は 価格動向を把握し 良い収益をもたらします

  4. トレーラーストップ・ロスは ポジションを間に合うように閉じて 過剰な損失を避けることができます

  5. ETFや株式などの 明らかに傾向のある商品に適しています

リスク分析

戦略のリスクは以下のとおりです.

  1. 価格 konsolidiation の間,より多くの誤った信号と逆開が起こる可能性があります.

  2. パラメータの調節が不適切であれば,価格動向が欠落したり,不要な取引が多すぎたりする可能性があります.

  3. 極端なパラメータ値は,戦略の収益性に影響を与える,過剰に攻撃的または過剰に保守的なストップ・ロースと利益を取ることにつながることがあります.

  4. 政策リスクやプレミアムリスクなどのETFの潜在リスクも戦略の業績に影響を与えます.

対応する解法:

  1. 必要のない取引を減らすためにパラメータを最適化します
  2. 取引信号を確認するためにより多くの要素とフィルターを追加します.
  3. パラメータを異なる市場に対応して調整する
  4. 単一のETFの投資とコントロールポジションのサイズを多様化する.

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

戦略は次の側面からさらに最適化できます.

  1. 移動平均値のような指標を追加して 誤った信号をフィルタリングします

  2. 適応性パラメータ最適化モジュールを開発し,異なる期間や製品のためのパラメータを自動調節します.

  3. マシン学習モデルを採用して,次のキャンドルの最高値と最低値を予測し,ブレイクシグナルを決定します.

  4. 偽のブレイクを避けるために 取引量の過剰を考慮してください

  5. 初期ポジションのサイズとアロケーションの割合を,異なる製品と市場制度に適応して最適化する.

結論

この戦略は明確でシンプルな論理を持っています. ブレイクアウトと適応型ATRストップ損失/取利益のコアメカニズムは,リスクを効果的に制御し,利益をロックすることができます.パラメータ最適化やより多くのフィルターを統合することにより,利益因子とリスク制御能力をさらに強化することで,収益性と最適化可能な定量戦略になります.


/*backtest
start: 2023-12-18 00:00:00
end: 2023-12-21 03:00:00
period: 1m
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/
// © FX_minds

//@version=4
strategy("ETF tradedr", overlay=true, pyramiding=100, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

//------------------------------ get user input
lookback                   = input(title="HH LL lookback", type=input.integer, defval=20)
ATR_periode                = input(title="ATR period", type=input.integer, defval=14)
ATR_SL_multiplier          = input(title="ATR SL multiplier", type=input.float, defval=2)
ATR_TP_multiplier          = input(title="ATR TP multiplier", type=input.float, defval=1)
trailing_SL_ATR_multiplier = input(title="ATR trailing SL multiplier", type=input.float, defval=3.5)
lookback_trailing_SL       = input(title="trailing SL lookback", type=input.integer, defval=4)
max_sequel_trades          = input(title="max sequel trades", type=input.float, defval=1)
trade_long                 = input(title= "trade long ?", type=input.bool, defval=true)
trade_short                = input(title= "trade short ?", type=input.bool, defval=false)

//------------------------------ determine entry conditions
long_condition   = barstate.isconfirmed and crossover(high, highest(high, lookback)[1])
short_condition  = barstate.isconfirmed and crossunder(low, lowest(low, lookback)[1])


//------------------------------ count open long trades
count_open_longs = 0
count_open_longs := nz(count_open_longs[1])

if (long_condition) 
    count_open_longs := count_open_longs +1
    //label.new(bar_index, low, tostring(count_open_longs, "#"), xloc.bar_index, yloc.belowbar, color.green, label.style_none, color.green, size.large)

if (short_condition)
    count_open_longs := 0


//------------------------------ count open short trades
count_open_shorts = 0
count_open_shorts := nz(count_open_shorts[1])

if (short_condition)
    count_open_shorts := count_open_shorts +1
    //label.new(bar_index, low, tostring(count_open_shorts, "#"), xloc.bar_index, yloc.belowbar, color.red, label.style_none, color.red, size.large)

if (long_condition)
    count_open_shorts := 0


//------------------------------ calculate entryprice
entryprice_long = long_condition ? close : na
entryprice_short = short_condition ? close : na


//------------------------------ calculate SL & TP
SL_distance = atr(ATR_periode) * ATR_SL_multiplier
TP_distance  = atr(ATR_periode) * ATR_TP_multiplier
trailing_SL_distance = atr(ATR_periode) * trailing_SL_ATR_multiplier

SL_long = entryprice_long - SL_distance
SL_short = entryprice_short + SL_distance

trailing_SL_short = lowest(close, lookback_trailing_SL) + trailing_SL_distance
trailing_SL_long  = highest(close, lookback_trailing_SL) - trailing_SL_distance

trailing_SL_short_signal = crossover(high, trailing_SL_short[1])
trailing_SL_long_signal = crossunder(low, trailing_SL_long[1])


//------------------------------ plot entry price & SL  
plot(entryprice_long, style=plot.style_linebr, color=color.white)
plot(SL_long, style=plot.style_linebr, color=color.red)
plot(SL_short, style=plot.style_linebr, color=color.green)
plot(trailing_SL_short, style=plot.style_linebr, color=color.red)
plot(trailing_SL_long, style=plot.style_linebr, color=color.green)


//------------------------------ submit entry orders
if (long_condition) and (count_open_longs <= max_sequel_trades) and (trade_long == true)
    strategy.entry("Long" + tostring(count_open_longs, "#"), strategy.long)
    strategy.exit("SL Long"+ tostring(count_open_longs, "#"), 
     from_entry="Long" + tostring(count_open_longs, "#"), stop=SL_long)

if (short_condition) and (count_open_shorts <= max_sequel_trades) and (trade_short == true)
    strategy.entry("Short" + tostring(count_open_shorts, "#"), strategy.short)
    strategy.exit("SL Short" + tostring(count_open_shorts, "#"), 
     from_entry="Short" + tostring(count_open_shorts, "#"), stop=SL_short)
    

//------------------------------ submit exit conditions
if (trailing_SL_long_signal)
    strategy.close("Long" + tostring(count_open_longs, "#"))
    strategy.close("Long" + tostring(count_open_longs-1, "#"))
    strategy.close("Long" + tostring(count_open_longs-2, "#"))
    strategy.close("Long" + tostring(count_open_longs-4, "#"))
    strategy.close("Long" + tostring(count_open_longs-5, "#"))
    strategy.close("Long" + tostring(count_open_longs-6, "#"))
    strategy.close("Long" + tostring(count_open_longs-7, "#"))
    strategy.close("Long" + tostring(count_open_longs-8, "#"))
    strategy.close("Long" + tostring(count_open_longs-9, "#"))
    
if (trailing_SL_short_signal)
    strategy.close("Short" + tostring(count_open_shorts, "#"))
    strategy.close("Short" + tostring(count_open_shorts-1, "#"))
    strategy.close("Short" + tostring(count_open_shorts-2, "#"))
    strategy.close("Short" + tostring(count_open_shorts-3, "#"))
    strategy.close("Short" + tostring(count_open_shorts-4, "#"))
    strategy.close("Short" + tostring(count_open_shorts-5, "#"))
    strategy.close("Short" + tostring(count_open_shorts-6, "#"))
    strategy.close("Short" + tostring(count_open_shorts-7, "#"))
    strategy.close("Short" + tostring(count_open_shorts-8, "#"))
    strategy.close("Short" + tostring(count_open_shorts-9, "#"))



もっと