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


作成日: 2023-12-26 16:05:55 最終変更日: 2023-12-26 16:05:55
コピー: 2 クリック数: 822
1
フォロー
1623
フォロワー

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

概要

この戦略は,平均リアル波幅 (ATR) と価格突破に基づくETF自動取引戦略である.これは,ATRを使用して,ストロップとストップオフを計算し,価格が一定の周期の高値または低値を破るとき,ポジションをオーバーまたはダウンする.

戦略原則

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

  1. 価格の動きと方向を判断するために,特定の周期 (例えば20根K線) の最高値と最低値を使用します. 価格が周期最高値を破るとき,多めにしてください. 価格が周期最低値を破るとき,空いてください.

  2. ATR を動的に使用してストップ・ローズを計算する. 入場価格からストップ・ローズまでのATR サイクルのATR 値は ((2) の係数で掛ける.

  3. ATR を使って,ストップを計算する. ストップ距離の入場価格をATR 周期のATR 値に係数 ((如1)) を掛ける.

  4. ATRtrailer多因子を用いてストップを追跡する.価格が不利な方向にトレーラーストップを突破すると,平仓ストップする.

この戦略はシンプルで信頼性があり,価格の傾向の方向を考慮し,価格の傾向をタイムリーに捉えるのに役立ちます. また,利益の機会を把握し,リスクを制御するのに役立つストップ・ロスとストップ・ポジションを設定します.

優位分析

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

  1. 戦略はシンプルで明快で,理解し,実行しやすい.

  2. ATRを使用して,ストップ・ストップ・ローズを計算し,ポジションの規模を動的に調整し,リスクを柔軟に制御できます.

  3. サイクルブレイク判断策略は価格トレンドを容易に捉え,収益が優れている.

  4. トレーラー・ストップは,危険を回避するために,早期にストップすることができます.

  5. ETF,株式など,傾向が顕著な品種に適用されます.

リスク分析

この戦略には以下のリスクもあります.

  1. 価格が揺れると,誤ったシグナルや反発が多く発生する可能性があります.

  2. 周期パラメータの設定が不適切である場合,価格トレンドを逃したり,空想の取引回数が多すぎたりすることがあります.

  3. 配数パラメータの設定が不適切で,止損やストップが過度に過激または保守的になり,利益に影響を与える可能性があります.

  4. 政策リスク,プレミアムリスクなどのETF自体のリスクも戦略に影響を与える.

対応方法:

  1. 仮想取引率を下げるためのパラメータの最適化.
  2. 複数の要素とフィルターを組み合わせて取引信号を決定する.
  3. 市場によってパラメータを調整する.
  4. 分散投資は,ETFの単一のポジションを制御する.

最適化の方向

この戦略は,以下の点でさらに最適化できます.

  1. 移動平均線などの指標を組み合わせて偽信号をフィルターします.

  2. 適応性パラメータ最適化モジュールを追加し,異なる周期と品種に応じてパラメータを自動的に最適化します.

  3. 突破信号を判断するために,次のK線の高点と低点を予測する機械学習モデルを追加します.

  4. 取引量溢れなどの指標を考慮し,偽突破を防止する.

  5. 倉庫開設のポジションのサイズと割合を最適化し,異なる品種と市場環境への適応性を開設する.

要約する

この戦略の全体的な考え方は明快で簡潔で,核心機構の突破とATRのダイナミックストップ・ストップ・ロスは,リスクを効果的に制御し,利益をロックすることができます.パラメータの最適化とより多くのフィルタリング指標を組み合わせることで,戦略のProfit因子とリスク制御能力をさらに強化することができます.これは入手し,継続的に最適化する価値のある量化戦略です.

ストラテジーソースコード
/*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, "#"))