볼링거 밴드, RSI, ADX 및 ATR를 이용한 반전 거래 전략

저자:차오장, 날짜: 2024-02-21 14:13:47
태그:

img

전반적인 설명

이 전략은 여러 가지 기술 지표를 통합합니다. 볼링거 밴드 지표가 RSI, ADX 및 ATR 지표에서 시장 구조에 대한 판단과 결합하여 가격 반전 신호를 생성 할 때 높은 확률의 반전 거래 기회를 찾습니다.

전략 논리

  1. 20주기 볼링거 밴드를 사용해서 가격이 밴드 최고 또는 최저에 도달할 때 반전 촛불 패턴을 기다립니다.

  2. RSI 지표는 시장이 범위 모드에 있는지 판단합니다. RSI는 60 이상으로 상승 범위를 나타내고 40 이하의 하락 범위를 나타냅니다.

  3. 20 이하의 ADX는 시장의 폭을 나타내고, 20 이상은 트렌드 상태를 나타냅니다.

  4. ATR은 스톱 손실을 설정하고 후속 스톱 손실을 설정합니다.

  5. EMA 라인의 추가 필터.

이점 분석

  1. 여러 지표가 결합되면 높은 확률의 거래 신호를 제공합니다.

  2. 구성 가능한 매개 변수는 다른 시장 환경에 적응합니다.

  3. 엄격한 스톱 로스 규칙은 위험을 효과적으로 제어합니다.

위험 분석

  1. 부적절한 매개 변수 설정은 과도한 거래로 이어질 수 있습니다.

  2. 반전 실패의 가능성은 여전히 존재합니다.

  3. 트레이일링 스톱 손실은 특정 시장에서 실패할 수 있습니다.

최적화 방향

  1. 더 나은 매개 변수 구성을 찾기 위해 더 많은 지표 조합을 테스트합니다.

  2. 초기 실패 후에도 재개할 수 있는 기회를 적시에 파악합니다.

  3. 다른 스톱 손실 방법을 테스트하여 더 지능적인 스톱을 만들 수 있습니다.

결론

이 전략은 핵심 거래 신호를 위해 볼링거 밴드를 사용하며 여러 보조 지표가 높은 확률의 필터링 시스템을 형성합니다. 스톱 로스 규칙도 상당히 완전합니다. 매개 변수 조정 및 지표 최적화로 더 많은 성능 향상을 달성 할 수 있습니다. 전반적으로이 전략은 신뢰할 수있는 반전 거래 시스템을 형성합니다.


/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy(shorttitle="BB + EMA + RSI + ADX + ATR Reversal", title="Bollinger Bands Reversal", overlay=true)

// Inputs
ema1Input       = input(title = "EMA1 Input",                          defval = 200,   minval = 10,    maxval = 400,   step = 10,                      group = "Indicators")
ema2Input       = input(title = "EMA2 Input",                          defval = 100,   minval = 10,    maxval = 400,   step = 10,                      group = "Indicators")
length          = input(title = "BB Length",                           defval = 20,    minval=1,                                                       group = "Bollinger Band Indicator")
bbsrc           = input(title = "BB Source",                            defval = close,                                                                 group = "Bollinger Band Indicator")
mult            = input(title = "BB Standard Deviation",            type = input.float,     defval = 2.0,   minval=0.001,   maxval=50,                                      group = "Bollinger Band Indicator")
offset          = input(title = "BB Offset",                           defval = 0,     minval = -500,  maxval = 500,                                   group = "Bollinger Band Indicator")  
rsilen          = input(title = "RSI Length",                          defval = 14,    minval=1,                                                       group = "RSI Indicator")
rsisrc          = input(title = "RSI Source",                           defval = close,                                                                 group = "RSI Indicator")
rsiMaxEntry     = input(title = "RSI Maximum Value",                   defval = 60,    minval = 50,    maxval = 100,                                   group = "RSI Indicator")
rsiMinEntry     = input(title = "RSI Minimum Value",                   defval = 40,    minval = 0,     maxval = 50,                                    group = "RSI Indicator")
rsiMaxExit      = input(title = "RSI Max Exit Value",                  defval = 70,    minval = 50,    maxval = 100,                                   group = "RSI Indicator")
rsiMinExit      = input(title = "RSI Min Exit Value",                  defval = 30,    minval = 0,     maxval = 50,                                    group = "RSI Indicator")
atrLength       = input(title = "ATR Length",                          defval = 14,    minval = 1,                                                     group = "ATR Indicator")
useStructure    = input(title = "Use Trailing Stop?",               type = input.bool,      defval = true,                                                                  group = "ATR Indicator")
atrlookback     = input(title = "ATR Lookback Period",                 defval = 7,     minval = 1,                                                     group = "ATR Indicator")
atrMultiplier   = input(title = "ATR Multiplier",                   type = input.float,     defval = 1.0,   minval = 0.1,                                                   group = "ATR Indicator")
sigMaxValue     = input(title = "ADX Max Value",                    type = input.float,     defval = 20.0,  minval = 0,     maxval = 100,   step = 0.1,                     group = "ADX Indicator")
adxlen          = input(title = "ADX Smoothing",                       defval = 14,                                                                    group = "ADX Indicator")
dilen           = input(title = "DI Length",                           defval = 14,                                                                    group = "ADX Indicator")

// Date input
fromMonth       = input(defval = 1,    title = "From Month",           minval = 1,     maxval = 12,    group = "Backtest Date Range")
fromDay         = input(defval = 1,    title = "From Day",             minval = 1,     maxval = 31,    group = "Backtest Date Range")
fromYear        = input(defval = 2000, title = "From Year",            minval = 1970,                  group = "Backtest Date Range")
thruMonth       = input(defval = 1,    title = "Thru Month",           minval = 1,     maxval = 12,    group = "Backtest Date Range")
thruDay         = input(defval = 1,    title = "Thru Day",             minval = 1,     maxval = 31,    group = "Backtest Date Range")
thruYear        = input(defval = 2099, title = "Thru Year",            minval = 1970,                  group = "Backtest Date Range")
inDataRange     = true

// Built in Bollinger Band
basis           = sma(bbsrc, length)
dev             = mult * stdev(bbsrc, length)
upper           = basis + dev
lower           = basis - dev
// Built in RSI
up              = rma(max(change(rsisrc), 0), rsilen)
down            = rma(-min(change(rsisrc), 0), rsilen)
rsi             = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
// Built in ADX
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)

// Custom variables
ema1 = ema(close, ema1Input)
ema2 = ema(close, ema2Input)
atr = atr(atrLength)

// Entry and exit signals
CrossLongEntry  = (close <= lower or close[1] <= lower[1]) and close > open and close[1] < open[1] and close > ema1 and close > ema2 and strategy.position_size == 0 and inDataRange and rsi > rsiMinEntry and rsi < rsiMaxEntry and sig < sigMaxValue
CrossShortEntry = (close >= upper or close[1] >= upper[1]) and close < open and close[1] > open[1] and close < ema1 and close < ema2 and strategy.position_size == 0 and inDataRange and rsi > rsiMinEntry and rsi < rsiMaxEntry and sig < sigMaxValue

CrossLongExit   = (close >= upper or close[1] >= upper[1]) and close < open and close[1] > open[1] and strategy.position_size > 0 and inDataRange or rsi < rsiMinExit or rsi > rsiMaxExit
CrossShortExit  = (close <= lower or close[1] <= lower[1]) and close > open and close[1] < open[1] and strategy.position_size < 0 and inDataRange or rsi < rsiMinExit or rsi > rsiMaxExit

// Determining the stop loss based on ATR
StopLossLong    = (useStructure ? lowest(low, atrlookback) : close) - atr * atrMultiplier
StopLossShort   = (useStructure ? highest(high, atrlookback) : close) + atr * atrMultiplier

// Custom variables used to store the stoploss value
var StopLong    = 0.0
var StopShort   = 0.0
// Telling my script to store the stoploss value in the corresponding variables
if CrossLongEntry
    StopLong := StopLossLong
if CrossShortEntry
    StopShort := StopLossShort

// Strategy
strategy.entry("Entry Long", strategy.long, when = CrossLongEntry, comment = "Entry Long")
strategy.close("Entry Long", when = CrossLongExit or close < StopLong, comment = "Long Exit")

strategy.entry("Entry Short", strategy.short, when = CrossShortEntry, comment = "Entry Short")
strategy.close("Entry Short", when = CrossShortExit or close > StopShort, comment = "Short Exit")

// Plots the Bollinger Band
plot(basis, "Basis", color=#872323, offset = offset)
p1 = plot(upper, "Upper", color=color.teal, offset = offset)
p2 = plot(lower, "Lower", color=color.teal, offset = offset)
fill(p1, p2, title = "Background", color=#198787, transp=95)

// Use this if you want to see the stoploss visualised, be aware though plotting these can be confusing
// plot(StopLong)
// plot(StopShort)

더 많은