이중 이동 평균 크로스오버 화살표 전략

저자:차오장, 날짜: 2023-11-21 17:00:49
태그:

img

전반적인 설명

이 전략은 MACD 지표의 이중 이동 평균의 교차를 계산하여 구매 및 판매 신호를 식별합니다. 거래 신호를 표시하기 위해 차트에 화살표를 표시합니다.

원칙

이 전략은 먼저 빠른 라인 (12주기 EMA), 느린 라인 (26주기 EMA) 및 MACD 차이를 계산합니다. 다음에는 빠른 라인과 느린 라인의 교차와 MACD 차이의 긍정적 / 부정적인 값을 기반으로 긴 신호와 짧은 신호를 결정합니다.

  1. 빠른 선이 느린 선 (황금 십자) 을 넘고 MACD 차이는 0을 넘으면 구매 신호입니다.
  2. 빠른 선이 느린 선 아래로 넘어가고 MACD 차이는 0 아래로 넘어가면 판매 신호입니다.

잘못된 신호를 필터링하기 위해, 코드는 또한 이전 촛불의 신호를 검사합니다. 현재의 신호는 이전 촛불이 반대 신호 (구입 대 판매 또는 반대로) 를 가지고있는 경우에만 트리거됩니다.

또한, 화살표에는 구매 및 판매 신호를 표시하기 위해 화살표 모양이 그려져 있습니다.

장점

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

  1. 이중 이동 평균 크로스오버를 사용하면 트렌드를 식별하고 시장 소음을 필터링 할 수 있습니다.
  2. MACD 차이를 포함하면 놓친 거래와 잘못된 신호가 피할 수 있습니다.
  3. 화살표는 입구와 출구를 명확하게 표시합니다.
  4. 단순하고 이해하기 쉬운 규칙은 복제를 촉진합니다.

위험 과 해결책

이 전략의 몇 가지 위험:

  1. 크로스오버는 잘못된 신호를 생성하고 과도한 거래를 유발할 수 있습니다. 매개 변수를 조정하거나 가짜 신호를 줄이기 위해 추가 필터를 추가 할 수 있습니다.
  2. 트렌드에서 범위를 구별할 수 없으므로 손실이 발생할 수 있습니다. ADX와 같은 트렌드 지표를 추가하면 이것을 피할 수 있습니다.
  3. 고정된 규칙은 변화하는 시장에 적응할 수 없습니다. 기계 학습은 이것을 최적화 할 수 있습니다.

더 나은 기회

전략을 개선할 수 있는 몇 가지 방법:

  1. 빠른 라인, 느린 라인 및 MACD를 위한 최적의 설정을 찾기 위해 다른 매개 변수 조합을 테스트
  2. 필터 신호에 볼륨 브레이크와 같은 추가 입력 조건을 추가합니다
  3. 단일 거래 손실을 제어하기 위해 스톱 손실을 포함
  4. VIX와 같은 변동성 지표를 사용하여 위험욕을 측정합니다.
  5. 고정된 규칙 대신 기계 학습 모델을 사용해 적응 최적화를 만들 수 있습니다.

요약

이중 이동 평균 크로스오버 화살표 전략은 상당히 간단하고 실용적입니다. 두 이동 평균의 크로스오버와 MACD 차이 필터링을 사용하여 중간 및 장기 트렌드 중에 입출구를 식별하여 놓친 가격 반전을 피합니다. 화살표 신호는 또한 명확한 운영 지침을 제공합니다. 매개 변수 조정, 추가 필터 및 적응적 최적화로 안정성과 수익성이 더 향상 될 수 있습니다.


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

//@version=3
//Daniels stolen code
strategy(shorttitle="Daniels Stolen Code", title="Daniels Stolen Code", overlay=true, calc_on_order_fills=true, pyramiding=0)

//Define MACD Variables
fast = 12, slow = 26
fastMACD = ema(hlc3, fast)
slowMACD = ema(hlc3, slow)
macd = fastMACD - slowMACD
signal = sma(macd, 9)
hist = macd - signal
currMacd = hist[0]
prevMacd = hist[1]
currPrice = hl2[0]
prevPrice = hl2[1]

buy = currPrice > prevPrice and currMacd > prevMacd
sell = currPrice < prevPrice and currMacd < prevMacd
neutral = (currPrice < prevPrice and currMacd > prevMacd) or (currPrice > prevPrice and currMacd < prevMacd)
//Plot Arrows

timetobuy = buy==1 and (sell[1]==1 or (neutral[1]==1 and sell[2]==1) or (neutral[1]==1 and neutral[2]==1 and sell[3]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and sell[4]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and neutral[4]==1 and sell[5]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and neutral[4]==1 and neutral[5]==1 and sell[6]==1))
timetosell = sell==1 and (buy[1]==1 or (neutral[1]==1 and buy[2]==1) or (neutral[1]==1 and neutral[2]==1 and buy[3]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and buy[4]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and neutral[4]==1 and buy[5]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and neutral[4]==1 and neutral[5]==1 and buy[6]==1))

plotshape(timetobuy, color=blue, location=location.belowbar, style=shape.arrowup)
plotshape(timetosell, color=red, location=location.abovebar, style=shape.arrowdown)
//plotshape(neutral, color=black, location=location.belowbar, style=shape.circle)


//Test Strategy
// strategy.entry("long", true, 1, when = timetobuy and time > timestamp(2017, 01, 01, 01, 01)) // buy by market if current open great then previous high
// strategy.close("long", when = timetosell and time > timestamp(2017, 01, 01, 01, 01))

strategy.order("buy", true, 1, when=timetobuy==1 and time > timestamp(2019, 01, 01, 01, 01))
strategy.order("sell", false, 1, when=timetosell==1 and time > timestamp(2019, 01, 01, 01, 01))



// strategy.entry(id = "Short", long = false, when = enterShort())
// strategy.close(id = "Short", when = exitShort())

//strategy.entry("long", true, 1, when = open > high[1]) // enter long by market if current open great then previous high
// strategy.exit("exit", "long", profit = 10, loss = 5) // ge

더 많은