이중 이동평균 트렌드 전략

저자:차오장, 날짜: 2023-09-18 21:57:00
태그:

전반적인 설명

이 전략은 트렌드 방향을 파악하고 빠른 MA가 느린 MA를 넘을 때 신호를 생성하기 위해 빠르고 느린 이동 평균을 사용하여 이중 MA 시스템을 만듭니다.

원칙

이 전략은 더 짧은 빠른 MA와 더 긴 느린 MA를 사용합니다.

느린 MA는 주요 트렌드 방향을 정의합니다. MA 이상의 가격은 상승 추세이고, 아래의 가격은 하락 추세입니다.

상승 트렌드에서는 빠른 MA가 느린 MA를 넘을 때 긴 신호가 생성됩니다. 하락 트렌드에서는 빠른 MA가 느린 MA를 넘을 때 짧은 신호가 생성됩니다.

신호 후, 후속 정지 선택적으로 활성화 될 수 있습니다.

장점

  1. 빠르고 느린 MA 조합은 트렌드를 효과적으로 식별합니다.

  2. 빠른 MA는 민감한 거래 신호를 생성합니다.

  3. 느린 MA 필터는 허위 탈출을 방지하는 소음을 차단합니다.

  4. EMA, DEMA와 같은 다양한 MA 유형을 사용할 수 있습니다.

  5. 트래일링 스톱 손실이 활성화될 수 있습니다.

위험 및 완화

  1. MA 지연은 신호를 지연시킬 수 있습니다. 더 민감한 매개 변수를 테스트할 수 있습니다.

  2. 스톱 손실이 너무 좁아서 조기 출구로 이어질 수 있습니다.

  3. 부피는 무시되고 가격 조작의 위험이 있습니다. 부피 확인을 추가할 수 있습니다.

  4. 신호가 틀릴 확률이 높습니다

  5. 매개 변수 최적화 어려운 단계적 최적화 또는 GA 최적의 매개 변수를 찾을 수 있습니다.

더 나은 기회

  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)

더 많은