역방향 캡처 전략


생성 날짜: 2023-11-24 16:43:25 마지막으로 수정됨: 2023-11-24 16:43:25
복사: 0 클릭수: 678
avatar of ChaoZhang ChaoZhang
1
집중하다
1621
수행원

역방향 캡처 전략

개요

반전 캡처 전략은 변동률 지표 부린라인과 동력 지표 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. 기계 학습 알고리즘을 추가하여 AI 기술을 사용하여 최적의 매개 변수를 자동으로 찾습니다.

요약하다

반전 캡처 전략은 전체적으로 효과가 좋은 단선 거래 전략이다. 그것은 추세 판단과 반전 신호를 결합하여, 위기 시장의 가짜 신호를 필터링 할 수 있으며, 추세 시장과 추세를 피하는 데 있어 위험을 제어 할 수 있다. 매개 변수 및 모델을 지속적으로 최적화함으로써 더 나은 전략 효과를 얻을 수 있다.

전략 소스 코드
/*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)