모멘텀 이동 평균 거래 전략


생성 날짜: 2024-01-24 11:09:58 마지막으로 수정됨: 2024-01-24 11:09:58
복사: 0 클릭수: 614
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

모멘텀 이동 평균 거래 전략

개요

이 전략은 빠른 EMA를 통과할 때 시장이 상승 추세에 있다고 판단하고 구매 신호를 생성한다. 빠른 EMA를 통과할 때 시장이 하향 추세에 있다고 판단하고 판매 신호를 생성한다. 전략은 또한 위험을 관리하기 위해 중지 및 중지 가격을 설정한다.

전략 원칙

이 전략은 빠른 EMA ((8일선) 과 느린 EMA ((21일선) 의 교차를 사용하여 시장의 흐름을 판단합니다. 구체적인 논리는 다음과 같습니다:

  1. 8일 EMA와 21일 EMA를 계산해
  2. 8일 EMA가 21일 EMA를 통과했을 때, 시장의 변동으로 판단하여 상승 추세가 시작됩니다.
  3. 8일 EMA가 21일 EMA를 통과했을 때, 시장의 변동으로 판단하여 하향 추세가 시작됩니다.
  4. 상승 추세에 있어서는 구매 신호를 생성하고, 하향 추세에 있어서는 판매 신호를 생성합니다.
  5. 각 주문에 대한 위험을 관리하기 위해 스톱로스 및 스톱 가격을 설정합니다.

이 전략은 역량 지표와 트렌드 분석을 결합하여 시장의 방향과 역점을 효과적으로 포착할 수 있습니다. 빠른 EMA 교차와 평평한 이동 평균을 결합하여 일부 잡음 거래 신호를 필터링 할 수 있습니다.

우위 분석

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

  1. 빠른 EMA와 느린 EMA의 교차는 시장의 추세와 매매 지점을 효과적으로 판단할 수 있습니다.
  2. 전략 파라미터를 최적화할 수 있으며, EMA 주기를 추가 조정할 수 있습니다.
  3. 동량 지표와 결합하여 노이즈 신호를 효과적으로 필터링 할 수 있습니다.
  4. 스탠드피드 로직을 설정하여 위험을 능동적으로 제어할 수 있습니다.

전체적으로, 이 전략은 추세와 동력 지표를 결합하고, 파라미터를 조정하여 다른 시장 환경에 적응할 수 있으며, 비교적 유연한 단선 거래 전략이다.

위험 분석

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

  1. 위기 상황에서 EMA 교차 신호가 자주 발생하여 잘못된 거래가 더 많이 발생합니다.
  2. 공중공간을 효과적으로 처리할 수 없는 상황
  3. 하지만, 그 중에서도 가장 중요한 것은,

이러한 위험들에 대해, 우리는 다음과 같은 몇 가지 측면에서 최적화할 수 있습니다:

  1. 다른 지표 필터를 추가하여 잘못된 신호의 가능성을 줄여줍니다.
  2. 더 큰 차원의 주기적 지표와 결합하여 장기적 추세를 판단하는 방법
  3. 최적화 매개 변수, 다양한 시장 환경에 맞게 EMA 길이를 조정
  4. 인위적 개입 거래, 부수적 공백을 피하여 막대한 손실을 방지하기 위해

최적화 방향

이 전략의 최적화 공간은 매우 넓고, 다음과 같은 방향으로 진행될 수 있습니다.

  1. EMA 주기 변수를 최적화하고, 역사 데이터에 대한 수익률에 대해 다른 변수를 테스트합니다.
  2. KDJ, MACD 등과 같은 다른 기술 지표에 필터링을 추가하여 전략 정확도를 향상시킵니다.
  3. 스톱 스톱 설정을 최적화하여 실황 특성에 더 적합하게 만듭니다.
  4. 기계 학습 방법을 통해 자동으로 최적화 된 매개 변수

이러한 최적화 조치는 전략의 안정성, 적응성 및 수익성을 크게 향상시킬 수 있습니다.

요약하다

이 전략은 전체적으로 트렌드 추적과 동력 지표의 교차를 기반으로 한 전형적인 짧은 라인 거래 전략입니다. 이 전략은 EMA 빠른 느린 라인 교차와 손해 중지 논리를 결합하여 시장 방향의 기회를 신속하게 포착 할 수 있습니다. 이 전략의 최적화 공간은 매우 넓고, 다른 보조 지표, 자동 매개 변수 최적화 등의 방법을 추가로 도입하면 전략의 성과를 더 안정적이고 우수하게 만들 수 있습니다. 이 전략은 시장에 대한 확실성을 알고 자주 작동하기를 원하는 투자자에게 적합합니다.

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

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TradersPostInc

//@version=5
strategy('TradersPost Example MOMO Strategy', overlay=true)

startTime = input(defval = timestamp('01 Jan 2021 00:00 +0000'), title = 'Start Time', group = 'Date Range')
endTime = input(defval = timestamp('31 Dec 2023 23:59 +0000'), title = 'End Time', group = 'Date Range')
timeCondition = true
timeConditionEnd = timeCondition[1] and not timeCondition

fastEmaLength = input.int(defval = 8, title = 'Fast EMA Length')
slowEmaLength = input.int(defval = 21, title = 'Slow EMA Length')
sides = input.string(defval = 'Both', title = 'Sides', options = ['Long', 'Short', 'Both', 'None'])

fastEma = ta.ema(close, fastEmaLength)
slowEma = ta.ema(close, slowEmaLength)

isUptrend = fastEma >= slowEma
isDowntrend = fastEma <= slowEma
trendChanging = ta.cross(fastEma, slowEma)

ema105 = request.security(syminfo.tickerid, '30', ta.ema(close, 105)[1], barmerge.gaps_off, barmerge.lookahead_on)
ema205 = request.security(syminfo.tickerid, '30', ta.ema(close, 20)[1], barmerge.gaps_off, barmerge.lookahead_on)
plot(ema105, linewidth=4, color=color.new(color.purple, 0), editable=true)
plot(ema205, linewidth=2, color=color.new(color.purple, 0), editable=true)

aa = plot(fastEma, linewidth=3, color=color.new(color.green, 0), editable=true)
bb = plot(slowEma, linewidth=3, color=color.new(color.red, 0), editable=true)
fill(aa, bb, color=isUptrend ? color.green : color.red, transp=90)

tradersPostBuy = trendChanging and isUptrend and timeCondition
tradersPostSell = trendChanging and isDowntrend and timeCondition

pips = syminfo.pointvalue / syminfo.mintick

percentOrPipsInput = input.string('Percent', title='Percent or Pips', options=['Percent', 'Pips'])

stopLossLongInput = input.float(defval=0, step=0.01, title='Stop Loss Long', minval=0)
stopLossShortInput = input.float(defval=0, step=0.01, title='Stop Loss Short', minval=0)

takeProfitLongInput = input.float(defval=0, step=0.01, title='Target Profit Long', minval=0)
takeProfitShortInput = input.float(defval=0, step=0.01, title='Target Profit Short', minval=0)

stopLossPriceLong = ta.valuewhen(tradersPostBuy, close, 0) * (stopLossLongInput / 100) * pips
stopLossPriceShort = ta.valuewhen(tradersPostSell, close, 0) * (stopLossShortInput / 100) * pips

takeProfitPriceLong = ta.valuewhen(tradersPostBuy, close, 0) * (takeProfitLongInput / 100) * pips
takeProfitPriceShort = ta.valuewhen(tradersPostSell, close, 0) * (takeProfitShortInput / 100) * pips

takeProfitALong = takeProfitLongInput > 0 ? takeProfitLongInput : na
takeProfitBLong = takeProfitPriceLong > 0 ? takeProfitPriceLong : na

takeProfitAShort = takeProfitShortInput > 0 ? takeProfitShortInput : na
takeProfitBShort = takeProfitPriceShort > 0 ? takeProfitPriceShort : na

stopLossALong = stopLossLongInput > 0 ? stopLossLongInput : na
stopLossBLong = stopLossPriceLong > 0 ? stopLossPriceLong : na

stopLossAShort = stopLossShortInput > 0 ? stopLossShortInput : na
stopLossBShort = stopLossPriceShort > 0 ? stopLossPriceShort : na

takeProfitLong = percentOrPipsInput == 'Pips' ? takeProfitALong : takeProfitBLong
stopLossLong = percentOrPipsInput == 'Pips' ? stopLossALong : stopLossBLong
takeProfitShort = percentOrPipsInput == 'Pips' ? takeProfitAShort : takeProfitBShort
stopLossShort = percentOrPipsInput == 'Pips' ? stopLossAShort : stopLossBShort

buyAlertMessage = '{"ticker": "' + syminfo.ticker + '", "action": "buy", "price": ' + str.tostring(close) + '}'
sellAlertMessage = '{"ticker": "' + syminfo.ticker + '", "action": "sell", "price": ' + str.tostring(close) + '}'

exitLongAlertMessage = '{"ticker": "' + syminfo.ticker + '", "action": "exit", "price": ' + str.tostring(close) + '}'
exitShortAlertMessage = '{"ticker": "' + syminfo.ticker + '", "action": "exit", "price": ' + str.tostring(close) + '}'

if (sides != "None")
    if tradersPostBuy
        strategy.entry('Long', strategy.long, when = sides != 'Short', alert_message = buyAlertMessage)
        strategy.close('Short', when = sides == "Short" and timeCondition, alert_message = exitShortAlertMessage)

    if tradersPostSell
        strategy.entry('Short', strategy.short, when = sides != 'Long', alert_message = sellAlertMessage)
        strategy.close('Long', when = sides == 'Long', alert_message = exitLongAlertMessage)

exitAlertMessage = '{"ticker": "' + syminfo.ticker + '", "action": "exit"}'

strategy.exit('Exit Long', from_entry = "Long", profit = takeProfitLong, loss = stopLossLong, alert_message = exitAlertMessage)
strategy.exit('Exit Short', from_entry = "Short", profit = takeProfitShort, loss = stopLossShort, alert_message = exitAlertMessage)

strategy.close_all(when = timeConditionEnd)