볼링거 밴드 트렌드 역전 전략

저자:차오장, 날짜: 2023-11-01 11:29:34
태그:

img

전반적인 설명

이 전략은 볼링거 밴드 및 이동 평균을 사용하여 가격이 상부 또는 하부 밴드에 접근 할 때 LONG 또는 SHORT로 이동합니다. 가격이 상부 밴드 이상으로 떨어지면 짧고 가격이 하부 밴드 아래에 떨어지면 길게됩니다. 전략은 트렌드 다음과 평균 반전 전략의 장점을 결합하여 범위 제한 시장에서 잘 수행합니다.

논리

전략은 두 가지 진입 신호를 식별합니다.

  1. 긴 신호: EMA 라인 위에 있는 상태에서 닫기 가격이 하위 범위를 때, 이전 촛불은 하향적이고 현재 촛불은 상승합니다.

  2. 짧은 신호: EMA 라인 아래에서 닫기 가격이 상단 범위를 때, 이전 촛불은 상승하고 현재 촛불은 하락합니다.

스톱 로스는 고정 스톱 로스를 사용 합니다. 스톱 로스 레벨은 엔트리 가격 더하기/미inus 리스크/어워드 비율 곱하기 엔트리 가격과 영업 수준 사이의 거리에 설정 됩니다.

이윤 취득은 동적 이윤 취득을 사용합니다. 긴 이윤 취득은 하부 밴드에서 설정됩니다. 짧은 이윤 취득은 상부 밴드에서 설정됩니다.

장점

  1. 트렌드를 따르는 전략과 평균 반전 전략의 장점을 결합하고, 범위 제한 시장에서 잘 수행합니다.

  2. 볼링거 밴드를 이용해서 과잉 구매 및 과잉 판매 수준을 파악하여 반전 신호의 정확성을 향상시킵니다.

  3. 일정한 스톱 로스는 위험 관리를 용이하게 합니다.

  4. 동적인 수익은 수익을 극대화 할 수 있습니다.

위험성

  1. 탈출 전략은 항복을 막을 수 있습니다.

  2. 시장이 너무 불안정할 때 빈번한 스톱 로스가 발생합니다.

  3. 고정 스톱 손실은 시장의 변동에 적응하지 못합니다. 너무 넓거나 너무 좁을 수 있습니다.

  4. 볼링거 밴드의 패러미터 조정이 제대로 되지 않으면 평균적인 결과를 얻을 수 있습니다.

강화

  1. 입력 신호를 필터링하기 위해 RSI 지표를 통합하십시오. 예를 들어, RSI가 50 이상이라면만 장거리, RSI가 50 이하라면만 단축하십시오. 이것은 나쁜 신호를 피합니다.

  2. 변동성에 따라 정지 거리를 조정하는 적응 스톱 손실을 구현하십시오. 예를 들어 동적 스톱 손실을 설정하기 위해 ATR을 사용하십시오.

  3. 가장 좋은 매개 변수 조합을 찾기 위해 볼링거 밴드 매개 변수를 최적화합니다.

  4. EMA의 지지/저항 효과를 강화하기 위해 다른 EMA 기간을 테스트합니다.

요약

이 전략은 경향과 역전을 결합하여 볼링거 밴드 (Bollinger Bands) 에 의해 식별된 과잉 구매/ 과잉 판매 수준에 진입합니다. 동적 인 수익을 통해 이익을 극대화합니다. 범위 제한 시장에서 잘 수행합니다. 정지 러닝을 조심하십시오. 성능을 최적화하기 위해 매개 변수를 세밀하게 조정하십시오. 전반적으로 실용적이고 효과적인 전략입니다.


/*backtest
start: 2023-10-24 00:00:00
end: 2023-10-31 00:00:00
period: 10m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4

// Welcome to yet another script. This script was a lot easier since I was stuck for so long on the Donchian Channels one and learned so much from that one that I could use in this one
// This code should be a lot cleaner compared to the Donchian Channels, but we'll leave that up to the pro's
// This strategy has two entry signals, long = when price hits lower band, while above EMA, previous candle was bearish and current candle is bullish
// Short = when price hits upper band, while below EMA, previous candle was bullish and current candle is bearish
// Take profits are the opposite side's band(lower band for long signals, upper band for short signals). This means our take profit price will change per bar
// Our stop loss doesn't change, it's the difference between entry price and the take profit target divided by the input risk reward
// At the time of writing this, I could probably calculate that much easier by simply multiplying the opposite band by the input risk reward ratio
// Since I want to get this script out and working on the next one, I won't clean that up, I'm sorry
// strategy(shorttitle="BB Trending Reverse Strategy", title="Bollinger Bands Trending Reverse Strategy", overlay=true, default_qty_type = strategy.cash, default_qty_value = 150, initial_capital = 1000, currency = currency.USD, commission_type = "percent", commission_value = 0.036)

// The built-in Bollinger Band indicator inputs and variables, added some inputs of my own and organised the code
length              = input(20, minval=1)
src                 = input(close, title="Source")
mult                = input(2.0, minval=0.001, maxval=50, title="StdDev")
emaInput            = input(title = "EMA Input", type = input.integer, defval = 200, minval = 10, maxval = 400, step = 1)
riskreward          = input(title = "Risk/Reward Ratio", type = input.float, defval = 1.50, minval = 0.01, maxval = 100, step = 0.01)
offset              = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)
basis               = sma(src, length)
dev                 = mult * stdev(src, length)
upper               = basis + dev
lower               = basis - dev
ema                 = ema(close, emaInput)

// These are our conditions as explained above
entryLong           = low[1] <= lower[1] and low <= lower and low > ema
entryShort          = high[1] >= upper[1] and high >= upper and high < ema
reversecandleLong   = close > open and close[1] < open[1]
reversecandleShort  = close < open and close[1] > open[1]
var stopLong        = 0.0
var stopShort       = 0.0

// These are our entry signals, notice how the stop condition is within the if statement while the strategy.exit is outside of the if statement, this way the take profit targets trails up or down depending on what the price does
if reversecandleLong and entryLong and strategy.position_size == 0
    stopLong := (((close / upper - 1) * riskreward + 1) * close)
    strategy.entry("Long Entry", strategy.long, comment = "Long Entry")
    
strategy.exit("Exit Long", "Long Entry", limit = upper, stop = stopLong, comment = "Exit Long")

if reversecandleShort and entryShort and strategy.position_size == 0
    stopShort := (((close / lower - 1) / riskreward + 1) * close)
    strategy.entry("Short Entry", strategy.short, comment = "Short Entry")

strategy.exit("Exit Short", "Short Entry", limit = lower, stop = stopShort, comment = "Exit Short")


// The built-in Bollinger Band plots
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)
plot(ema, color=color.red)

// These plots are to check the stoplosses, they can  make a mess of your chart so only use these if you want to make sure these work
// plot(stopLong)
// plot(stopShort)

더 많은