거래 전략에 따른 다중 기간 이동 평균 추세 모멘텀

EMA ATR KC SMA LR
생성 날짜: 2024-11-12 16:35:41 마지막으로 수정됨: 2024-11-12 16:35:41
복사: 4 클릭수: 640
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

거래 전략에 따른 다중 기간 이동 평균 추세 모멘텀

개요

이 전략은 주로 20, 50, 100 및 200일 지수 이동 평균 (EMA) 의 배열된 조합을 분석하여 일선과 주위의 동적 지표와 결합하여 거래한다. 이 전략은 ATR 중지 방식을 채택하고, EMA 동적 조건이 충족되면 출장하여 ATR의 배수를 설정하여 손실 및 수익 목표를 설정하여 위험을 관리한다.

전략 원칙

전략의 핵심 논리는 다음과 같은 핵심 부분으로 구성됩니다.

  1. EMA 조율 시스템: 20일 EMA가 50일 EMA 위에 있고, 50일 EMA가 100일 EMA 위에 있고, 100일 EMA가 200일 EMA 위에 있는 것을 요구하며, 완벽한 다목적 조율을 형성한다.
  2. 동력 확인 시스템: 일선 및 주위선 시간 주기에서 각각 계산되는 선형 회귀를 기반으로 한 사용자 정의 동력 지표. 이 동력 지표는 가격과 켈트너 통로의 중축의 오차 정도에 대한 선형 회귀를 통해 측정된다.
  3. 재조정 입시 시스템: 가격이 20일 EMA의 지정된 퍼센트 범위 내에서 재조정되어야 입시가 허용되며, 추격을 피한다.
  4. 리스크 관리 시스템: ATR의 배수를 사용하여 중지 및 수익 목표를 설정합니다. 기본 중지값은 1.5배 ATR이며 수익 목표는 3배 ATR입니다.

전략적 이점

  1. 다중 확인 메커니즘: 평균선 배열, 다중 주기 동력 및 가격 회귀 등의 다중 조건 확인을 통해 거짓 신호를 감소시킨다.
  2. 과학적인 위험 관리: ATR을 사용하여 시장의 변동성에 적응하기 위해 스톱로스 및 수익 목표를 동적으로 조정합니다.
  3. 트렌드 추적과 동력을 결합하여, 큰 트렌드를 파악할 수 있고, 트렌드 중에서도 좋은 진입 시점을 파악할 수 있습니다.
  4. 맞춤형성: 전략의 각 매개 변수는 시장 특성에 따라 최적화 조정할 수 있다.
  5. 다주기 분석: 일선과 둘레의 조합을 통해 신호의 신뢰도를 높인다.

전략적 위험

  1. 평균선 지연성: EMA는 지연된 지표로 입시 시기가 늦어질 수 있다. 다른 선도 지표와 결합하는 것이 좋습니다.
  2. 흔들리는 시장은 적용되지 않습니다: 전략은 가로판 흔들리는 시장에서 종종 거짓 신호를 생성할 수 있습니다. 시장 환경 필터를 추가하는 것이 좋습니다.
  3. 철수 위험: ATR이 중단되었지만, 극단적인 상황에서는 여전히 큰 철수가 발생할 수 있습니다. 최대 철수 제한을 설정하는 것이 고려 될 수 있습니다.
  4. 매개 변수 민감성: 전략 효과는 매개 변수 설정에 민감하다. 충분한 매개 변수 최적화 테스트를 수행하는 것이 좋습니다.

전략 최적화 방향

  1. 시장 환경 식별: 변동률 지표 또는 트렌드 강도 지표를 추가하여 다른 시장 환경에서 다른 파라미터 조합을 사용합니다.
  2. 입력 최적화: RSI와 같은 변동 지표를 추가하여 회귀 영역에서 더 정확한 입력 지점을 찾을 수 있습니다.
  3. 동적 변수 조정: 시장의 변동성에 따라 ATR 배수 및 회귀 범위를 자동으로 조정한다.
  4. 거래량 분석에 추가: 거래량으로 트렌드 강도를 확인하여 신호 신뢰도를 높인다.
  5. 기계 학습을 도입: 기계 학습 알고리즘을 사용하여 동적으로 최적화 파라미터를 사용하여 전략 적응성을 향상시킵니다.

요약하다

이것은 합리적이고 논리적으로 엄격한 트렌드 추적 전략을 설계한다. 다중 기술 지표의 조합 사용으로 전략의 안정성이 보장되고 좋은 위험 관리 장치가 제공됩니다. 전략의 사용자 정의가 강하여 시장 특성에 따라 최적화 할 수 있습니다. 일부 고유한 위험이 있지만, 제안 된 최적화 방향으로 전략의 성능을 더욱 향상시킬 수 있습니다.

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

//@version=5
strategy("Swing Trading with EMA Alignment and Custom Momentum", overlay=true)

// User inputs for customization
atrLength = input.int(14, title="ATR Length", minval=1)
atrMultiplierSL = input.float(1.5, title="Stop-Loss Multiplier (ATR)", minval=0.1)   // Stop-loss at 1.5x ATR
atrMultiplierTP = input.float(3.0, title="Take-Profit Multiplier (ATR)", minval=0.1)   // Take-profit at 3x ATR
pullbackRangePercent = input.float(1.0, title="Pullback Range (%)", minval=0.1) // 1% range for pullback around 20 EMA
lengthKC = input.int(20, title="Length for Keltner Channels (Momentum Calculation)", minval=1)

// EMA settings
ema20 = ta.ema(close, 20)
ema50 = ta.ema(close, 50)
ema100 = ta.ema(close, 100)
ema200 = ta.ema(close, 200)

// ATR calculation
atrValue = ta.atr(atrLength)

// Custom Momentum Calculation based on Linear Regression for Daily Timeframe
highestHighKC = ta.highest(high, lengthKC)
lowestLowKC = ta.lowest(low, lengthKC)
smaCloseKC = ta.sma(close, lengthKC)

// Manually calculate the average of highest high and lowest low
averageKC = (highestHighKC + lowestLowKC) / 2

// Calculate daily momentum using linear regression
dailyMomentum = ta.linreg(close - (averageKC + smaCloseKC) / 2, lengthKC, 0) // Custom daily momentum calculation

// Fetch weekly data for momentum calculation using request.security()
[weeklyHigh, weeklyLow, weeklyClose] = request.security(syminfo.tickerid, "W", [high, low, close])

// Calculate weekly momentum using linear regression on weekly timeframe
weeklyHighestHighKC = ta.highest(weeklyHigh, lengthKC)
weeklyLowestLowKC = ta.lowest(weeklyLow, lengthKC)
weeklySmaCloseKC = ta.sma(weeklyClose, lengthKC)
weeklyAverageKC = (weeklyHighestHighKC + weeklyLowestLowKC) / 2

weeklyMomentum = ta.linreg(weeklyClose - (weeklyAverageKC + weeklySmaCloseKC) / 2, lengthKC, 0) // Custom weekly momentum calculation

// EMA alignment condition (20 EMA > 50 EMA > 100 EMA > 200 EMA)
emaAligned = ema20 > ema50 and ema50 > ema100 and ema100 > ema200

// Momentum increasing condition (daily and weekly momentum is positive and increasing)
dailyMomentumIncreasing = dailyMomentum > 0 and dailyMomentum > dailyMomentum[1] //and dailyMomentum[1] > dailyMomentum[2]
weeklyMomentumIncreasing = weeklyMomentum > 0 and weeklyMomentum > weeklyMomentum[1] //and weeklyMomentum[1] > weeklyMomentum[2]

// Redefine Pullback condition: price within 1% range of the 20 EMA
upperPullbackRange = ema20 * (1 + pullbackRangePercent / 100)
lowerPullbackRange = ema20 * (1 - pullbackRangePercent / 100)
pullbackToEma20 = (close <= upperPullbackRange) and (close >= lowerPullbackRange)

// Entry condition: EMA alignment and momentum increasing on both daily and weekly timeframes
longCondition = emaAligned and dailyMomentumIncreasing and weeklyMomentumIncreasing and pullbackToEma20

// Initialize stop loss and take profit levels as float variables
var float longStopLevel = na
var float longTakeProfitLevel = na

// Calculate stop loss and take profit levels based on ATR
if (longCondition)
    longStopLevel := close - (atrMultiplierSL * atrValue)  // Stop loss at 1.5x ATR below the entry price
    longTakeProfitLevel := close + (atrMultiplierTP * atrValue) // Take profit at 3x ATR above the entry price

// Strategy execution
if (longCondition)
    strategy.entry("Long", strategy.long)

// Exit conditions: Stop-loss at 1.5x ATR and take-profit at 3x ATR
if (strategy.position_size > 0)
    strategy.exit("Take Profit/Stop Loss", "Long", stop=longStopLevel, limit=longTakeProfitLevel)