멀티 타임프레임 이동 평균 크로스오버 최적화 전략

저자:차오장, 날짜: 2024-01-05 12:05:42
태그:

img

전반적인 설명

이 전략은 유명한 CM_Ultimate_MA_MTF 지표에 기반하여 거래 전략으로 다시 작성되었습니다. 여러 시간 프레임에 걸쳐 이동 평균을 그래프화하고 다른 기간의 MA 사이의 크로스오버 신호를 생성 할 수 있습니다. 이 전략에는 또한 후속 스톱 손실 메커니즘이 포함되어 있습니다.

전략 논리

  1. 사용자 구성에 따라 주요 차트 시간 프레임과 더 높은 시간 프레임에 다른 유형의 MA 라인을 그래프하십시오.
  2. 더 빠른 MA가 더 느린 MA를 넘을 때 길게; 더 빠른 MA가 더 느린 MA를 넘을 때 짧게.
  3. 후속 스톱 손실을 추가 제어 위험에 추가합니다.

이점 분석

  1. 시간 프레임에 걸쳐 MA 크로스오버는 신호 품질을 향상시키고 잘못된 신호를 줄일 수 있습니다.
  2. 다른 MA 유형을 조합하면 더 나은 안정성을 위해 개별 지표의 강점을 활용합니다.
  3. 트래일링 스톱 로즈는 적시에 손실을 제한하는 데 도움이 됩니다.

위험 분석

  1. MA의 지연 성격은 단기 기회를 놓칠 수 있습니다.
  2. MA 기간의 최적화가 좋지 않으면 과도한 잘못된 신호를 생성할 수 있습니다.
  3. 잘못된 스톱 로스 배치로 인해 불필요한 탈퇴가 발생할 수 있습니다.

최적화 방향

  1. 최적의 설정을 찾기 위해 MA 매개 변수 조합을 테스트합니다.
  2. 신호 필터링 및 품질 향상을 위한 다른 지표들을 추가합니다.
  3. 시장 프로필에 맞게 스톱 로스 전략을 최적화합니다.

결론

이 전략은 신호 품질과 위험 통제를 향상시키기 위해 멀티 타임프레임 분석과 이동 평균의 트래일링 스톱 접근 방식을 통합합니다. 매개 변수 조정 및 보완적 지표 추가로 추가 개선이 가능합니다.


/*backtest
start: 2022-12-29 00:00:00
end: 2024-01-04 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2

strategy(title = "Ultimate Moving Average Strategy", shorttitle = "UMA Strategy", overlay = true)

//Created by user ChrisMoody 4-24-2014
//Converted to strategy by Virtual_Machinist 7-11-2018
//Plots The Majority of Moving Averages
//Defaults to Current Chart Time Frame --- But Can Be Changed to Higher Or Lower Time Frames
//2nd MA Capability with Show Crosses Feature

//inputs
src = close
useCurrentRes = input(true, title="Use Current Chart Resolution?")
resCustom = input(title="Use Different Timeframe? Uncheck Box Above",  defval="D")
len = input(20, title="Moving Average Length - LookBack Period")
atype = input(1,minval=1,maxval=7,title="1=SMA, 2=EMA, 3=WMA, 4=HullMA, 5=VWMA, 6=RMA, 7=TEMA")
cc = input(true,title="Change Color Based On Direction?")
smoothe = input(2, minval=1, maxval=10, title="Color Smoothing - 1 = No Smoothing")
doma2 = input(false, title="Optional 2nd Moving Average")
len2 = input(50, title="Moving Average Length - Optional 2nd MA")
atype2 = input(1,minval=1,maxval=7,title="1=SMA, 2=EMA, 3=WMA, 4=HullMA, 5=VWMA, 6=RMA, 7=TEMA")
cc2 = input(true,title="Change Color Based On Direction 2nd MA?")
warn = input(false, title="***You Can Turn On The Show Dots Parameter Below Without Plotting 2nd MA to See Crosses***")
warn2 = input(false, title="***If Using Cross Feature W/O Plotting 2ndMA - Make Sure 2ndMA Parameters are Set Correctly***")
sd = input(false, title="Show Dots on Cross of Both MA's")

useStop     = input(defval = true, title = "Use Trailing Stop?")
slPoints    = input(defval = 200, title = "Stop Loss Trail Points", minval = 1)
slOffset    = input(defval = 400, title = "Stop Loss Trail Offset", minval = 1)

res = useCurrentRes ? timeframe.period : resCustom
//hull ma definition
hullma = wma(2*wma(src, len/2)-wma(src, len), round(sqrt(len)))
//TEMA definition
ema1 = ema(src, len)
ema2 = ema(ema1, len)
ema3 = ema(ema2, len)
tema = 3 * (ema1 - ema2) + ema3

avg = atype == 1 ? sma(src,len) : atype == 2 ? ema(src,len) : atype == 3 ? wma(src,len) : atype == 4 ? hullma : atype == 5 ? vwma(src, len) : atype == 6 ? rma(src,len) : tema
//2nd Ma - hull ma definition
hullma2 = wma(2*wma(src, len2/2)-wma(src, len2), round(sqrt(len2)))
//2nd MA TEMA definition
sema1 = ema(src, len2)
sema2 = ema(sema1, len2)
sema3 = ema(sema2, len2)
stema = 3 * (sema1 - sema2) + sema3

avg2 = atype2 == 1 ? sma(src,len2) : atype2 == 2 ? ema(src,len2) : atype2 == 3 ? wma(src,len2) : atype2 == 4 ? hullma2 : atype2 == 5 ? vwma(src, len2) : atype2 == 6 ? rma(src,len2) : tema

out = avg 
out_two = avg2

out1 = request.security(syminfo.tickerid, res, out)
out2 = request.security(syminfo.tickerid, res, out_two)

ma_up = out1 >= out1[smoothe]
ma_down = out1 < out1[smoothe]

col = cc ? ma_up ? lime : ma_down ? red : aqua : aqua
col2 = cc2 ? ma_up ? lime : ma_down ? red : aqua : aqua

circleYPosition = out2

plot(out1, title="Multi-Timeframe Moving Avg", style=line, linewidth=4, color = col)
plot(doma2 and out2 ? out2 : na, title="2nd Multi-TimeFrame Moving Average", style=circles, linewidth=4, color=col2)
plot(sd and cross(out1, out2) ? circleYPosition : na,style=cross, linewidth=5, color=yellow)

// Strategy conditions

longCond    = ma_up
shortCond   = ma_down
// entries and base exit
strategy.entry("long", strategy.long, when = longCond)
strategy.entry("short", strategy.short, when = shortCond)

if (useStop)
    strategy.exit("XL", from_entry = "long", trail_points = slPoints, trail_offset = slOffset)
    strategy.exit("XS", from_entry = "short", trail_points = slPoints, trail_offset = slOffset)
// not sure needed, but just incase..
strategy.exit("XL", from_entry = "long", when = shortCond)
strategy.exit("XS", from_entry = "short", when = longCond)

더 많은