전략에 따른 듀얼 MACD 가격 액션 돌파

MACD ATR
생성 날짜: 2024-11-25 11:15:50 마지막으로 수정됨: 2024-11-25 11:15:50
복사: 1 클릭수: 532
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

전략에 따른 듀얼 MACD 가격 액션 돌파

개요

이 전략은 15분 주기 상의 이중 MACD 직선 도형 색상의 변화를 관찰하여 시장의 추세를 결정하고, 5분 주기 상의 강력한 마찰 형태를 찾고, 1분 주기 상의 돌파 신호를 확인합니다. 이 전략은 ATR 기반의 동적 중지 손실 및 추적 마찰 메커니즘을 채택하여 위험을 효과적으로 관리하면서 수익 공간을 극대화합니다.

전략 원칙

전략은 두 개의 다른 매개 변수의 MACD 지표를 사용하여 시장의 흐름을 확인합니다. 두 개의 MACD 직선 그래프가 동일한 색상의 흐름을 표시 할 때, 시스템은 5 분 차트에서 강력한 형태를 찾습니다. 이 형태는 그림자보다 1.5 배 더 큰 개체입니다. 강력한 이 발견되면, 시스템은 1 분 차트에서 돌파구가 발생하는지 여부를 모니터링합니다. 상승 추세에서 높은 지점을 돌파하거나 하락 추세에서 낮은 지점을 돌파 할 때, 시스템은 상장을합니다.

전략적 이점

  1. 다주기 분석: 15분, 5분, 1분 세 시간 주기를 결합하여 신호 신뢰도를 높인다
  2. 트렌드 확인: 이중 MACD 크로스 검증을 사용하여 가짜 신호를 감소시킵니다.
  3. 가격 행동 분석: 강력한 변동 형태를 통해 중요한 가격 수준을 식별
  4. 다이내믹 리스크 관리: ATR 기반의 적응형 상쇄 및 추적 중지 메커니즘
  5. 신호 필터링: 엄격한 입시 조건으로 오작동을 줄일 수 있다.
  6. 높은 수준의 자동화: 모든 거래가 자동화되고 인간의 개입이 줄어들었다.

전략적 위험

  1. 트렌드 리버스 위험: 급격한 변동 시장에서 가짜 돌파구가 발생할 수 있습니다.
  2. 슬라이드 리스크: 1분 주기 높은 주파수 거래가 슬라이드 영향을 받을 수 있다.
  3. 과도한 거래 위험: 빈번한 신호가 과도한 거래로 이어질 수 있다.
  4. 시장 환경 의존성: 불안정한 시장에서 부진할 수 있다 완화 조치:
  • 트렌드 필터 추가
  • 최소 변동 임계값을 설정
  • 거래 제한을 추가합니다.
  • 시장환경 식별 메커니즘 소개

전략 최적화 방향

  1. MACD 매개 변수 최적화: 다른 시장 특성에 따라 MACD 매개 변수를 조정할 수 있다
  2. 스톱로스 최적화: 변동율에 기반한 동적 스톱로스를 추가하는 것을 고려하십시오.
  3. 거래 시간 필터: 거래 시간 창 제한을 추가
  4. 위치 관리: 배치 창고 및 출장 메커니즘을 구현
  5. 시장 환경 필터링: 트렌드 강도 지표 추가
  6. 철회 제어: 이익과 이익 곡선 기반의 위험 제어 메커니즘 도입

요약하다

이것은 기술 분석과 위험 관리의 통합 적용 전략 시스템이다. 다중 주기 분석과 엄격한 신호 필터링을 통해 거래 품질을 보장하고, 동적 스톱 및 추적 스톱 메커니즘을 사용하여 위험을 효과적으로 관리한다. 전략은 강한 적응력을 가지고 있지만, 시장 환경에 따라 계속적인 최적화가 필요합니다. 실내 적용 시, 충분한 피드백과 매개 변수 최적화를 먼저 수행하고, 시장 특성에 맞게 타겟 조정하는 것이 좋습니다.

전략 소스 코드
/*backtest
start: 2024-01-01 00:00:00
end: 2024-11-24 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// @version=5
strategy("Price Action + Double MACD Strategy with ATR Trailing", overlay=true)

// Inputs for MACD
fastLength1 = input.int(34, title="First MACD Fast Length")
slowLength1 = input.int(144, title="First MACD Slow Length")
signalLength1 = input.int(9, title="First MACD Signal Length")

fastLength2 = input.int(100, title="Second MACD Fast Length")
slowLength2 = input.int(200, title="Second MACD Slow Length")
signalLength2 = input.int(50, title="Second MACD Signal Length")

// Input for ATR Trailing
atrMultiplier = input.float(1.5, title="ATR Multiplier for Trailing")

// Inputs for Stop Loss
atrStopMultiplier = input.float(1.0, title="ATR Multiplier for Stop Loss")

// MACD Calculations
[macdLine1, signalLine1, macdHist1] = ta.macd(close, fastLength1, slowLength1, signalLength1)
[macdLine2, signalLine2, macdHist2] = ta.macd(close, fastLength2, slowLength2, signalLength2)

// Get 15M MACD histogram colors
macdHist1Color = request.security(syminfo.tickerid, "15", (macdHist1 >= 0 ? (macdHist1[1] < macdHist1 ? #26A69A : #B2DFDB) : (macdHist1[1] < macdHist1 ? #FFCDD2 : #FF5252)))
macdHist2Color = request.security(syminfo.tickerid, "15", (macdHist2 >= 0 ? (macdHist2[1] < macdHist2 ? #26A69A : #B2DFDB) : (macdHist2[1] < macdHist2 ? #FFCDD2 : #FF5252)))

// Check MACD color conditions
isMacdUptrend = macdHist1Color == #26A69A and macdHist2Color == #26A69A
isMacdDowntrend = macdHist1Color == #FF5252 and macdHist2Color == #FF5252

// Function to detect strong 5M candles
isStrongCandle(open, close, high, low) =>
    body = math.abs(close - open)
    tail = math.abs(high - low) - body
    body > tail * 1.5  // Ensure body is larger than the tail

// Variables to track state
var float fiveMinuteHigh = na
var float fiveMinuteLow = na
var bool tradeExecuted = false
var bool breakoutDetected = false
var float entryPrice = na
var float stopLossPrice = na
var float longTakeProfit = na
var float shortTakeProfit = na

// Check for new 15M candle and reset flags
if ta.change(time("15"))
    tradeExecuted := false      // Reset trade execution flag
    breakoutDetected := false  // Reset breakout detection
    if isStrongCandle(open[1], close[1], high[1], low[1])
        fiveMinuteHigh := high[1]
        fiveMinuteLow := low[1]
    else
        fiveMinuteHigh := na
        fiveMinuteLow := na

// Get 1-minute close prices
close1m = request.security(syminfo.tickerid, "5", close)

// Ensure valid breakout direction and avoid double breakouts
if not na(fiveMinuteHigh) and not breakoutDetected
    for i = 1 to 3
        if close1m[i] > fiveMinuteHigh and not tradeExecuted  // 1M breakout check with close
            breakoutDetected := true
            if isMacdUptrend 
                // Open Long trade
                entryPrice := close
                stopLossPrice := close - (atrStopMultiplier * ta.atr(14))  // ATR-based stop loss
                longTakeProfit := close + (atrMultiplier * ta.atr(14)) // Initialize take profit

                strategy.entry("Long", strategy.long)
                tradeExecuted := true
            break // Exit the loop after detecting a breakout

        else if close1m[i] < fiveMinuteLow and not tradeExecuted  // 1M breakout check with close
            breakoutDetected := true
            if isMacdDowntrend
                // Open Short trade
                entryPrice := close
                stopLossPrice := close + (atrStopMultiplier * ta.atr(14))  // ATR-based stop loss
                shortTakeProfit := close - (atrMultiplier * ta.atr(14)) // Initialize take profit

                strategy.entry("Short", strategy.short)
                tradeExecuted := true
            break // Exit the loop after detecting a breakout

// Update trailing take-profit dynamically
if tradeExecuted and strategy.position_size > 0  // Long trade
    longTakeProfit := math.max(longTakeProfit, close + (atrMultiplier * ta.atr(14)))
    strategy.exit("Long TP/SL", "Long", stop=stopLossPrice, limit=longTakeProfit)

else if tradeExecuted and strategy.position_size < 0  // Short trade
    shortTakeProfit := math.min(shortTakeProfit, close - (atrMultiplier * ta.atr(14)))
    strategy.exit("Short TP/SL", "Short", stop=stopLossPrice, limit=shortTakeProfit)

// Reset trade state when position is closed
if strategy.position_size == 0
    tradeExecuted := false
    entryPrice := na
    longTakeProfit := na
    shortTakeProfit := na