이중 이동 평균 역전 전략

저자:차오장, 날짜: 2023-11-22 10:07:19
태그:

img

전반적인 설명

이 전략의 주요 아이디어는 빠른 이동 평균과 느린 이동 평균의 교차를 사용하여 시장 트렌드를 판단하고 단기 및 장기 이동 평균이 역전될 때 위치를 취하여 트렌드를 추적하는 효과를 달성하는 것입니다.

전략 논리

  1. 단기 이동 평균 기간 shortma (7일 기본) 및 장기 이동 평균 기간 longma (77일 기본) 를 설정합니다.
  2. 짧은 MA가 긴 MA를 넘을 때, 그것은 구매 신호 및 기록 바로 결정됩니다. 긴 MA는 상승 추세가 시작되었음을 암시합니다. 짧은 MA가 긴 MA를 넘을 때, 그것은 판매 신호 및 기록 바로 결정됩니다. 긴 MA는 상승 추세가 끝났다는 것을 암시합니다.
  3. 바스 시인치 값을 비교하십시오. 짧은 MA가 아래로 넘어가면서 더 많은 바가 많을수록 상승 추세는 더 오래 지속되었습니다. 짧은 MA가 위로 넘어가면서 더 많은 바가 많을수록 역전 신호가 강합니다.
  4. 판매 신호의 바스센스가 구매 신호의 바스센스보다 크면 구매 신호가 발사됩니다. 구매 신호의 바스센스가 판매 신호의 바스센스보다 크면 판매 신호가 발사됩니다.
  5. 기본적으로 이것은 트렌드 반전 지점을 탐지하기 위해 빠르고 느린 MA의 교차 반전을 사용하는 이중 MA 반전 전략입니다.

장점

  1. 일부 잘못된 신호를 필터하기 위해 이중 MAs를 사용합니다
  2. 비교가 잘못된 파업과 가까운 가격 반전을 피하기 때문에 추가 바
  3. 이해하기 쉽고 실행하기 쉽다
  4. 사용자 정의 가능한 MA 매개 변수는 다른 기간과 시장에 적합합니다

위험성

  1. 듀얼 MA 전략은 더 빈번한 거래 신호를 생성하는 경향이 있습니다.
  2. 잘못된 MA 매개 변수 조정으로 더 긴 트렌드를 놓칠 수 있습니다.
  3. 장기 MAs가 깨질 때 손실을 멈추는 것은 멀리 떨어져 있어 더 큰 마감으로 이어질 수 있습니다.
  4. 코일과 오시슬레이션을 효과적으로 필터링 할 수 없습니다.

개선 방향

  1. 다른 지표들을 추가하여 다양한 시장에서 위프사를 피합니다.
  2. 스톱 로스 메커니즘을 추가
  3. MA 매개 변수 조합을 최적화
  4. 시장 주기를 기반으로 MA 매개 변수를 동적으로 조정합니다.

요약

이 전략은 전반적으로 명확하고 이해하기 쉬운 논리를 가지고 있으며, 트렌드 반전 지점을 탐지하기 위해 빠르고 느린 MA 반전을 사용합니다. 이론적으로는 트렌드를 효과적으로 추적 할 수 있습니다. 그러나 실제 구현에서는 여전히 알고리즘 자체를 최적화하고 매개 변수를 조정하여 더욱 견고하고 실용화해야합니다.


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

//@version=3
strategy("Up Down", "Up Down", precision = 6, pyramiding = 1, default_qty_type = strategy.percent_of_equity, default_qty_value = 99, commission_type = strategy.commission.percent, commission_value = 0.0, initial_capital = 1000, overlay = true)

buy = close > open and open > close[1]
sell = close < open and open < close[1]

longma = input(77,"Long MA Input")
shortma = input(7,"Short MA Input")
long = sma(close,longma)
short = sma(close, shortma)
mabuy = crossover(short,long) or buy and short > long
masell = crossunder(short,long) or sell and short > long

num_bars_buy = barssince(mabuy)
num_bars_sell = barssince(masell)
//plot(num_bars_buy, color = teal)
//plot(num_bars_sell, color = orange)

xbuy = crossover(num_bars_sell, num_bars_buy)
xsell = crossunder(num_bars_sell, num_bars_buy)
plotshape(xbuy,"Buy Up Arrow", shape.triangleup, location.belowbar, white, size = size.tiny)
plotshape(xsell,"Sell Down Arrow", shape.triangledown, location.abovebar, white, size = size.tiny)
plot(long,"Long MA", fuchsia, 2)

// Component Code Start
// Example usage:
// if testPeriod()
//   strategy.entry("LE", strategy.long)
testStartYear = input(2017, "Backtest Start Year")
testStartMonth = input(01, "Backtest Start Month")
testStartDay = input(2, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)

testStopYear = input(2019, "Backtest Stop Year")
testStopMonth = input(7, "Backtest Stop Month")
testStopDay = input(30, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)

// A switch to control background coloring of the test period
testPeriodBackground = input(title="Color Background?", type=bool, defval=true)
testPeriodBackgroundColor = testPeriodBackground and (time >= testPeriodStart) and (time <= testPeriodStop) ? #00FF00 : na
bgcolor(testPeriodBackgroundColor, transp=97)

testPeriod() => true
// Component Code Stop

if testPeriod()
    strategy.entry("buy", true, when = xbuy, limit = close)
    strategy.close("buy", when = xsell)


더 많은