다중 이동 평균 교차 지원 RSI 동적 매개변수 양적 거래 전략

RSI MA SMA EMA WMA SMMA RMA
생성 날짜: 2025-01-17 16:14:38 마지막으로 수정됨: 2025-01-17 16:14:38
복사: 1 클릭수: 410
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

다중 이동 평균 교차 지원 RSI 동적 매개변수 양적 거래 전략

개요

이는 상대 강도 지수(RSI)와 여러 이동 평균을 결합한 양적 거래 전략입니다. 이 전략은 주로 RSI 지표의 다양한 이동 평균(SMA, EMA, WMA 및 SMMA 포함)의 교차 신호를 모니터링하여 시장 추세를 결정하고 RSI 지표 자체의 매수 과다 및 매도 과다 범위를 보조 기준으로 결합합니다. 판단, 시장 추세를 결정하기 위해. 거래 타이밍.

전략 원칙

전략에는 주로 다음과 같은 주요 계산 단계가 포함됩니다.

  1. 14기간 RSI 지표를 계산하여 매수과잉 영역을 70, 매도과잉 영역을 30으로 설정합니다.
  2. RSI 곡선에서 서로 다른 매개변수를 사용하여 세 개의 이동 평균을 계산합니다.
    • MA1: 20주기, 선택형 SMA/EMA/WMA/SMMA
    • MA2: 50주기, 선택형 SMA/EMA/WMA/SMMA
    • MA3: 100주기, 선택형 SMA/EMA/WMA/SMMA
  3. 거래 신호 생성 규칙:
    • 매수 신호: MA2가 MA3을 상향 교차할 때
    • 매도신호 : MA2가 MA3을 하향 교차할 때
  4. 동시에 RSI 지표의 편차를 감지하여 거래 결정에 대한 보조적 참고 자료를 제공합니다.

전략적 이점

  1. 여러 기술 지표가 교차 검증되어 거래 신호의 신뢰성이 향상됩니다.
  2. 이동평균 유형과 매개변수는 조정이 가능하여 유연성이 뛰어납니다.
  3. RSI 발산 감지 기능은 시장 전환점을 미리 감지하는 데 도움이 됩니다.
  4. 위험을 효과적으로 통제하기 위해 백분율 포지션 관리를 활용하세요
  5. 뛰어난 시각화 효과, 분석 및 백테스트 용이

전략적 위험

  1. 이동 평균 교차는 지연 효과를 가질 수 있습니다.
  2. 횡보장에서는 자주 거짓 신호가 발생할 수 있습니다.
  3. 특정 시장 상황에서 RSI 지표의 왜곡
  4. 잘못된 매개변수 선택으로 인해 거래 신호가 너무 많거나 너무 적을 수 있습니다. 해결 방법:
  • 교차 검증을 위해 시장 동향과 거래량을 결합하는 것이 좋습니다.
  • 이동평균 매개변수를 조정하여 거래 빈도를 최적화할 수 있습니다.
  • 리스크를 통제하기 위해 손절매와 이익실현을 설정하세요

전략 최적화 방향

  1. 신호 필터링 최적화:
  • 추세 확인 지표 추가
  • 볼륨 분석 추가
  1. 매개변수의 동적 최적화:
  • 시장 변동성에 따라 RSI 및 MA 매개변수를 자동으로 조정합니다.
  • 적응형 사이클 계산 방법 소개
  1. 위험 관리 최적화:
  • 동적 손절매 및 이익실현 메커니즘 개발
  • 동적 창고 관리 시스템 설계

요약하다

이 전략은 RSI와 여러 이동평균선을 결합하여 매우 적응력 있는 거래 시스템을 구축합니다. 이 전략의 핵심적인 장점은 여러 기술 지표의 교차 검증과 유연한 매개변수 구성에 있지만, 동시에 이동 평균의 지연과 전략 성과에 미치는 시장 상황의 영향에도 주의해야 합니다. 이 전략은 지속적인 최적화와 위험 관리를 통해 실제 거래에서 안정적인 성과를 달성할 것으로 기대됩니다.

전략 소스 코드
/*backtest
start: 2024-01-17 00:00:00
end: 2025-01-16 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":49999}]
*/

//@version=6
strategy(title="Relative Strength Index with MA Strategy", shorttitle="RSI-MA Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=200)

// RSI Inputs
rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")
rsiSourceInput = input.source(close, "Source", group="RSI Settings")
calculateDivergence = input.bool(false, title="Calculate Divergence", group="RSI Settings", tooltip="Calculating divergences is needed in order for divergence alerts to fire.")

// RSI Calculation
change_rsi = ta.change(rsiSourceInput)
up = ta.rma(math.max(change_rsi, 0), rsiLengthInput)
down = ta.rma(-math.min(change_rsi, 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))

// RSI Plot
plot(rsi, "RSI", color=#7E57C2)
hline(70, "RSI Upper Band", color=#787B86)
hline(50, "RSI Middle Band", color=color.new(#787B86, 50))
hline(30, "RSI Lower Band", color=#787B86)
fill(hline(70), hline(30), color=color.rgb(126, 87, 194, 90), title="RSI Background Fill")

// RSI-based MA Inputs
grpRSIMovingAverages = "RSI Moving Averages"
ma1Length = input.int(20, title="MA1 Length", group=grpRSIMovingAverages)
ma2Length = input.int(50, title="MA2 Length", group=grpRSIMovingAverages)
ma3Length = input.int(100, title="MA3 Length", group=grpRSIMovingAverages)
ma1Type = input.string("SMA", title="MA1 Type", options=["SMA", "EMA", "WMA", "SMMA"], group=grpRSIMovingAverages)
ma2Type = input.string("EMA", title="MA2 Type", options=["SMA", "EMA", "WMA", "SMMA"], group=grpRSIMovingAverages)
ma3Type = input.string("WMA", title="MA3 Type", options=["SMA", "EMA", "WMA", "SMMA"], group=grpRSIMovingAverages)

// MA Calculation Function
calcMA(source, length, type) =>
    switch type
        "SMA" => ta.sma(source, length)
        "EMA" => ta.ema(source, length)
        "WMA" => ta.wma(source, length)
        "SMMA" => ta.rma(source, length)

// MA Calculations
ma1 = calcMA(rsi, ma1Length, ma1Type)
ma2 = calcMA(rsi, ma2Length, ma2Type)
ma3 = calcMA(rsi, ma3Length, ma3Type)

// MA Plots
plot(ma1, title="RSI MA1", color=color.blue)
plot(ma2, title="RSI MA2", color=color.green)
plot(ma3, title="RSI MA3", color=color.red)

// Divergence (Retained from original script)
lookbackRight = 5
lookbackLeft = 5
rangeUpper = 60
rangeLower = 5
bearColor = color.red
bullColor = color.green
textColor = color.white
noneColor = color.new(color.white, 100)

_inRange(bool cond) =>
    bars = ta.barssince(cond)
    rangeLower <= bars and bars <= rangeUpper

plFound = false
phFound = false

bullCond = false
bearCond = false

rsiLBR = rsi[lookbackRight]

if calculateDivergence
    // Regular Bullish
    plFound := not na(ta.pivotlow(rsi, lookbackLeft, lookbackRight))    
    rsiHL = rsiLBR > ta.valuewhen(plFound, rsiLBR, 1) and _inRange(plFound[1])
    lowLBR = low[lookbackRight]
    priceLL = lowLBR < ta.valuewhen(plFound, lowLBR, 1)
    bullCond := priceLL and rsiHL and plFound

    // Regular Bearish
    phFound := not na(ta.pivothigh(rsi, lookbackLeft, lookbackRight))
    rsiLH = rsiLBR < ta.valuewhen(phFound, rsiLBR, 1) and _inRange(phFound[1])
    highLBR = high[lookbackRight]
    priceHH = highLBR > ta.valuewhen(phFound, highLBR, 1)
    bearCond := priceHH and rsiLH and phFound

// plot(
//      plFound ? rsiLBR : na,
//      offset=-lookbackRight,
//      title="Regular Bullish",
//      linewidth=2,
//      color=(bullCond ? bullColor : noneColor),
//      display = display.pane
//      )

plotshape(
     bullCond ? rsiLBR : na,
     offset=-lookbackRight,
     title="Regular Bullish Label",
     text=" Bull ",
     style=shape.labelup,
     location=location.absolute,
     color=bullColor,
     textcolor=textColor
     )

// plot(
//      phFound ? rsiLBR : na,
//      offset=-lookbackRight,
//      title="Regular Bearish",
//      linewidth=2,
//      color=(bearCond ? bearColor : noneColor),
//      display = display.pane
//      )

plotshape(
     bearCond ? rsiLBR : na,
     offset=-lookbackRight,
     title="Regular Bearish Label",
     text=" Bear ",
     style=shape.labeldown,
     location=location.absolute,
     color=bearColor,
     textcolor=textColor
     )

alertcondition(bullCond, title='Regular Bullish Divergence', message="Found a new Regular Bullish Divergence, `Pivot Lookback Right` number of bars to the left of the current bar.")
alertcondition(bearCond, title='Regular Bearish Divergence', message='Found a new Regular Bearish Divergence, `Pivot Lookback Right` number of bars to the left of the current bar.')

// ----- MUA/BÁN -----

// Điều kiện Mua: MA2 cắt lên MA3 và MA3 < 55
buyCondition = ta.crossover(ma2, ma3) 

// Điều kiện Bán: MA2 cắt xuống MA3 và MA3 > 40
sellCondition = ta.crossunder(ma2, ma3)

// Thực hiện lệnh Mua/Bán
if (buyCondition)
    strategy.entry("Buy", strategy.long, comment="Buy Signal")

if (sellCondition)
    strategy.close("Buy", comment="Sell Signal")



// ----- KẾT THÚC -----