ATRストップロスに基づく一目均衡表戦略


作成日: 2023-09-14 20:06:11 最終変更日: 2023-09-14 20:06:11
コピー: 2 クリック数: 874
1
フォロー
1617
フォロワー

この記事では,ATRをストップとして,均線を入場として使用する量化取引戦略について詳しく説明する.この戦略は,取引リスクを制御するために,ウィリアム指数と組み合わせて信号検証を行う.

戦略の原則

この戦略の核心指標は以下の通りです.

  1. ATRは,市場変動を動的に反映するストップ・ローズ・インジケーターです.

  2. 平均線は,トレンドの方向を判断する入場信号を提供する.

  3. ウィリアム指数は,偽入学を避けるために,追加で検証されます.

取引の論理は以下の通りです.

価格が初等均衡線を下げて後戻しをするときは,多めにすること.価格が平均線を突破して後戻しをするときは,空白すること.これはトレンド追跡を行うことができる.

また,ウィリアム指数が方向と一致しているかどうかをチェックし,一致しない場合は入場を放棄する.これは偽信号をフィルターすることができます.

各入場時に,ATRで計算されたストップ・ロスを設定する.ATRは,市場の波動程度を動的に反映し,合理的なストップ・ロスを設定する.

ストップ・ローズまたはストップ・ストップレベルが触発されたとき,平仓は利潤となる.

2 戦略的優位性

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

第一に,ATRの止損は,市場変動によるリスクコントロールを設定することで,大きな損失を効果的に回避できます.

第二に,均線入場は,ウィリアム指標の検証と組み合わせて,信号の質を向上させることができる.

最後に,ストップ・ロスト・ストップ設定は,各取引に定義されたリスク・リターンを与えます.

3 潜在的リスク

しかし,以下のようなリスクも考慮すべきです.

まず,トレンドが変化したときに,均線信号が遅れて,適切なタイミングで反応することができない.

第二に,過剰な激進的な停止は,停止の破綻につながる可能性がある.

最後に,パラメータの最適化が不適切であることも,過適合を引き起こす可能性があります.

内容と要約

この記事では,ATRを止損と均等な入場としてベースとする定量取引戦略について詳しく説明します. これは,動的止損と信号フィルタリングによって良いリスク管理効果を実現できます. しかし,トレンド突破や止損が突破されるなどの問題を防ぐこともできます. 全体的に,この戦略は,シンプルで効果的なトレンド追跡方法を提供します.

ストラテジーソースコード
/*backtest
start: 2023-09-06 00:00:00
end: 2023-09-13 00:00:00
period: 15m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
// strategy("NNFX ft. ATR, Kijun-Sen, %R","NNFX-2",true,pyramiding=1,calc_on_order_fills=true,calc_on_every_tick=true,initial_capital = 1000, currency="USD",slippage=5,commission_type=strategy.commission.cash_per_contract,commission_value=0.000035)
strategy.initial_capital = 50000    
//INDICATOR---------------------------------------------------------------------    
    //Average True Range (1. RISK)
atr_period = input(14, "Average True Range Period")
atr = atr(atr_period)

    //Ichimoku Cloud - Kijun Sen (2. BASELINE)
ks_period = input(20, "Kijun Sen Period")
kijun_sen = (highest(high,ks_period) + lowest(low,ks_period))/2
base_long = open < kijun_sen and close > kijun_sen
base_short = open > kijun_sen and close < kijun_sen

    //Williams Percent Range (3. Confirmation#1)
use_wpr = input(true,"Use W%R?")
wpr_len = input(1, "Williams % Range Period")
wpr = -100*(highest(high,wpr_len) - close)/(highest(high,wpr_len) - lowest(low,wpr_len))
wpr_up = input(-25, "%R Upper Level")
wpr_low = input(-75, "%R Lower Level")
conf1_long = wpr >= wpr_up
conf1_short = wpr <= wpr_low
if(use_wpr == false)
    conf1_long := true
    conf1_short := true
//TRADE LOGIC-------------------------------------------------------------------
    //Long Entry
    //if -> WPR crosses below -39 AND MACD line is less than signal line
l_en = base_long and conf1_long
    //Long Exit
    //if -> WPR crosses above -14
l_ex = close < kijun_sen
    //Short Entry
    //if -> WPR crosses above -39 AND MACD line is greater than signal line
s_en = base_short and conf1_short
    //Short Exit
    //if -> WPR crosses under -14
s_ex = close > kijun_sen
    
//MONEY MANAGEMENT--------------------------------------------------------------
balance = strategy.netprofit + strategy.initial_capital //current balance
floating = strategy.openprofit          //floating profit/loss
isTwoDigit = input(false,"Is this a 2 digit pair? (JPY, XAU, XPD...")
risk = input(5,"Risk %")/100           //risk % per trade
equity_protector = input(30,"Equity Protection %")/100  //equity protection %
stop = atr*100000*input(1.5,"Average True Range multiplier")    //Stop level
if(isTwoDigit)
    stop := stop/100
target = input(150, "Target TP in Points")  //TP level
    //Calculate current DD and determine if stopout is necessary
equity_stopout = false
if(floating<0 and abs(floating/balance)>equity_protector)
    equity_stopout := true
    
    //Calculate the size of the next trade
temp01 = balance * risk     //Risk in USD
temp02 = temp01/stop        //Risk in lots
temp03 = temp02*100000      //Convert to contracts
size = temp03 - temp03%1000 //Normalize to 1000s (Trade size)
if(size < 1000)
    size := 1000            //Set min. lot size

//TRADE EXECUTION---------------------------------------------------------------
strategy.close_all(equity_stopout)      //Close all trades w/equity protector
is_open = strategy.opentrades > 0

if(true)
    strategy.entry("l_en",true,oca_name="a",when=l_en and not is_open)  //Long entry
    strategy.entry("s_en",false,oca_name="a",when=s_en and not is_open) //Short entry
    
    strategy.exit("S/L","l_en",loss=stop, profit=target)      //Long exit (stop loss)
    strategy.close("l_en",when=l_ex)            //Long exit (exit condition)
    strategy.exit("S/L","s_en",loss=stop, profit=target)      //Short exit (stop loss)
    strategy.close("s_en",when=s_ex)            //Short exit (exit condition)
    
//PLOTTING----------------------------------------------------------------------
plot(kijun_sen,"Kijun-Sen",color.blue,2)