ADX+RSI戦略

作者: リン・ハーンチャオチャン, 日時: 2023-09-27 16:27:39
タグ:

概要

ADXとRSIを組み合わせたトレンドフォロー戦略である.これは,トレンドが不明確であるときにトレードをフィルタリングするトレンドを決定するためにRSIを使用して,トレード信号を生成するために過剰購入および過剰販売レベルを特定し,範囲限定市場でのウィプソウを回避する.

戦略の論理

  1. 7 期間の RSI を使って,過剰購入と過剰販売のレベルを特定する
  • RSIが30以下である場合は過売れとみなされます.
  • RSIが70を超えると過買いとされます.
  1. ADX を使ってトレンドを判定する
  • ADXが30を超えると強い傾向を示唆している
  • ADXが30を下回ると,傾向がない.
  1. 入国規則
  • RSI < 30 と ADX > 30 の場合
  • RSI > 70 と ADX > 30 のときショート
  1. 利益とストップ損失
  • 選択的得益とストップ・損失方法 - 閉機またはスウィングベースの方法
  • 密着型用途 閉店価格
  • 振動ベースの利用 最近の振動高位/低位

利点分析

  1. RSI は,買い/売りの罠を避けるために,過剰購入と過剰販売レベルを効果的に識別します.

  2. ADXは,波動を避けるために範囲限定市場をフィルタリングします

  3. 任意の取利益/ストップ損失方法によりリスクの管理が改善されます

  4. シンプルで理解しやすい アルゴリズム取引を学ぶ初心者にとって良い

  5. パラメータの最適化と精製のための多くの余地

リスク分析

  1. RSI の 買い過ぎ/売り過ぎ は 引き下げ と 逆転 が 起こり ます.

  2. ADXのトレンド決定は遅延し,トレンドターニングポイントを見逃す可能性があります

  3. 誤ったストップ損失の配置は損失につながる可能性があります.

  4. 単純化による過度に最適化されるリスク

  5. より良いパフォーマンスのために必要なパラメータ最適化

オプティマイゼーションの方向性

  1. RSI パラメータと過買い/過売りレベルを最適化

  2. 最適な設定を見つけるために異なるADX期間をテスト

  3. 異なる取利益/停止損失方法をテストする

  4. 逆トレンド取引を避けるためにトレンドフィルターを追加する

  5. 性能向上のために他の指標と組み合わせる

概要

この戦略は,トレンドを特定し,ウィップソーを避けるためにクラシックなRSIとADX指標の強みを組み合わせます.より良いパフォーマンスを達成するために最適化する余地があります.全体として,それは初心者の導入アルゴリズム取引戦略としてよく機能し,より複雑な取引システムにも組み込める可能性があります.


/*backtest
start: 2023-09-19 00:00:00
end: 2023-09-26 00:00:00
period: 15m
basePeriod: 5m
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/
// © tweakerID

// This is a strategy that uses the 7 Period RSI to buy when the indicator is shown as oversold (OS) and sells when 
// the index marks overbought (OB). It also uses the ADX to determine whether the trend is ranging or trending
// and filters out the trending trades. Seems to work better for automated trading when the logic is inversed (buying OB 
// and selling the OS) wihout stop loss.

//@version=4
strategy("ADX + RSI Strat", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=100, commission_value=0.04, calc_on_every_tick=false)

direction = input(0, title = "Strategy Direction", type=input.integer, minval=-1, maxval=1)
strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))


//SL & TP Inputs
i_SL=input(false, title="Use Swing Lo/Hi Stop Loss & Take Profit")
i_SwingLookback=input(20, title="Swing Lo/Hi Lookback")
i_SLExpander=input(defval=0, step=.2, title="SL Expander")
i_TPExpander=input(defval=0, step=.2, title="TP Expander")
i_reverse=input(true, title="Reverse Trades")

//SL & TP Calculations
SwingLow=lowest(i_SwingLookback)
SwingHigh=highest(i_SwingLookback)
bought=strategy.position_size != strategy.position_size[1]
LSL=valuewhen(bought, SwingLow, 0)-((valuewhen(bought, atr(14), 0))*i_SLExpander)
SSL=valuewhen(bought, SwingHigh, 0)+((valuewhen(bought, atr(14), 0))*i_SLExpander)
lTP=strategy.position_avg_price + (strategy.position_avg_price-(valuewhen(bought, SwingLow, 0))+((valuewhen(bought, atr(14), 0))*i_TPExpander))
sTP=strategy.position_avg_price - (valuewhen(bought, SwingHigh, 0)-strategy.position_avg_price)-((valuewhen(bought, atr(14), 0))*i_TPExpander)
islong=strategy.position_size > 0
isshort=strategy.position_size < 0
SL= islong ? LSL : isshort ? SSL : na
TP= islong ? lTP : isshort ? sTP : na

//RSI Calculations
RSI=rsi(close, 7)
OS=input(30, step=5)
OB=input(80, step=5)

//ADX Calculations
adxlen = input(14, title="ADX Smoothing")
dilen = input(14, title="DI Length")
dirmov(len) =>
	up = change(high)
	down = -change(low)
	plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
	minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
	truerange = rma(tr, len)
	plus = fixnan(100 * rma(plusDM, len) / truerange)
	minus = fixnan(100 * rma(minusDM, len) / truerange)
	[plus, minus]
adx(dilen, adxlen) =>
	[plus, minus] = dirmov(dilen)
	sum = plus + minus
	adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
sig = adx(dilen, adxlen)
adxlevel=input(30, step=5)


//Entry Logic
BUY = sig < adxlevel and (RSI < OS) 
SELL = sig < adxlevel and (RSI > OB) 

//Entries
strategy.entry("long", strategy.long, when=i_reverse?SELL:BUY)
strategy.entry("short", strategy.short, when=not i_reverse?SELL:BUY)
//Exits
if i_SL
    strategy.exit("longexit", "long", stop=SL, limit=TP)
    strategy.exit("shortexit", "short", stop=SL, limit=TP)

//Plots
plot(i_SL ? SL : na, color=color.red, style=plot.style_cross, title="SL")
plot(i_SL ? TP : na, color=color.green, style=plot.style_cross, title="TP")
plotshape(BUY ? 1 : na, style=shape.triangleup, location=location.belowbar, color=color.green, title="Bullish Setup")
plotshape(SELL ? 1 : na, style=shape.triangledown, location=location.abovebar, color=color.red, title="Bearish Setup")

もっと