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

저자:차오장, 날짜: 2024-02-19 15:41:29
태그:

img

전반적인 설명

멀티 타임프레임 이동 평균 크로스오버 전략 (Multi Timeframe Moving Average Crossover Strategy) 은 트렌드 방향을 결정하기 위해 서로 다른 시간 프레임 사이의 이동 평균 크로스오버 신호를 활용한 알고리즘 거래 전략이다. 이 전략은 트렌드, 모멘텀 및 변동성 지표를 결합하여 더 신뢰할 수있는 거래 신호를 생성합니다.

전략 논리

이 전략은 CCI 지표를 다른 기간에 걸쳐 계산하여 시장 트렌드 방향을 결정하고 MACD 신호와 결합하여 황금 십자가와 죽음의 십자가를 찾아내며 마지막으로 ATR 지표를 사용하여 낮은 가격으로 구매하고 높은 가격으로 판매하기 위해 스톱 로스/프로프트 레벨을 설정합니다.

특히, 먼저 20기 CCI를 계산하여 상승세 또는 하락세를 판단합니다. 그 다음 MACD 라인이 교차하는지 확인하여 거래 신호를 식별합니다. 다음으로, ATR은 수익을 잠금하기 위해 트레일링 스톱을 생성하는 데 사용됩니다. 마지막으로 모든 신호가 통합되어 입출 신호를 생성합니다.

장점

  1. 여러 표시기 조합은 신호 정확성을 향상시킵니다.

    CCI, MACD 및 ATR의 조합은 추세, 동력 및 변동성을 공동으로 판단함으로써 거래 신호의 신뢰성을 향상시킵니다.

  2. 다중 시간 프레임 분석 시장 리듬을 포착

    더 긴 기간 CCI는 전반적인 추세를 파악하고, 더 높은 빈도의 MACD는 지역 전환점을 파악하여 전략이 큰 시장 변동을 활용 할 수 있습니다.

  3. ATR 후속 정지 컨트롤은 효과적으로 위험

    ATR에 기반한 스톱 로스는 시장의 변동성에 적응할 수 있고, 후속 기능은 시장이 유리한 방향으로 움직일 때 수익을 더 높일 수 있습니다.

위험성

  1. 제한된 최적화 공간

    대부분의 매개 변수는 좁은 정밀 조정 공간을 가지고 있으며 성능 병목에 쉽게 도달합니다.

  2. 컴퓨터 부하 증가

    여러 지표가 함께 실행되면 컴퓨팅 부하가 증가하여 고주파 거래의 지연을 유발할 수 있습니다.

  3. 빈번한 신호, 제한된 위험 통제

    신호는 빈번할 수 있지만 위험 통제는 주로 극단적인 움직임에 대한 제한이있는 ATR 후속 정지에 의존합니다.

개선

  1. 더 효율적인 매개 변수 조정을 위해 기계 학습을 적용

    베이지안 최적화, 유전 알고리즘 등이 더 지능적이고 효율적인 매개 변수 조정을 가능하게 할 수 있습니다.

  2. 적응력을 높이기 위해 기능적 지표를 추가합니다.

    변동성, 부피, 감정과 같은 다른 지표를 포함하면 전략이 더 견고하고 유연해질 수 있습니다.

  3. 더 나은 안정성을 위한 위험 관리 강화

    더 과학적인 스톱 로스 규칙이 설계될 수 있고, 위치 사이징과 같은 추가 모듈은 극단적인 사건으로부터 보호하는데 도움이 될 수 있습니다.

결론

멀티 타임프레임 이동 평균 크로스오버 전략은 CCI, MACD 및 ATR의 힘을 활용하여 신뢰할 수있는 트렌드 캡처 및 효율적인 위험 통제를 달성합니다. 정확한 신호를 생성하고 시장 리듬을 파악하고 위험을 관리하기 위해 트렌드, 모멘텀 및 변동성을 고려합니다. 매개 변수 조정, 컴퓨팅 로드 및 위험 관리와 같은 일부 측면이 더 향상 될 수 있지만, 그것은 여전히 탄탄한 알고리즘 거래 시스템입니다. 기계 학습, 더 많은 지표 및 더 나은 위험 관리를 사용하는 일부 향상으로 성능은 새로운 수준에 도달 할 수 있습니다.


/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy('smplondonclinic Strategy', shorttitle='SMPLC Strategy', overlay=true, pyramiding = 0, process_orders_on_close = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)

direction   = input.string(title='Entry Direction', defval='Long', options=['Long', 'Short', 'Both'],group = "Strategy Entry Direction")

TPPerc = input.float(title='Take Profit (%)', minval=0.0, step=0.1, defval=0.5, group='Strategy TP & SL')
SLPerc = input.float(title='Stop Loss (%)', minval=0.0, step=0.1, defval=0.5, group='Strategy TP & SL')

period = input(20, 'CCI period',group = "TREND MAGIC")
coeff = input(1, 'ATR Multiplier',group = "TREND MAGIC")
AP = input(5, 'ATR Period',group = "TREND MAGIC")
ATR = ta.sma(ta.tr, AP)
srctm = close
upT = low - ATR * coeff
downT = high + ATR * coeff
MagicTrend = 0.0
MagicTrend := ta.cci(srctm, period) >= 0 ? upT < nz(MagicTrend[1]) ? nz(MagicTrend[1]) : upT : downT > nz(MagicTrend[1]) ? nz(MagicTrend[1]) : downT
color1 = ta.cci(srctm, period) >= 0 ? #0022FC : #FC0400
plot(MagicTrend, color=color1, linewidth=3)
tmb = ta.cci(srctm, period) >= 0 and close>MagicTrend
tms = ta.cci(srctm, period) <= 0 and close<MagicTrend

//MACD

res           = input.timeframe("",  "Indicator TimeFrame", group = "MACD")
fast_length   = input.int(title="Fast Length", defval=12, group = "MACD")
slow_length   = input.int(title="Slow Length", defval=26, group = "MACD")
src           = input.source(title="Source", defval=close, group = "MACD")
signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 999, defval = 9, group = "MACD")
sma_source    = input.string(title="Oscillator MA Type", defval="EMA", options=["SMA", "EMA"], group = "MACD")
sma_signal    = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"], group = "MACD")

fast_ma = request.security(syminfo.tickerid, res, sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length))
slow_ma = request.security(syminfo.tickerid, res, sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length))
macd = fast_ma - slow_ma
signal = request.security(syminfo.tickerid, res, sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length))
hist = macd - signal

trend_up   = macd > signal
trend_dn   = macd < signal
cross_UP   = signal[1] >= macd[1] and signal < macd
cross_DN   = signal[1] <= macd[1] and signal > macd
cross_UP_A = (signal[1] >= macd[1] and signal < macd) and macd > 0
cross_DN_B = (signal[1] <= macd[1] and signal > macd) and macd < 0


//UT Bot

srcut = close
showut = input.bool(false, 'Show UT Bot Labels', group = "UT BOT")
keyvalue = input.float(2, title='Key Vaule. \'This changes the sensitivity\'', step=.5, group = "UT BOT")
atrperiod = input(7, title='ATR Period', group = "UT BOT")
xATR = ta.atr(atrperiod)
nLoss = keyvalue * xATR

xATRTrailingStop = 0.0
iff_1 = srcut > nz(xATRTrailingStop[1], 0) ? srcut - nLoss : srcut + nLoss
iff_2 = srcut < nz(xATRTrailingStop[1], 0) and srcut[1] < nz(xATRTrailingStop[1], 0) ? math.min(nz(xATRTrailingStop[1]), srcut + nLoss) : iff_1
xATRTrailingStop := srcut > nz(xATRTrailingStop[1], 0) and srcut[1] > nz(xATRTrailingStop[1], 0) ? math.max(nz(xATRTrailingStop[1]), srcut - nLoss) : iff_2

pos = 0
iff_3 = srcut[1] > nz(xATRTrailingStop[1], 0) and srcut < nz(xATRTrailingStop[1], 0) ? -1 : nz(pos[1], 0)
pos := srcut[1] < nz(xATRTrailingStop[1], 0) and srcut > nz(xATRTrailingStop[1], 0) ? 1 : iff_3

xcolor = pos == -1 ? color.red : pos == 1 ? color.green : color.blue

//plot(xATR, color=xcolor, title='Trailing Stop')
buy = ta.crossover(srcut, xATRTrailingStop)
sell = ta.crossunder(srcut, xATRTrailingStop)
barcolor = srcut > xATRTrailingStop

plotshape(showut ? buy:na, title='Buy', text='Buy', style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), textcolor=color.new(color.white, 0), size=size.tiny)
plotshape(showut ? sell:na, title='Sell', text='Sell', style=shape.labeldown, color=color.new(color.red, 0), textcolor=color.new(color.white, 0), size=size.tiny)

//barcolor(barcolor ? color.green : color.red)

goLong = buy and tmb and cross_UP
goShort = sell and tms and cross_DN

plotshape(goLong, location=location.bottom, style=shape.triangleup, color=color.lime, size=size.small)
plotshape(goShort, location=location.top, style=shape.triangledown, color=color.red, size=size.small)

percentAsPoints(pcnt) =>
    strategy.position_size != 0 ? math.round(pcnt / 100.0 * strategy.position_avg_price / syminfo.mintick) : float(na)

percentAsPrice(pcnt) =>
    strategy.position_size != 0 ? (pcnt / 100.0 + 1.0) * strategy.position_avg_price : float(na)

current_position_size = math.abs(strategy.position_size)
initial_position_size = math.abs(ta.valuewhen(strategy.position_size[1] == 0.0, strategy.position_size, 0))

TP = strategy.position_avg_price + percentAsPoints(TPPerc) * syminfo.mintick * strategy.position_size / math.abs(strategy.position_size)
SL = strategy.position_avg_price - percentAsPoints(SLPerc) * syminfo.mintick * strategy.position_size / math.abs(strategy.position_size)

var long = false
var short = false

if direction == 'Long' 
    long := goLong
    short := false

if direction == 'Short'
    short := goShort
    long := false

if direction == 'Both' 
    long := goLong
    short := goShort

if long and strategy.opentrades == 0
    strategy.entry(id='Long', direction=strategy.long)

if short and strategy.opentrades == 0
    strategy.entry(id='Short', direction=strategy.short)

if strategy.position_size > 0

    strategy.exit('TPSL', from_entry='Long', qty=initial_position_size, limit=TP, stop=SL)

if strategy.position_size < 0

    strategy.exit('TPSL2', from_entry='Short', qty=initial_position_size, limit=TP, stop=SL)



더 많은