ADX + RSI 전략

저자:차오장, 날짜: 2023-09-27 16:27:39
태그:

전반적인 설명

이것은 ADX와 RSI 지표를 결합한 트렌드를 따르는 전략입니다. 그것은 거래 신호를 생성하기 위해 과소매와 과소매 수준을 식별하기 위해 RSI를 사용하고, 트렌드가 불분명할 때 트레이드를 필터링하는 트렌드를 결정하기 위해 ADX를 사용하여 범위 시장에서 위프스를 피합니다.

전략 논리

  1. 7주기 RSI를 사용하여 과반 구매 및 과반 판매 수준을 식별
  • 30 이하의 RSI는 과판된 것으로 간주됩니다.
  • 70 이상인 RSI는 과잉 매입된 것으로 간주됩니다.
  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")

더 많은