이중 이동 평균 크로스오버 트렌드 전략

저자:차오장, 날짜: 2023-11-22 17:29:04
태그:

img

전반적인 설명

이중 이동 평균 크로스오버 트렌드 전략 (Dual Moving Average Crossover Trend Strategy) 은 트렌드를 따르는 전략으로 빠르고 느린 이동 평균 라인이 교차할 때 구매 및 판매 신호를 생성합니다. 트렌드 방향을 결정하기 위해 MACD 및 RSI와 같은 여러 지표를 통합하고 강력한 트렌드 추적 기능을 가지고 있습니다.

전략 논리

이 전략은 주로 다음의 지표를 이용해서 판단합니다.

  1. 빠르고 느린 이동 평균 라인: 구매 신호를 위한 황금 십자, 판매 신호를 위한 죽음의 십자

  2. MACD: 시그널 라인 위에 있는 MACD 라인과 상승하는 MACD가 상승 신호의 최하위입니다.

  3. RSI: 상승률은 50 이상, 하락률은 50 이하입니다.

  4. AW (Awesome Oscillator) (AO): AO가 0선을 넘어서 구매하고 판매를 위해 아래를 넘는다.

  5. 3개의 일일 이동 평균: 더 짧은 기간의 일일 MA가 구매 신호로 더 긴 기간의 일일 MA를 넘는다.

이 전략은 여러 시간 프레임과 지표를 결합하여 구매 및 판매 논리를 생성합니다. 여러 지표가 동시에 상승 신호를 표시 할 때 구매 주문을 생성하고 추세를 추적하기 위해 하락 신호가 나타날 때 판매 주문을 생성합니다.

이점 분석

이 전략은 다음과 같은 장점을 가지고 있습니다.

  1. 여러 지표 조합은 잘못된 신호를 줄이고 정확도를 향상시킵니다.

  2. 여러 시간 프레임을 통합하면 더 큰 트렌드 방향을 식별합니다.

  3. 파라미터 튜닝은 좋은 수익성을 제공합니다.

  4. 리스크를 통제하고 손실을 제한하기 위해 이동 스톱 로스를 채택합니다.

  5. 수동 개입 없이 트렌드 추적을 자동화하여 비용을 절감합니다.

위험 분석

또한 몇 가지 위험이 있습니다.

  1. 범위를 제한하는 시장에서 더 많은 윙사가 발생할 수 있습니다. 유효하지 않은 신호를 줄이기 위해 매개 변수를 최적화하십시오.

  2. 블랙 스완 이벤트는 급격한 인력 감축을 일으킬 수 있습니다.

  3. 복잡한 구매/판매 논리는 최적의 매개 변수를 찾기 위해 큰 역사적 데이터에 의존합니다.

  4. 부적절한 스톱 로스 설정으로 인해 조기 종료가 됩니다.

최적화 방향

이 전략은 다음과 같은 측면에서 개선될 수 있습니다.

  1. 변동성 지수, OBV 등과 같은 더 안정적이고 정확한 신호를 위해 더 많은 지표 조합을 테스트하십시오.

  2. 기계 학습과 유전 알고리즘으로 지표 매개 변수를 최적화하여 과잉 거래를 줄이세요.

  3. 모델 앙상블 기술을 도입하여 여러 독립적인 전략 모델의 신호를 통합하여 안정성을 향상시킵니다.

  4. 더 높은 시간 프레임에 거래를 입력 하 고, 더 낮은 시간 프레임에 출입 하 고, 보유 마감 위험을 줄입니다.

  5. 거래별 스톱 로스 비율, 최대 마감 등에 대한 엄격한 제한과 함께 정량적 리스크 제어 모듈을 구축합니다.

요약

이중 이동 평균 크로스오버 트렌드 전략은 자동 트렌드 추적을 위해 트렌드 방향을 판단하기 위해 MACD, RSI와 함께 빠르고 느린 MA 크로스를 거래 신호로 사용합니다. 더 많은 지표, 매개 변수 조정, 모델 집합 등을 통합하여 더 나은 전략 효과를 위해 상당한 최적화 공간이 있습니다.


/*backtest
start: 2023-10-22 00:00:00
end: 2023-11-21 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy('SteffVans', shorttitle='SteffVans strategy', overlay=true, process_orders_on_close = true)

// Input settings
macd_fast_length = input(12)
macd_slow_length = input(26)
macd_signal_length = input(9)

// Calculate MACD values
[macd_line, signal_line, _] = ta.macd(close, macd_fast_length, macd_slow_length, macd_signal_length)
mg = ta.lowest(signal_line, 30) >= -0

// RSI
ma(source, length, type) =>
    switch type
        "SMA" => ta.sma(source, length)
        "Bollinger Bands" => ta.sma(source, length)
        "EMA" => ta.ema(source, length)
        "SMMA (RMA)" => ta.rma(source, length)
        "WMA" => ta.wma(source, length)
        "VWMA" => ta.vwma(source, length)

rsiLengthInput = input.int(14, minval=1)
rsiSourceInput = input.source(close, "Source", group="RSI Settings")
maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
maLengthInput = input.int(14, title="MA Length", group="MA Settings")
bbMultInput = input.float(2.0, minval=0.001, maxval=50, title="BB StdDev", group="MA Settings")

up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
RSI = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))


//  AO
AO = ta.sma((high + low) / 2, 5) - ta.sma((high + low) / 2, 34)
crossaosell = AO < AO[1] and AO[1] < AO[2] and AO[2] > AO[3]  and ta.lowest(low,3)

// Uptrend sma
len1 = input.int(5, minval=1)
len2 = input.int(10, minval=1)
len3 = input.int(20, minval=1)
src = input(close)

out1 = ta.sma(src, len1)
out2 = ta.sma(src, len2)
out3 = ta.sma(src, len3)



// Timeframe 
macdl60 = request.security(syminfo.tickerid, "60", signal_line,lookahead = barmerge.lookahead_on)
ao = request.security(syminfo.tickerid, "60", AO,lookahead = barmerge.lookahead_on)
rsi = request.security(syminfo.tickerid, "60", RSI,lookahead = barmerge.lookahead_on)
good = request.security(syminfo.tickerid, "60", mg,lookahead = barmerge.lookahead_on)
bad = request.security(syminfo.tickerid, "60", crossaosell,lookahead = barmerge.lookahead_on)

ma1 = request.security(syminfo.tickerid, "D", out1,lookahead = barmerge.lookahead_on)
ma2 = request.security(syminfo.tickerid, "D", out2, lookahead = barmerge.lookahead_on)
ma3 = request.security(syminfo.tickerid, "D", out3, lookahead = barmerge.lookahead_on)






// Kriteria BUY and SELL
uptrend1 =  request.security(syminfo.tickerid, "D", close,lookahead = barmerge.lookahead_on) > ma1 and ma1 > ma3 and ma2 > ma3
uptrend2 = ta.lowest(ma1,12) > ta.lowest(ma3,12) and ta.lowest(ma2,12) > ta.lowest(ma3,12) 


 

// Triger BUY and SELL 
cross1 = ao > ao[1] and ao[1] < ao[2] and ao > 0 and good and rsi >= 60 and uptrend1
cross2 = ao > 0 and ao[1] < 0 and good and rsi >=50 and uptrend1
cross3 =  ao > 0 and ao[1] < 0 and not good and uptrend2 and uptrend1
cross4 =  ao > ao[1] and ao[1] > ao[2] and ao[2] < ao[3] and ao[3] < ao[4]  and not good and uptrend2 and uptrend1

s1 = ao < ao[1] and ao[1] < ao[2] and ao[2] < ao[3] and ao > 0 and rsi < 50 and request.security(syminfo.tickerid, "D", close,lookahead = barmerge.lookahead_on) < ma1
s2 =  ao < 0 and ao < ao[2] and rsi < 50 and request.security(syminfo.tickerid, "D", close,lookahead = barmerge.lookahead_on) < ma1 

// Variabel Buy dan Sell
buySignal = false
sellSignal = false

// Syarat masuk Buy
buyCondition =  cross1 or cross2 or cross3 or cross4
if buyCondition
    buySignal := true

// Syarat masuk Sell
sellCondition = s1 or s2
if sellCondition
    sellSignal := true

// Reset sinyal jika ada sinyal berulang
if buySignal and sellSignal
    sellSignal := false
if sellSignal and buySignal
    buySignal := false

// Logika perdagangan
if buySignal
    strategy.entry("Buy", strategy.long, comment = "BUY")
if sellSignal
    strategy.close("Buy")


plotshape(cross1,title = "Stefkuy1", style = shape.labelup, location = location.belowbar, color = color.green,text = "1", textcolor = color.white,size = size.small)
plotshape(cross2,title = "Stefkuy2", style = shape.labelup, location = location.belowbar, color = color.green, text = "2", textcolor= color.white, size = size.small)
plotshape(cross3,title = "StefVan1", style = shape.labelup, location = location.belowbar, color = color.rgb(0, 153, 255), text = "3", textcolor= color.white,size = size.small)
plotshape(cross4,title = "StefVan2", style = shape.labelup, location = location.belowbar, color = color.rgb(0, 153, 255), text = "4", textcolor= color.white,size = size.small)


더 많은