移動平均値とウィリアムズ指標に基づいた日々のFX戦略

作者: リン・ハーンチャオチャン開催日:2024年1月29日 (月) 14:35:48
タグ:

img

概要

この戦略は,移動平均値,ATR指標,およびウィリアムズ指標を組み合わせて,日々のFX取引を行う.まず移動平均値を通じて価格動向と潜在的な逆転点を判断し,その後,トレーディング信号をさらに確認するためにウィリアムズ指標を使用し,ストップ損失とポジションサイズを計算するためにATR指標を利用する.

戦略の論理

  1. 20日間の移動平均線 (ベースライン) を用いて全体的な傾向を決定します.価格が下から上へと横切るのは購入信号で,上から下へと横切るのは販売信号です.
  2. ウィリアムズ指標は,価格逆転を確認するために使用されます.指標が -35を超えると購入の確認になります. -70を下回ると販売の確認です.
  3. ATR インディケーターは,過去2日間の価格範囲の平均を計算します.因数で掛けられた値はストップ・ロスの距離として設定されます.
  4. ポジションのサイズは,口座資本の50%のリスクに基づいています.取引サイズは,ストップ損失距離とリスクパーセントに基づいて計算されます.
  5. ロングポジションに入ると,ストップロスは低価格マイナスストップロスの距離に設定される. 利益を取ることはエントリー価格プラス100ポイントに設定される. 退出ロジックはさらに出口信号を確認する.
  6. 同じようにショートポジションでは,ストップ・ロストとテイク・プロフィートが同じ方法で設定されます.出口論理も出口を確認するために使用されます.

利点分析

  1. 移動平均値によるトレンド判断と指標による確認を組み合わせることで,誤ったブレイクによる損失を効果的に回避できます.
  2. ATRによる動的ストップ損失は,市場の変動に基づいて合理的なストップ距離を設定できます.
  3. リスク管理とダイナミックなポジションサイズ化により,単一の取引損失を最大限にコントロールできます.
  4. アクジットロジックと移動平均を組み合わせることで,良いアウトジットタイミングをさらに確認し,早急な利益を取ることを避けるのに役立ちます.

リスク分析

  1. 移動平均信号は誤りがある可能性が高く,指標からのさらなる確認が必要である.
  2. インディケーター自体も 誤った信号を生成し 損失を完全に回避することができません
  3. この戦略は,トレンドペアにうまく適応しますが,レンジバインドペアでは結果が悪くなります.
  4. 不適切なリスクコントロール比設定も戦略の収益性に影響を与えます

移動平均期間の調整,より多くの指標の組み合わせ,手動的介入などの方法により戦略をさらに最適化し改善することができます.

結論

この戦略は,トレンド判断とインジケーターフィルターを組み合わせて日々の取引を行う.また,ダイナミックストップ・ロスト,リスクコントロール,および他の手段を活用して取引リスクを制御する.戦略のパフォーマンスをさらに向上させるために,パラメータチューニングと方法の組み合わせによって最適化する余地が多く存在する.


/*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)


もっと