트레일링 스톱 시스템을 활용한 RSI MA 크로스오버 스윙 트레이딩 전략

RSI MA CROSSOVER TRAILING SL Swing Trading risk management
생성 날짜: 2025-04-24 16:51:14 마지막으로 수정됨: 2025-04-24 16:51:14
복사: 4 클릭수: 349
avatar of ianzeng123 ianzeng123
2
집중하다
319
수행원

트레일링 스톱 시스템을 활용한 RSI MA 크로스오버 스윙 트레이딩 전략 트레일링 스톱 시스템을 활용한 RSI MA 크로스오버 스윙 트레이딩 전략

개요

이 전략은 RSI (대비적으로 강한 지수) 가 이동 평균 (MA) 과 교차하는 스윙 트레이딩 전략으로, 4시간 차트용으로 설계되었다. 이 전략은 RSI와 MA의 골드 포크와 데드 포크를 통해 트레이딩 신호를 생성하고, 고정된 스톱/스톱, 추적 스톱 및 역전출 메커니즘을 포함한 여러 위험 관리 도구와 결합되었다. 이 전략은 연속 손실 제한을 설정하고, 연속 손실이 두 번 이상되면 다음 날짜가 재설정될 때까지 거래를 중지한다.

전략 원칙

  1. 시간 프레임 제한이 전략은 4시간 차트에서만 작동하여 거래 신호가 설계된 시간주기와 일치하도록 합니다.
  2. 지표 계산: RSI를 사용하여 (기본 길이는 14) 이동 평균 (SMA 또는 EMA, 기본 길이는 14) 을 사용하여 신호를 생성한다.
    • 금강 ((RSI 상의 MA) 이 구매 신호를 촉발합니다.
    • 사다리 ((RSI 아래 MA를 뚫고) 트리거는 팔기 신호 ((공백) 을 발생시킨다)
  3. 포지션 관리: 각 거래의 자본 분배와 현재 가격에 따라 포지션 크기를 계산한다.
  4. 탈퇴 장치
    • 고정 중지/정지%로 설정된 스톱로스 (기본 1.5%) 와 스톱 (기본 2.5%)
    • 손실 추적: 가격이 최고점에서 철회할 때 지정된 점 (기본 10점) 을 트리거한다.
    • 탈퇴이쪽은 반전 신호가 나오면 평행한다.
  5. 위험 관리
    • 2회 연속으로 손실을 입었을 때 거래를 중지하고 매일 9:15에 손실을 재설정한다.

우위 분석

  1. 다차원 신호 검증RSI와 MA의 듀얼 필터링을 결합하여 가짜 신호를 줄여줍니다.
  2. 동적 위험 관리: 추적 스톱로스는 수익을 잠금하고, 고정 스톱로스는 손실을 제한한다.
  3. 엄격한 재무 관리자본분배에 기반한 포지션, 과도한 레버리지를 피한다.
  4. 징계 통제“연속 적자 잠정제도”는 감정적 거래를 막아줍니다.
  5. 시각화 표기: 명확한 도표 표기법은 신호와 출구 지점을 빠르게 식별하는 데 도움이 됩니다.

위험 분석

  1. 매개변수 민감도RSI와 MA의 길이는 신호 품질에 큰 영향을 미치며 시장의 변동에 적응하기 위해 최적화해야합니다.
  2. 동향 시장의 성과RSI는 강한 추세에서 장기간 과매매할 수 있으며, 신호가 지연될 수 있다.
  3. 시간 프레임 제한: 4시간 차트에서만 적용됩니다. 다른 주기에는 재확인해야 합니다.
  4. 연속적인 손실 위험이 경우, 손실 계산기를 재설정하기 전에 잠재적인 수익 기회를 놓칠 수 있습니다.
    해결책
  • 역사 회귀를 통해 최적화 매개 변수.
  • 트렌드 지표와 결합하여 ((ADX와 같은) 필터 신호.
  • 다이내믹 손실 수를 설정합니다.

최적화 방향

  1. 다중 지표 통합: MACD 또는 브린 밴드 강화 신호 확인.
  2. 동적 변수 조정: 시장의 변동에 따라 RSI 길이를 조정하고 손실 비율을 조정한다.
  3. 시간적 확장: 테스트 전략이 더 높은 또는 더 낮은 주기 (예: 일조선/1시간) 에서 수행되는 것.
  4. 기계 학습 최적화: 역사 데이터 트레이닝 모델을 사용하여 입학 및 퇴출 조건을 최적화한다.
  5. 자금 관리 업그레이드: 계좌의 순가치에 따라 거래당 자본 비율을 조정한다.

요약하다

이 전략은 RSI와 MA의 교차 신호를 통해 스윙 거래를 실현하고, 다층의 위험 관리 도구와 결합하여 수익 잠재력과 위험 통제를 균형 잡는다. 그것의 장점은 명확한 논리와 엄격한 규율에 있다. 그러나 다양한 시장 환경에 적응하기 위해 추가적인 최적화가 필요하다.

전략 소스 코드
/*backtest
start: 2024-04-23 00:00:00
end: 2024-09-06 00:00:00
period: 4h
basePeriod: 4h
exchanges: [{"eid":"Futures_Binance","currency":"DOGE_USDT"}]
*/

//@version=5
strategy("📈 RX Swing ", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=1)


// === INPUTS ===
rsiLength     = input.int(14, title="RSI Length")
maLength      = input.int(14, title="RSI MA Length")
maType        = input.string("SMA", options=["SMA", "EMA"], title="MA Type for RSI")
sl_pct        = input.float(1.5, title="Stop Loss %", minval=0.0)
tp_pct        = input.float(2.5, title="Take Profit %", minval=0.0)
capitalPerTrade = input.float(15000, title="Capital Per Trade (INR)", minval=1)
lotSize       = input.int(50, title="Lot Size (Nifty Options Lot)", minval=1)
trail_points  = input.float(10, title="Trailing SL Points", minval=0.1)

// === CALCULATIONS ===
rsi    = ta.rsi(close, rsiLength)
rsiMA  = maType == "SMA" ? ta.sma(rsi, maLength) : ta.ema(rsi, maLength)

longSignal  = ta.crossover(rsi, rsiMA)
shortSignal = ta.crossunder(rsi, rsiMA)

// === TRADING WINDOW ===
canTrade = true
exitTime = false

// === STATE VARIABLES ===
var float entryPrice = na
var bool inTrade = false
var string tradeDir = ""
var int lossCount = 0
var float trailHigh = na
var float trailLow = na

// === EXIT TRIGGER ===
exitNow = false
exitReason = ""

// === POSITION SIZE BASED ON CAPITAL ===
positionSize = (capitalPerTrade / close) * lotSize

// === ENTRY LOGIC (AFTER CLOSE OF CANDLE) ===
if (canTrade and lossCount < 2)
    if (longSignal and not inTrade and barstate.isconfirmed)  // Ensure the signal happens after candle close
        strategy.entry("Buy Call", strategy.long, qty=positionSize)
        entryPrice := close
        trailHigh := close
        inTrade := true
        tradeDir := "CALL"

    else if (shortSignal and not inTrade and barstate.isconfirmed)  // Ensure the signal happens after candle close
        strategy.entry("Buy Put", strategy.short, qty=positionSize)
        entryPrice := close
        trailLow := close
        inTrade := true
        tradeDir := "PUT"

// === TRAILING STOP-LOSS LOGIC ===
if (inTrade)
    if (tradeDir == "CALL")
        trailHigh := math.max(trailHigh, close)
        if (close <= trailHigh - trail_points)
            strategy.close("Buy Call", comment="CALL Trailing SL Hit")
            exitNow := true
            exitReason := "Trail SL"
            inTrade := false
            lossCount := lossCount + 1

    if (tradeDir == "PUT")
        trailLow := math.min(trailLow, close)
        if (close >= trailLow + trail_points)
            strategy.close("Buy Put", comment="PUT Trailing SL Hit")
            exitNow := true
            exitReason := "Trail SL"
            inTrade := false
            lossCount := lossCount + 1

// === REVERSAL EXIT LOGIC ===
if (inTrade)
    if (tradeDir == "CALL" and shortSignal)
        strategy.close("Buy Call", comment="CALL Exit on Reversal")
        exitNow := true
        exitReason := "Reversal"
        inTrade := false
        if (strategy.position_size < 0)
            lossCount := lossCount + 1

    if (tradeDir == "PUT" and longSignal)
        strategy.close("Buy Put", comment="PUT Exit on Reversal")
        exitNow := true
        exitReason := "Reversal"
        inTrade := false
        if (strategy.position_size > 0)
            lossCount := lossCount + 1

// === TP/SL EXIT LOGIC ===
if (inTrade)
    tpLevel = entryPrice * (1 + tp_pct / 100)
    slLevel = entryPrice * (1 - sl_pct / 100)

    if (strategy.position_size > 0)
        if (close >= tpLevel)
            strategy.close("Buy Call", comment="CALL TP Hit")
            exitNow := true
            exitReason := "TP"
            inTrade := false
        else if (close <= slLevel)
            strategy.close("Buy Call", comment="CALL SL Hit")
            exitNow := true
            exitReason := "SL"
            inTrade := false
            lossCount := lossCount + 1

    if (strategy.position_size < 0)
        tpLevel = entryPrice * (1 - tp_pct / 100)
        slLevel = entryPrice * (1 + sl_pct / 100)

        if (close <= tpLevel)
            strategy.close("Buy Put", comment="PUT TP Hit")
            exitNow := true
            exitReason := "TP"
            inTrade := false
        else if (close >= slLevel)
            strategy.close("Buy Put", comment="PUT SL Hit")
            exitNow := true
            exitReason := "SL"
            inTrade := false
            lossCount := lossCount + 1

// === RESET LOSS COUNT ON NEW DAY ===
if (hour == 9 and minute == 15)
    lossCount := 0

// === MARKUPS ===
plotshape(longSignal and canTrade and lossCount < 2 and barstate.isconfirmed, title="📗 CALL Entry", location=location.belowbar, style=shape.triangleup, color=color.green, size=size.small, text="CALL")
plotshape(shortSignal and canTrade and lossCount < 2 and barstate.isconfirmed, title="📕 PUT Entry", location=location.abovebar, style=shape.triangledown, color=color.red, size=size.small, text="PUT")
plotshape(exitNow and exitReason == "TP", location=location.belowbar, style=shape.xcross, color=color.green, size=size.tiny, title="✅ TP Exit", text="TP")
plotshape(exitNow and exitReason == "SL", location=location.abovebar, style=shape.xcross, color=color.red, size=size.tiny, title="❌ SL Exit", text="SL")
plotshape(exitNow and exitReason == "Reversal", location=location.abovebar, style=shape.circle, color=color.fuchsia, size=size.tiny, title="🔁 Reversal Exit", text="REV")
plotshape(exitNow and exitReason == "Trail SL", location=location.abovebar, style=shape.square, color=color.yellow, size=size.tiny, title="🔂 Trailing SL Exit", text="Trail")