반전 포획 전략

저자:차오장, 날짜: 2023-11-24 16:43:25
태그:

img

전반적인 설명

리버서스 캐처 전략은 변동성 지표 볼링거 밴드 (Bollinger Bands) 와 추진력 지표 RSI를 활용한 리버서스 거래 전략이다. 트렌드 방향이 변할 때 역전 기회를 찾기 위한 신호로 볼링거 밴드 채널과 RSI 과잉 구매/ 과잉 판매 라인을 설정한다.

전략 논리

이 전략은 거래 신호를 확인하기 위해 RSI 및 다른 추진력 지표와 결합하여 볼링거 밴드를 주요 기술 지표로 사용합니다. 구체적인 논리는 다음과 같습니다.

  1. 긴 또는 짧은 입장을 결정하기 위해 주요 트렌드 방향을 판단하십시오. 트렌드를 결정하기 위해 50 일 EMA와 21 일 EMA 황금 십자 / 죽은 십자.
  2. 하향 추세에서, 가격이 볼링거 하위 대역을 넘어서면, 그리고 RSI가 지나친 판매 영역에서 다시 반등하여 황금색 십자가를 형성하면, 그것은 지나친 판매 영역이 이미 바닥에 도달했다는 것을 나타내고, 구매 신호를 제공합니다.
  3. 상승 트렌드에서 가격이 볼링거 상단역 아래로 떨어지고, RSI가 과잉 매입 영역에서 다시 떨어지고, 죽은 십자가를 형성하면, 과잉 매입 영역이 후퇴하기 시작한다는 것을 나타내고, 판매 신호를 제공합니다.
  4. 위 구매 신호와 판매 신호는 거짓 신호를 피하기 위해 함께 작동해야 합니다.

이점 분석

이 전략의 장점은 다음과 같습니다.

  1. 변동성과 동력 지표를 결합하면 신호가 더 신뢰할 수 있습니다.
  2. 리버스 트레이딩은 단기 거래에 적합한 낮은 위험을 가지고 있습니다.
  3. 거래 규칙은 자동화 거래를 위해 프로그래밍 가능합니다.
  4. 트렌드 트레이딩과 결합하면 시장 통합 중에 장애가 발생하지 않습니다.

위험 분석

이 전략의 위험은 다음과 같습니다.

  1. 볼링거 밴드는 잘못된 신호의 위험을 뚫고, RSI 필터를 필요로 합니다.
  2. 실패한 환전 위험, 신속한 스톱 손실이 필요합니다.
  3. 리버스 타이밍 위험, 너무 일찍 들어가거나 가장 좋은 입구 지점을 놓칠 수 있습니다.

위험을 통제하기 위해 우리는 위험 노출을 제한하기 위해 스톱 로스 수준을 설정하고 시스템 성능을 향상시키기 위해 볼링거 밴드 기간이나 RSI 수치와 같은 매개 변수를 최적화 할 수 있습니다.

최적화 방향

주요 최적화 방향은 다음과 같습니다.

  1. 볼링거 밴드 매개 변수를 최적화하고, 최적의 설정을 찾기 위해 기간 길이와 표준편차를 조정합니다.
  2. 트렌드 판단을 위해 가장 좋은 시기를 결정하기 위해 이동 평균 기간을 최적화하십시오.
  3. 가장 좋은 과반 구매/ 과반 판매 범위를 찾기 위해 RSI 매개 변수를 조정합니다.
  4. KDJ, MACD와 같은 다른 지표를 추가하여 진입 신호를 다양화합니다.
  5. 최적화된 매개 변수를 찾기 위해 기계 학습 모델을 도입합니다.

결론

리버설 캐처 전략은 전반적으로 효과적인 단기 거래 전략이다. 트렌드 필터링과 리버설 신호를 결합함으로써 시장 통합 중에 잘못된 신호를 피하고 트렌드에 맞서 싸우는 것을 피할 수 있다. 지속적인 매개 변수와 모델 최적화를 통해 더 나은 전략 성능을 달성할 수 있다.


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

// This is an Open source work. Please do acknowledge in case you want to reuse whole or part of this code.
// Please see the documentation to know the details about this.

//@version=5
strategy('Strategy:Reversal-Catcher', shorttitle="Reversal-Catcher", overlay=true , currency=currency.NONE, initial_capital=100000)

// Inputs
src = input(close, title="Source (close, high, low, open etc.")

BBlength = input.int(defval=20, minval=1,title="Bollinger Period Length, default 20")
BBmult = input.float(defval=1.5, minval=1.0, maxval=4, step=0.1, title="Bollinger Bands Standard Deviation, default is 1.5")

fastMovingAvg = input.int(defval=21, minval=5,title="Fast Exponential Moving Average, default 21", group = "Trends")
slowMovingAvg = input.int(defval=50, minval=8,title="Slow Exponential Moving Average, default 50", group = "Trends")

rsiLenght = input.int(defval=14, title="RSI Lenght, default 14", group = "Momentum")
overbought = input.int(defval=70, title="Overbought limit (RSI), default 70", group = "Momentum")
oversold = input.int(defval=30, title="Oversold limit (RSI), default 30", group = "Momentum")

hide = input.bool(defval=true, title="Hide all plots and legends from the chart (default: true)")


// Trade related
tradeType = input.string(defval='Both', group="Trade settings", title="Trade Type", options=['Both', 'TrendFollowing', 'Reversal'], tooltip="Consider all types of trades? Or only Trend Following or only Reversal? (default: Both).")
endOfDay = input.int(defval=1500, title="Close all trades, default is 3:00 PM, 1500 hours (integer)", group="Trade settings")
mktAlwaysOn = input.bool(defval=false, title="Markets that never closed (Crypto, Forex, Commodity)", tooltip="Some markers never closes. For those cases, make this checked. (Default: off)", group="Trade settings")


// Utils
annotatePlots(txt, val, hide) => 
    if (not hide)
        var l1 = label.new(bar_index, val, txt, style=label.style_label_left, size = size.tiny, textcolor = color.white, tooltip = txt)
        label.set_xy(l1, bar_index, val)

/////////////////////////////// Indicators /////////////////////
vwap = ta.vwap(src)
plot(hide ? na : vwap, color=color.purple, title="VWAP", style = plot.style_line)
annotatePlots('VWAP', vwap, hide)

// Bollinger Band of present time frame
[BBbasis, BBupper, BBlower] = ta.bb(src, BBlength, BBmult)
p1 = plot(hide ? na : BBupper, color=color.blue,title="Bollinger Bands Upper Line")
p2 = plot(hide ? na : BBlower, color=color.blue,title="Bollinger Bands Lower Line")
p3 = plot(hide ? na : BBbasis, color=color.maroon,title="Bollinger Bands Width", style=plot.style_circles, linewidth = 1)
annotatePlots('BB-Upper', BBupper, hide)
annotatePlots('BB-Lower', BBlower, hide)
annotatePlots('BB-Base(20-SMA)', BBbasis, hide)

// RSI
rsi = ta.rsi(src, rsiLenght)

// Trend following
ema50 = ta.ema(src, slowMovingAvg)
ema21 = ta.ema(src, fastMovingAvg)
annotatePlots('21-EMA', ema21, hide)
annotatePlots('50-EMA', ema50, hide)


// Trend conditions
upTrend = ema21 > ema50 
downTrend = ema21 < ema50


// Condition to check Special Entry: HH_LL
// Long side:
hhLLong = barstate.isconfirmed and (low > low[1]) and (high > high[1]) and (close > high[1])
hhLLShort = barstate.isconfirmed and (low < low[1]) and (high < high[1]) and (close < low[1])

longCond =  barstate.isconfirmed and (high[1] < BBlower[1]) and (close > BBlower) and (close < BBupper) and hhLLong and ta.crossover(rsi, oversold) and downTrend
shortCond = barstate.isconfirmed and (low[1] > BBupper[1]) and (close < BBupper) and (close > BBlower) and hhLLShort and ta.crossunder(rsi, overbought) and upTrend

// Trade execute
h = hour(time('1'), syminfo.timezone)
m = minute(time('1'), syminfo.timezone)
hourVal = h * 100 + m
totalTrades = strategy.opentrades + strategy.closedtrades
if (mktAlwaysOn or (hourVal < endOfDay))
    // Entry
    var float sl = na
    var float target = na
    if (longCond)
        strategy.entry("enter long", strategy.long, 1, limit=na, stop=na, comment="Long[E]")
        sl := low[1]
        target := high >= BBbasis ? BBupper : BBbasis
        alert('Buy:' + syminfo.ticker + ' ,SL:' + str.tostring(math.floor(sl)) + ', Target:' + str.tostring(target), alert.freq_once_per_bar)
    if (shortCond)
        strategy.entry("enter short", strategy.short, 1, limit=na, stop=na, comment="Short[E]")
        sl := high[1]
        target := low <= BBbasis ? BBlower : BBbasis
        alert('Sell:' + syminfo.ticker + ' ,SL:' + str.tostring(math.floor(sl)) + ', Target:' + str.tostring(target), alert.freq_once_per_bar)

    // Exit: target or SL
    if ((close >= target) or (close <= sl))
        strategy.close("enter long", comment=close < sl ? "Long[SL]" : "Long[T]")
    if ((close <= target) or (close >= sl))
        strategy.close("enter short", comment=close > sl ? "Short[SL]" : "Short[T]")
else if (not mktAlwaysOn)
    // Close all open position at the end if Day
    strategy.close_all(comment = "EoD[Exit]", alert_message = "EoD Exit", immediately = true)


더 많은