이중 이동 평균 추세 추종 전략


생성 날짜: 2023-09-18 21:57:00 마지막으로 수정됨: 2023-09-18 21:57:00
복사: 1 클릭수: 646
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

개요

이 전략은 빠른 이동 평균과 느린 이동 평균의 조합을 사용하여 트렌드 방향을 판단합니다. 빠른 라인이 느린 라인을 뚫을 때 거래 신호를 생성합니다. 이중 이동 평균 거래 시스템 중 하나입니다.

원칙

이 전략은 짧은 길이의 빠른 이동 평균과 긴 긴 느린 이동 평균을 사용합니다.

느린MA는 주 트렌드 방향을 판단하는 데 사용됩니다. 가격이 MA 위에있을 때, 상승 트렌드로 판단하고, 가격이 MA 아래에있을 때, 하향 트렌드로 판단합니다.

상승 트렌드에서, 빠른 MA 위에 느린 MA를 뚫으면 구매 신호를 생성한다. 하향 트렌드에서, 빠른 MA 아래에 느린 MA를 뚫으면 판매 신호를 생성한다.

거래 신호가 발생하면, 스톱로스를 계속 추적할 수 있도록 스톱로스를 설정할 수 있습니다.

장점

  1. MA 조합은 트렌드를 효과적으로 식별할 수 있습니다.

  2. 빠른 MA는 좀 더 민감한 거래 신호를 생성할 수 있다.

  3. 마켓 소음을 제거하고 가짜 돌파를 방지하기 위해 천천히 MA를 사용하십시오.

  4. 다양한 MA 알고리즘을 선택할 수 있습니다.

  5. 손해지기를 추적할 수 있는 Stop Loss 전략이 활성화됩니다.

위험과 해결책

  1. MA에는 지연 문제가 있으며, 신호 지연으로 이어질 수 있다. 보다 민감한 파라미터를 테스트할 수 있다.

  2. 정지점은 지나치게 가까이 접근하여 파격으로 인해 손실이 발생할 수 있다. 적절한 변동 공간을 남겨 두어야 한다.

  3. 거래량을 고려하지 않고 가격 조작의 위험이 있습니다. 거래량 확인을 추가할 수 있습니다.

  4. 단지 지표에 근거하여 잘못된 신호를 발생시킬 수 있다. 다른 요소를 추가하여 확인이 가능하다.

  5. 매개 변수 최적화 난이도. 단계적 최적화 또는 유전 알고리즘을 사용하여 최적의 매개 변수를 찾을 수 있다.

더 나은 생각

  1. 다른 MA 알고리즘의 변수를 테스트하여 최적의 변수를 찾는다.

  2. 감수성을 높이기 위해 이동 평균을 연구합니다.

  3. 다른 지표 또는 요소를 추가하여 신호 필터링을 최적화한다.

  4. 역동적인 손해배상 제도를 구축하여 손해배상 제도를 보다 유연하게 할 수 있도록 한다.

  5. ATR 동력에 따라 포지션을 조정하는 것과 같은 자금 관리 전략을 최적화하십시오.

요약하다

이 전략은 쌍MA 교차 판단 경향을 사용하여 거래 신호를 생성하고, 스톱로스 리미팅 리스크를 설정할 수 있다. 거래 논리는 간단하고 명확하지만, 매개 변수 선택의 어려움이 있다. 매개 변수 최적화, 지표 필터링, 스톱로스 전략 등으로 개선할 수 있어 전략이 더 안정적이고 신뢰할 수 있다.

전략 소스 코드
/*backtest
start: 2023-08-18 00:00:00
end: 2023-09-17 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
strategy(title = "Noro's Trend MAs Strategy v1.7", shorttitle = "Trend MAs str 1.7", overlay=true, default_qty_type = strategy.percent_of_equity, default_qty_value=100.0, pyramiding=0)

//Settings
needlong = input(true, "long")
needshort = input(true, "short")
needstops = input(false, "stops")
stoppercent = input(5, defval = 5, minval = 1, maxval = 50, title = "Stop, %")
type = input(7, defval = 7, minval = 1, maxval = 7, title = "Type of Slow MA")
src = input(close, defval = close, title = "Source of Slow MA")
usefastsma = input(true, "Use fast MA Filter")
fastlen = input(5, defval = 5, minval = 1, maxval = 50, title = "fast MA Period")
len = input(20, defval = 20, minval = 2, maxval = 200, title = "slow MA Period")
bars = input(2, defval = 2, minval = 0, maxval = 3, title = "Bars Q")
needbg = input(false, defval = false, title = "Need trend Background?")
needarr = input(false, defval = false, title = "Need entry arrows?")

fastsma = ema(src, fastlen)

//DEMA
dema = 2 * ema(src, len) - ema(ema(close, len), len)

//TEMA
xPrice = close
xEMA1 = ema(src, len)
xEMA2 = ema(xEMA1, len)
xEMA3 = ema(xEMA2, len)
tema = 3 * xEMA1 - 3 * xEMA2 + xEMA3

//KAMA
xvnoise = abs(src - src[1])
nfastend = 0.20
nslowend = 0.05
nsignal = abs(src - src[len])
nnoise = sum(xvnoise, len)
nefratio = iff(nnoise != 0, nsignal / nnoise, 0)
nsmooth = pow(nefratio * (nfastend - nslowend) + nslowend, 2) 
kama = nz(kama[1]) + nsmooth * (src - nz(kama[1]))

//PriceChannel
lasthigh = highest(src, len)
lastlow = lowest(src, len)
center = (lasthigh + lastlow) / 2

//Trend
ma = type == 1 ? sma(src, len) : type == 2 ? ema(src, len) : type == 3 ? vwma(src, len) : type == 4 ? dema : type == 5 ? tema : type == 6 ? kama : type == 7 ? center : 0
trend = low > ma and low[1] > ma[1] and low[2] > ma[2] ? 1 : high < ma and high[1] < ma[1] ? -1 : trend[1]

//Bars
bar = close > open ? 1 : close < open ? -1 : 0
redbars = bars == 0 ? 1 : bars == 1 and bar == -1 ? 1 : bars == 2 and bar == -1 and bar[1] == -1 ? 1 : bars == 3 and bar == -1 and bar[1] == -1 and bar[2] == -1 ? 1 : 0
greenbars = bars == 0 ? 1 : bars == 1 and bar == 1 ? 1 : bars == 2 and bar == 1 and bar[1] == 1 ? 1 : bars == 3 and bar == 1 and bar[1] == 1 and bar[2] == 1 ? 1 : 0

//Signals
min = min(open, close)
max = max(open, close)
up = trend == 1 and (low < fastsma or usefastsma == false) and redbars == 1 ? 1 : 0
dn = trend == -1 and (high > fastsma or usefastsma == false) and greenbars == 1 ? 1 : 0

//Lines
colorfastsma = usefastsma == true ? red : na
plot(fastsma, color = colorfastsma, title = "Fast MA")
plot(ma, color = blue, linewidth = 3, transp = 0, title = "Slow MA")

//Arrows
plotarrow(up == 1 and needarr == true ? 1 : 0, colorup = black, colordown = black, transp = 0)
plotarrow(dn == 1 and needarr == true ? -1 : 0, colorup = black, colordown = black, transp = 0)

//Background
col = needbg == false ? na : trend == 1 ? lime : red
bgcolor(col, transp = 90)

//Alerts
alertcondition(up == 1, title='buy', message='Uptrend')
alertcondition(dn == 1, title='sell', message='Downtrend')

//Trading
stoplong = up == 1 and needstops == true ? close - (close / 100 * stoppercent) : stoplong[1]
stopshort = dn == 1 and needstops == true ? close + (close / 100 * stoppercent) : stopshort[1]

longCondition = up == 1
if (longCondition)
    strategy.entry("Long", strategy.long, needlong == false ? 0 : na)
    strategy.exit("Stop Long", "Long", stop = stoplong)

shortCondition = dn == 1
if (shortCondition)
    strategy.entry("Short", strategy.short, needshort == false ? 0 : na)
    strategy.exit("Stop Short", "Short", stop = stopshort)