모멘텀 브레이크 이동 평균 전략

저자:차오장, 날짜: 2023-11-27 16:25:54
태그:

img

전반적인 설명

모멘텀 브레이크아웃 이동 평균 전략 (Momentum Breakout Moving Average) 은 이동 평균 크로스오버 신호를 운동량 지표와 결합한 주식 거래 전략이다. 이 전략은 기하급수적인 이동 평균 (EMA), 간단한 이동 평균 (SMA), 이동 평균 컨버전스 디버전스 (MACD), 수정된 상대 강도 지표 (StockRSI) 를 포함한 여러 기술적 지표를 사용하여 장기 상승 추세를 확인 할 때 구매 신호를 생성합니다. 단기 운동량 지표가 역전 신호를 표시하면 전략은 이익을 취합니다.

전략 논리

이 전략의 주요 구성 요소는 다음과 같습니다.

  1. EMA/SMA 크로스오버: 9주기 EMA 빠른 라인은 21주기 SMA 느린 라인의 위를 넘어서 구매 신호를 발사합니다.

  2. MACD 지표: MACD 히스토그램은 EMA/SMA 크로스오버 신호와 결합했을 때 긍정적이어야 합니다. 추가 확인으로요.

  3. 주식RSI 지표: StockRSI가 OVERBOUGHT 수준 (80) 이상 또는 OVERSOLD 수준 (20) 이하일 때 신호가 발사됩니다.

  4. 볼링거 밴드: 중간 지대가 20주기 SMA이고 지대의 폭이 2개의 표준편차인 지대 내에 있어야 합니다.

  5. 손실 을 멈추고 이득 을 취하라: 14주기 ATR을 기준으로 계산됩니다.

이 전략은 3개 지표 중 적어도 2개가 구매 신호를 제공하도록 요구하며, 가격은 볼링거 밴드 내에 있으며, 장기 트렌드는 최종 구매 신호를 생성하기 위해 상승세를 유지합니다. MACD 히스토그램이 음으로 변하고 StockRSI가 과잉 구매 지역에 진입하면 판매 신호를 제공합니다.

이점 분석

이 전략의 주요 강점은 다음과 같습니다.

  1. 탁월 한 백테스트 결과: 여러 가지 검증된 지표가 벤치마크와 개별 지표보다 더 나은 성과를 가져옵니다.

  2. 최적화된 매개 변수: EMA 기간과 볼링거 밴드 같은 주요 매개 변수는 안정성을 향상시키기 위해 최적화됩니다.

  3. 자동 스톱 손실/이익 취득: 볼링거 반드와 ATR는 더 나은 위험 통제를 위해 동적 정지 조정을 허용합니다.

  4. 적용 하기 쉽다: 깔끔한 코드 구조와 쉬운 데이터 접근성으로 인해 간단한 실제 작업이 가능합니다.

위험 분석

좋은 성과에도 불구하고 주요 위험은 다음과 같습니다.

  1. 거짓 신호: 비정상적인 시장 변동 또는 지표의 장애가 잘못된 신호를 생성 할 수 있습니다.

  2. 부적절 한 매개 변수: 부적절한 매개 변수는 너무 빈번한 거래 또는 불충분한 감수성으로 이어질 수 있습니다. 매개 변수는 다른 제품과 시장 환경에 따라 조정되어야합니다.

  3. 부적절한 스톱 손실: 너무 좁은 스톱 로스는 조기 중단되는 경향이 있으며, 너무 넓은 스톱 로스는 과도한 손실을 초래할 수 있습니다. 스톱 로스와 이익 취득 수준 사이의 적절한 균형을 달성해야합니다.

위의 위험을 해결하기 위해 다음과 같은 조치를 취할 수 있습니다.

  1. 수동 개입: 비정상적인 상황에서는 신호를 수동으로 검사하거나 매개 변수를 재조정하거나 전략을 일시 중단할 수 있습니다.

  2. 매개 변수 최적화: 유전 알고리즘과 같은 보다 과학적이고 객관적인 방법은 체계적인 최적화를 위해 사용될 수 있습니다.

  3. 변동성 조정 정지: 스톱 로스 범위는 변동성을 반영하기 위해 ATR의 1-3배로 설정할 수 있습니다.

더 나은 기회

이 전략은 다음 영역에서 더 향상될 수 있습니다.

  1. 더 강력한 스톱 로스 메커니즘: 트래일링 스톱 로스 또는 이동 평균에 기반한 스톱을 포함할 수 있습니다.

  2. 부피 필터: 가짜 파장을 피하기 위해 부피 지표를 추가합니다.

  3. 동적 매개 변수: 자동으로 이동 평균 기간과 대역 폭과 같은 매개 변수를 최적화합니다. 시장 조건의 변화에 따라.

  4. 기계 학습: LSTM, RNN 및 다른 알고리즘은 매개 변수의 동적 최적화를 가능하게합니다.

결론

모멘텀 브레이크아웃 이동 평균 전략은 여러 기술적 지표를 결합하는 장점을 활용하고 장기 및 단기 확인으로 적당한 수익성을 달성했습니다. 좋은 리스크 제어 절차가 실행되면이 전략은 더 일관된 알파 수익을 달성하기 위해 스톱 손실 메커니즘 및 신호 필터링과 같은 영역에서 추가 개선에 대한 충분한 잠재력을 가지고 있습니다.


/*backtest
start: 2022-11-20 00:00:00
end: 2023-11-26 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Improved Custom Strategy", shorttitle="ICS", overlay=true)

// Volatility
volatility = ta.atr(14)

// EMA/MA Crossover
fast_length = 9
slow_length = 21
fast_ma = ta.ema(close, fast_length)
slow_ma = ta.sma(close, slow_length)
crossover_signal = ta.crossover(fast_ma, slow_ma)

// MACD
[macdLine, signalLine, macdHistogram] = ta.macd(close, 12, 26, 9)
macd_signal = crossover_signal and (macdHistogram > 0)

// Bollinger Bands
source = close
basis = ta.sma(source, 20)
upper = basis + 2 * ta.stdev(source, 20)
lower = basis - 2 * ta.stdev(source, 20)

// Fractal-based Support and Resistance levels
isFractalHigh = high[2] < high[1] and high[1] > high[0]
isFractalLow = low[2] > low[1] and low[1] < low[0]
resistance = ta.valuewhen(isFractalHigh, high[1], 0)
support = ta.valuewhen(isFractalLow, low[1], 0)

// StockRSI
length = 14
K = 100 * (close - ta.lowest(close, length)) / (ta.highest(close, length) - ta.lowest(close, length))
D = ta.sma(K, 3)
overbought = 80
oversold = 20
stockrsi_signal = ((K < D) and (K < oversold)) or ((K > D) and (K > overbought))

// Buy and sell conditions
mandatory_buy_conditions = (crossover_signal ? 1 : 0) + (macd_signal ? 1 : 0) + (stockrsi_signal ? 1 : 0)

// Long-term Trend Check
long_term_ma = ta.sma(close, 200)
long_term_bullish = close > long_term_ma
long_term_bearish = close < long_term_ma

// Plot the long-term MA for visual clarity
plot(long_term_ma, color=color.gray, title="200-Day MA", linewidth=1)

// Simplified Buy and Sell conditions
buy_condition = long_term_bullish and (mandatory_buy_conditions >= 2) and (close > lower) and (close < upper)
sell_condition = (macdHistogram < 0) and (K > D) and (K > overbought)


// Potential SL and TP based on volatility
potential_SL = close - volatility
potential_TP = close + 2 * volatility

plot(potential_SL, title="SL Level", color=color.red, linewidth=1, style=plot.style_linebr)
plot(potential_TP, title="TP Level", color=color.green, linewidth=1, style=plot.style_linebr)

// ... (rest of your code above)

// State variable to track if we're in a position, a counter for trades, and a delayed counter for plotting
var bool inPosition = false
var tradeCounter = 0
var tradeCounterDelayed = 0 // Declaration of the variable

// Buy logic: Check if tradeCounter is 0 and the buy condition is met
if tradeCounter == 0 and buy_condition
    strategy.entry("BUY", strategy.long, stop=potential_SL, limit=potential_TP)
    inPosition := true
    tradeCounter := tradeCounter + 1

// Sell logic: Check if tradeCounter is 1, the sell condition is met, and we are in a position
if tradeCounter == 1 and inPosition and sell_condition
    strategy.close("BUY")
    inPosition := false
    tradeCounter := tradeCounter - 1

// Update the delayed trade counter:
tradeCounterDelayed := tradeCounter

// Plotting
bgcolor(buy_condition ? color.new(color.green, 90) : sell_condition ? color.new(color.red, 90) : na)
plotshape(series=buy_condition and tradeCounterDelayed == 0, style=shape.labelup, location=location.belowbar, color=color.green, text="BUY", size=size.small)
plotshape(series=sell_condition and tradeCounterDelayed == 1, style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", size=size.small)

// ... (rest of your code if any)


더 많은