NA0TA

RSIのダイバージェンス-システム

OANDA:NZDJPY   Dollar Néo-Zélandais / Yen Japonais
NZDJPY
マーケットの魔術師:システムトレーダー編でトム・デマークがインタビューで
RSIなどのオシレータは絶対値よりもダイバージェンスが発生した時に意味があると言ってたので検証してみました。

NZD/JPYの8時間足で2015年から現在までの期間でスリッページは5pipsでバックテスト。
ピボットハイポイントが発生したら過去10本のバーの高値より高いか判定。
ピボットローポイントが発生したら過去10本のバーの安値より低いか判定。
これらをシグナル1に設定します。

RSIは10期間で計算
シグナル1がtrueの時でピボットハイポイントが発生した時に過去10本のバーのRSIより低いか判定。
シグナル1がtrueの時でピボットローポイントが発生した時に過去10本のバーのRSIより高いか判定。
これらの条件がダイバージェンスの発生とみなし、シグナル2に設定します。

シグナル1、シグナル2の条件が揃ったときに売買シグナルをトリガーして次のバーで成行で執行。
ピボットローのダイバージェンスでロングエントリー
ピボットハイのダイバージェンスでショートエントリー

ロングポジションを取っている時:
終値が仕掛け値から1ATR以上で過去20本のバーの90パーセンタイルをトレイリングストップ
過去5本のバーの最高値と最安値の値幅の2倍を仕掛け値から逆指値でロスストップ
過去5本のバーの最高値と最安値の値幅の5倍を仕掛け値から指値でターゲットオーダー
ショートポジションはこの逆とします。

そして、(ATR×為替レート×取引通貨単位)の200日間の最高値で保有資産の2%を割った数でポジションサイジング

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
strategy("test3", shorttitle="test3", initial_capital=1000000, currency="JPY",
overlay=true, slippage=50, commission_type =strategy.commission.cash_per_order, commission_value=0)
po_sizin = input(false, type=input.bool)
htR = input(defval=4000, title="HTR" ,step=1000 ,minval=1000)
atr_pct = input(defval=2, title="係数X" ,step=1 ,minval=1, maxval=30)

atr_tget = input(false, type=input.bool)
atr_tg = input(5, "ターゲットポイント", step=0.5, minval=1)
atr_stopLoss = input(false, type=input.bool)
atr_stop = input(2, "ロスポイント", step=0.5, minval=1)

sc1(currency) =>
currency=="JPY" ? 1 :
currency=="USD" ? security("usdjpy" ,"D" ,close) :
currency=="AUD" ? security("audjpy" ,"D" ,close) :
currency=="GBP" ? security("gbpjpy" ,"D" ,close) :
na

revareg = 25
unit_val_src = strategy.initial_capital + strategy.netprofit
unit_val = unit_val_src * unit_val_pct * 0.01
max_amoN = floor((unit_val_src - unit_val * 1.1) / (close / revareg ) / lot) * lot
max_amo = max_amoN == 0 ? lot*1 : max_amoN

amount_setN = floor( unit_val_src * atr_pct*0.01 / htR) * lot
amount_set = amount_setN == 0 ? lot*1 : amount_setN
amount = amount_set < max_amo ? amount_set : max_amo

p_len = input(10, title="ルックバック", step=5, minval=5, maxval=50)
ph = pivothigh(1,1)
pl = pivotlow(1,1)

h_cond = not na(ph)
le = false
le := h_cond ? true : false

l_cond = not na(pl)
se = false
se := l_cond ? true : false

PH_go = le and rising(high, p_len)
PL_go = se and falling(low, p_len)

//RSIフィルター
RSI = rsi(close, 10)
rsHD = PH_go and falling(RSI, p_len)
reLD = PL_go and rising(RSI, p_len)
//買いシグナル△
LONG_SIGNAL = reLD and vof_on and F_on
//売りシグナル▽
SHORT_SIGNAL = rsHD and vof_on and F_on

strategy.close("買い", when = parcentile == true and close > strategy.position_avg_price + atr * 1 ?
crossunder(hlc3, percentile_nearest_rank(hlc3, pa_len, stop_pa)) : na)
strategy.close("売り", when = parcentile == true and close < strategy.position_avg_price - atr * 1 ?
crossover(hlc3, percentile_nearest_rank(hlc3, pa_len, 100 - stop_pa)) : na)

hl_tL = strategy.position_avg_price + (highest(high, 5) - lowest(low, 5))*hl_PT
hl_tS = strategy.position_avg_price - (highest(high, 5) - lowest(low, 5))*hl_PT
strategy.exit("TG2","買い", limit = re_su == true ? hl_tL : na)
strategy.exit("TG2","売り", limit = re_su == true ? hl_tS : na)
strategy.cancel("TG2", strategy.openprofit < 0 or re_su == false or atr_tget == true)

hl_tL2 = strategy.position_avg_price - (highest(high, 5) - lowest(low, 5))*hl_PT2
hl_tS2 = strategy.position_avg_price + (highest(high, 5) - lowest(low, 5))*hl_PT2
strategy.close("買い", when = re_su2 == true ? crossunder(close, hl_tL2) : na)
strategy.close("売り", when = re_su2 == true ? crossover(close, hl_tS2) : na)
Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.