이동평균 회귀 돌파를 기반으로 한 추세 추종 전략


생성 날짜: 2024-02-23 14:46:37 마지막으로 수정됨: 2024-02-23 14:46:37
복사: 0 클릭수: 651
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

이동평균 회귀 돌파를 기반으로 한 추세 추종 전략

개요

평균 회귀 돌파 전략은 전형적인 트렌드를 추적하는 양적 거래 전략이다. 이 전략은 이동 평균과 표준 격차 통로를 사용하여 시장 움직임을 판단하고 가격이 표준 격차 통로를 돌파 할 때 거래 신호를 발생시킨다.

전략 원칙

이 전략은 먼저 N일 (설정된 50일) 의 간단한 이동 평균 SMA를 계산하고, 그 다음 SMA를 기반으로 그 주기의 가격의 표준 차이를 StdDev로 계산한다. SMA를 중심축으로, 위아래는 StdDev의 2배로 상하 궤도를 구성한다.

시장에 진입한 후, 전략은 손실을 중지하는 위치를 설정한다. 구체적으로, 더 많은 것을 한 후, 중단 라인은 진입 시의 종결 가격의 ((100 - 손실을 중지하는 비율); 공백 후, 중지 라인은 진입 시의 종결 가격의 ((100 + 중지하는 비율) 이다.

우위 분석

이 전략은 다음과 같은 장점을 가지고 있습니다.

  1. 트렌드 추적 능력이 강하다. 표준 차차 통로를 사용하여 동적으로 시장의 변동을 추적할 수 있다.
  2. 회수 제어 능력이 강하다. 이동식 스톱을 사용하면 단편 손실을 효과적으로 제어할 수 있다.
  3. 구현이 간단하다. 많은 변수 최적화를 절감하여 매우 쉽게 구현할 수 있다.

위험 분석

이 전략에는 몇 가지 위험도 있습니다.

  1. 트렌드 반전 위험. 트렌드 추적 전략이 손실이 빠져나와 반전될 수 있는 경우.
  2. 매개 변수 민감 위험. 이동 평균 주기 및 표준 격차 배수의 매개 변수 선택은 전략 성능에 큰 영향을 미칩니다.
  3. 너무 급진적이라 추가적인 손실이 발생할 수 있다.

위험을 대응하는 해결책은 다음과 같습니다.

  1. 변동률 지표와 함께 가짜 돌파구를 피하십시오.
  2. 매개 변수를 최적화하여 최적의 매개 변수 조합을 찾습니다.
  3. “이번 사태는 우리나라도 마찬가지입니다.

최적화 방향

이 전략에는 더 많은 최적화할 여지가 있습니다:

  1. 여러 시간 주기의 평균선을 사용하여 검증하고, 곡선이 너무 민감하지 않도록하십시오.

  2. MACD와 같은 다른 지표와 결합하여 추세와 이탈 현상을 판단한다.

  3. 기계 학습 알고리즘의 동적 최적화 매개 변수를 도입한다.

요약하다

평균선 회귀 돌파 전략은 전체적으로 매우 실용적인 수량 거래 전략이다. 그것은 추세를 추적하고, 회수 제어의 장점을 가지고 있으며, 수량 거래의 필요에 맞는 간단한 것을 구현한다. 또한 일부 파라미터 선택 및 스톱 손실 설정 문제에 주의를 기울여야하며, 다중 시간 축 분석 및 파라미터 최적화와 함께 더 나은 전략 성능을 얻을 수 있다.

전략 소스 코드
/*backtest
start: 2023-02-16 00:00:00
end: 2024-02-22 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Standard Deviation Bands with Buy/Sell Signals", overlay=true)

// Input for the number of standard deviations
deviationMultiplier = input.float(2.0, title="Standard Deviation Multiplier")

// Input for the length of the moving average
maLength = input.int(50, title="Moving Average Length")

// Input for the stop loss percentage
stopLossPercentage = input.float(12, title="Stop Loss Percentage")

// Calculate the moving average
sma = ta.sma(close, maLength)

// Calculate the standard deviation of the price
priceDeviation = ta.stdev(close, maLength)

// Calculate the upper and lower bands
upperBand = sma + (priceDeviation * deviationMultiplier)
lowerBand = sma - (priceDeviation * deviationMultiplier)

// Plot the bands
plot(upperBand, color=color.green, title="Upper Band")
plot(lowerBand, color=color.red, title="Lower Band")

// Plot the moving average
plot(sma, color=color.blue, title="SMA", linewidth=2)

// Buy Signal
buyCondition = ta.crossover(close, lowerBand)
sellCondition = ta.crossunder(close, upperBand)

// Calculate stop loss level
stopLossLevelBuy = close * (1 - stopLossPercentage / 100)
stopLossLevelSell = close * (1 + stopLossPercentage / 100)

// Create Buy and Sell Alerts
alertcondition(buyCondition, title="Buy Signal", message="Buy Signal - Price Crossed Below Lower Band")
alertcondition(sellCondition, title="Sell Signal", message="Sell Signal - Price Crossed Above Upper Band")

// Plot Buy and Sell Arrows on the chart
plotshape(buyCondition, style=shape.triangleup, location=location.belowbar, color=color.green, title="Buy Signal Arrow")
plotshape(sellCondition, style=shape.triangledown, location=location.abovebar, color=color.red, title="Sell Signal Arrow")

// Exit Long and Short Positions
var float stopLossBuy = na
var float stopLossSell = na

if ta.crossover(close, sma)
    stopLossBuy := stopLossLevelBuy
if ta.crossunder(close, sma)
    stopLossSell := stopLossLevelSell

strategy.entry("Buy", strategy.long, when = buyCondition)
strategy.exit("Stop Loss/Take Profit Buy", from_entry = "Buy", stop = stopLossBuy)
strategy.entry("Sell", strategy.short, when = sellCondition)
strategy.exit("Stop Loss/Take Profit Sell", from_entry = "Sell", stop = stopLossSell)