移動平均とウィリアムズ指標に基づく日次戦略


作成日: 2024-01-29 14:35:48 最終変更日: 2024-01-29 14:35:48
コピー: 1 クリック数: 639
1
フォロー
1617
フォロワー

移動平均とウィリアムズ指標に基づく日次戦略

概要

この戦略は,平均線,ATR指数およびウィリアム指数を使用して,GBP/JPYの外貨品種に対して日線レベルの取引を行う.戦略は,価格の傾向と可能な逆転点を平均線から判断し,その後,ウィリアム指数を使用して取引信号をさらに確認し,ATR指数を使用してストップ・損失と取引量を計算します.

戦略原則

  1. 20日線の平均線 ((ベースライン) を用いて価格の全体的な傾向を判断する.価格は平均線の下から買い信号として掃描し,平均線上から下から売り信号として破る
  2. ウィリアム指数は,価格の逆転を確認するために使用される.指数は,35を突破すると買いを確認し,70を突破すると売りを確認する.
  3. ATR指標は,過去2日の平均波動範囲を計算する. この値は,係数で掛けて,止損距離に設定する.
  4. 口座権益の50%に応じてリスクコントロールを行う.取引量は,ストップ・ロスト・ディスタンスとリスクの比率に従って計算される.
  5. 長期ポジションに入ると,ストップポイントは価格の低点に減算され,ストップポイントはエントリーポイントに100ポイント加算されます. 退出シグナルをさらに確認するために,Exiting logicを使用します.
  6. ショートポジションに入ると,ストップとストップが同期する. 退出信号をさらに確認するために,Exiting logicを使用する.

優位分析

  1. 平均線判断のトレンドとインチケーターの統合使用により,偽突破による損失を効果的にフィルタリングできます.
  2. ATRのダイナミックストップは,市場の波動量に応じて合理的なストップ距離を設定できます.
  3. リスク管理とダイナミックな取引量計算により,単一損失を最大限に抑えることができます.
  4. Exiting logicと均線判断は,退出のタイミングをさらに確認し,早期の停滞を回避します.

リスク分析

  1. 平均線判断は誤信号を生成する確率が高いため,指標のさらなる確認が必要である.
  2. また,指数自体が誤った信号を発し,損失を完全に回避することはできません.
  3. この戦略は,トレンド品種に適しており,範囲の変動品種には効果が悪くなる可能性があります.
  4. リスク管理の不適切な割合設定は,戦略的収益にも影響を及ぼします.

平均線周期の調整,より多くの指標の組み合わせ,または人工介入取引などの方法によってさらに最適化および改善することができます.

要約する

この戦略は,トレンド判断と指標フィルタリングを組み合わせ,GBP/JPY日線レベルの取引に対して方法設計する。同時に,ダイナミックストップ,リスクコントロールなどの手段を用いて取引リスクを制御する。最適化余地が広く,パラメータ調整と方法の組み合わせにより戦略効果をさらに改善することができる。

ストラテジーソースコード
/*backtest
start: 2023-12-29 00:00:00
end: 2024-01-28 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy("GBPJPY DAILY FX",initial_capital = 1000,currency="USD", overlay=true)

UseHAcandles    = input(false, title="Use Heikin Ashi Candles in Algo Calculations")
//
// === /INPUTS ===

// === BASE FUNCTIONS ===

haClose = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period, close) : close
haOpen  = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period, open) : open
haHigh  = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period, high) : high
haLow   = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period, low) : low

//INDICATOR---------------------------------------------------------------------    
    //Average True Range (1. RISK)
atr_period = 2
atr = atr(atr_period)



    //Ichimoku Cloud - Kijun Sen (2. BASELINE)
ks_period = 20
kijun_sen = (highest(haHigh,ks_period) + lowest(haLow,ks_period))/2
base_long = haOpen < kijun_sen and haClose > kijun_sen
base_short = haOpen > kijun_sen and haClose < kijun_sen

    //Williams Percent Range (3. Confirmation#1)
use_wpr = true
wpr_len = 4
wpr = -100*(highest(haHigh,wpr_len) - haClose)/(highest(haHigh,wpr_len) - lowest(haLow,wpr_len))
wpr_up = -35
wpr_low = -70
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 = haClose < 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 = haClose > kijun_sen
    
strategy.initial_capital = 50000
//MONEY MANAGEMENT--------------------------------------------------------------
balance = strategy.netprofit + strategy.initial_capital //current balance
floating = strategy.openprofit          //floating profit/loss
isTwoDigit = input(true,"Is this a 2 digit pair? (JPY, XAU, XPD...")
risk = input(50,"Risk %")/100           //risk % per trade
equity_protector = input(30,"Equity Protection %")/100  //equity protection %
stop = atr*100000*input(1,"Average True Range multiplier")    //Stop level
if(isTwoDigit)
    stop := stop/100
target = input(100, "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 < 1)
    size := 1            //Set min. lot size

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

fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
fromYear = input(defval = 2000, title = "From Year", minval = 1970)
 //monday and session 
// To Date Inputs
toDay = input(defval = 31, title = "To Day", minval = 1, maxval = 31)
toMonth = input(defval = 12, title = "To Month", minval = 1, maxval = 12)
toYear = input(defval = 2021, title = "To Year", minval = 1970)

startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)
finishDate = timestamp(toYear, toMonth, toDay, 00, 00)
time_cond = true

if(time_cond)
    strategy.entry("l_en",true,1,oca_name="a",when=l_en and not is_open)  //Long entry
    strategy.entry("s_en",false,1,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)