다중 지표 융합 동적 이동 평균 교차 정량적 전략

SMA EMA WMA VWMA HMA RMA ALMA MA
생성 날짜: 2025-01-06 13:46:47 마지막으로 수정됨: 2025-01-06 13:46:47
복사: 2 클릭수: 443
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

다중 지표 융합 동적 이동 평균 교차 정량적 전략

개요

이 전략은 다중 이동평균선 교차 신호를 기반으로 하는 양적 거래 시스템입니다. 여기에는 단순 이동 평균(SMA), 지수 이동 평균(EMA), 가중 이동 평균(WMA), 거래량 가중 이동 평균(VWMA), 헐 이동 평균(LME) 등 7가지 유형의 이동 평균 지표가 결합되어 있습니다. 높은 이동 평균(HMA), 대략적인 이동 평균(RMA), 아놀드-레귀즈 이동 평균(ALMA). 이 전략은 2라인 또는 3라인 크로스오버 시스템을 지원하며, 시장 상황에 따라 롱 포지션 또는 숏 포지션을 유연하게 선택할 수 있습니다.

전략 원칙

이 전략의 핵심 논리는 다양한 기간의 이동 평균선 간의 교차 관계를 관찰하여 시장 추세를 판단하는 것입니다. 빠르게 움직이는 평균이 느리게 움직이는 평균을 위쪽으로 교차할 때, 롱 신호가 생성되고, 그렇지 않을 때는 숏 신호가 생성됩니다. 이 시스템은 두 가지 진입 방법을 제공합니다. 하나는 이동 평균선의 직접 교차를 기반으로 하며, 다른 하나는 이동 평균선에 대한 종가의 포지션 관계를 기반으로 합니다. 3선 시스템은 중기 이동 평균을 도입하여 신호의 신뢰성과 안정성을 높입니다.

전략적 이점

  1. 강력한 적응성: 7개의 다양한 이동 평균을 통합함으로써 이 전략은 다양한 시장 환경과 거래 상품에 적응할 수 있습니다.
  2. 안정적인 신호: 거짓 신호를 방지하기 위해 여러 확인 메커니즘을 사용합니다.
  3. 유연한 매개변수: 사용자 정의 주기 설정 지원, 최적화 및 백테스트 용이
  4. 위험 관리 가능: 양방향 거래 기회 포착을 돕기 위한 공매도 메커니즘 제공
  5. 명확한 시각화: 이 전략은 추세 영역 채우기와 같은 시각적 보조 도구를 포함하여 직관적인 그래픽 인터페이스를 제공합니다.

전략적 위험

  1. 지연: 이동 평균선은 본질적으로 지표보다 뒤떨어져 있기 때문에 변동성이 큰 시장에서는 최적의 진입 시점을 놓칠 수 있습니다.
  2. 변동성이 있는 시장에 적합하지 않음: 횡보 및 변동성이 있는 시장에서는 빈번하게 잘못된 신호가 생성될 수 있습니다.
  3. 매개변수 종속성: 다양한 매개변수 조합의 성능은 크게 다르며 지속적으로 최적화해야 합니다.
  4. 체계적 위험: 시장 사건이 발생할 때 손실을 제때 막는 것이 불가능할 수 있습니다.

전략 최적화 방향

  1. 변동성 지표 소개: ATR 등의 변동성 지표를 결합하여 포지션 크기를 동적으로 조정하는 것이 좋습니다.
  2. 시장 환경 필터 추가: 변동성이 큰 시장에서 거래 신호를 필터링하기 위해 추세 강도 지표를 추가할 수 있습니다.
  3. 손절매 메커니즘 최적화: 위험 관리 역량을 향상시키기 위해 트레일링 손절매 기능을 추가하는 것이 좋습니다.
  4. 볼륨 분석 추가: 추세의 유효성을 확인하기 위해 볼륨 변화를 결합하는 것이 좋습니다.

요약하다

이 전략은 여러 이동 평균 지표와 유연한 매개변수 설정을 통합하여 트레이더에게 신뢰할 수 있는 정량적 거래 프레임워크를 제공하는 포괄적인 추세 추적 시스템입니다. 어느 정도 지연이 있기는 하지만, 이 전략은 합리적인 매개변수 최적화와 위험 관리 조치를 통해 여전히 좋은 실질적 가치를 가지고 있습니다. 트레이더는 실제 거래에서 특정 시장 특성을 기반으로 타겟팅된 최적화를 수행하는 것이 좋습니다.

전략 소스 코드
/*backtest
start: 2019-12-23 08:00:00
end: 2025-01-04 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Cruce de Medias Total", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100,max_bars_back=1000)

// Parámetros de entrada
periodo_rapida = input.int(50, title="Periodos para media rápida", minval=1)
periodo_lenta = input.int(200, title="Periodos para media lenta", minval=1)

// Selección del tipo de media móvil
tipo_de_media = input.string(title="Elige el tipo de media móvil", defval="Simple sma", options=["Simple sma", "Exponencial ema", "Ponderada wma", "Volumen ponderada vwma", "Hull hma", "Media suavizada rma", "Media de Arnaud Legoux alma"])

// Posibilidad de estrategia con cruce de tres medias móviles
tres_medias = input.bool(false, title="Estrategia con cruce de 3 medias móviles")
periodo_media = input.int(100, title="Periodos para media media", minval=1)

// Opción de operar en corto
permitir_corto = input.bool(false, title="Permitir operaciones en corto")

// Opción de cuando comprar
cuando_comprar = input.string(title="Cuando comprar", defval="Cruce de medias", options=["Vela anterior cierra por encima de las medias", "Cruce de medias"])
// Opción de cuando vender
cuando_vender = input.string(title="Cuando vender", defval="Cruce de medias", options=["Vela anterior cierra por debajo de las medias", "Cruce de medias"])

float media_mov_rapida = na
float media_mov_media = na
float media_mov_lenta = na

// Definición de las medias móviles
if tipo_de_media == "Simple sma"
    media_mov_rapida := ta.sma(close, periodo_rapida)
    media_mov_media := ta.sma(close, periodo_media)
    media_mov_lenta := ta.sma(close, periodo_lenta)
else if tipo_de_media == "Exponencial ema"
    media_mov_rapida := ta.ema(close, periodo_rapida)
    media_mov_media := ta.ema(close, periodo_media)
    media_mov_lenta := ta.ema(close, periodo_lenta)
else if tipo_de_media == "Ponderada wma"
    media_mov_rapida := ta.wma(close, periodo_rapida)
    media_mov_media := ta.wma(close, periodo_media)
    media_mov_lenta := ta.wma(close, periodo_lenta)
else if tipo_de_media == "Volumen ponderada vwma"
    media_mov_rapida := ta.vwma(close, periodo_rapida)
    media_mov_media := ta.vwma(close, periodo_media)
    media_mov_lenta := ta.vwma(close, periodo_lenta)
else if tipo_de_media == "Hull hma"
    media_mov_rapida := ta.hma(close, periodo_rapida)
    media_mov_media := ta.hma(close, periodo_media)
    media_mov_lenta := ta.hma(close, periodo_lenta)
else if tipo_de_media == "Media suavizada rma"
    media_mov_rapida := ta.rma(close, periodo_rapida)
    media_mov_media := ta.rma(close, periodo_media)
    media_mov_lenta := ta.rma(close, periodo_lenta)
else if tipo_de_media == "Media de Arnaud Legoux alma"
    offset = input.int(0, title="Desfase para ALMA", minval=-100, maxval=100)
    sigma = input.float(6, title="Sigma para ALMA", minval=0.1, maxval=10)
    media_mov_rapida := ta.alma(close, periodo_rapida, offset, sigma)
    media_mov_media := ta.alma(close, periodo_media, offset, sigma)
    media_mov_lenta := ta.alma(close, periodo_lenta, offset, sigma)

// Graficar las medias móviles en el gráfico
plot_rapida = plot(media_mov_rapida, color=color.green, linewidth=2, title="Media Móvil Rápida")
plot_media = plot(tres_medias ? media_mov_media : na, color=color.blue, linewidth=2, title="Media Móvil Media")
plot_lenta = plot(media_mov_lenta, color=color.red, linewidth=2, title="Media Móvil Lenta")

// Rellenar el área entre las medias móviles con color condicionado
fill(plot_rapida, plot_lenta, media_mov_rapida > media_mov_lenta ? color.new(color.green, 90) : color.new(color.red, 90), title="Relleno entre Medias")

// Lógica de la estrategia para cruce de medias
comprado = strategy.position_size > 0  // Verifica si ya hay una posición abierta
vendido = strategy.position_size < 0 

if not comprado  // Solo compra si no hay una posición abierta
    if tres_medias and cuando_comprar == "Cruce de medias"
        if media_mov_rapida > media_mov_media and media_mov_media > media_mov_lenta
            strategy.entry("Largo", strategy.long)
            label.new(bar_index, low, "Largo", style=label.style_label_up, color=color.green, textcolor=color.white)
    else if not tres_medias and cuando_comprar == "Cruce de medias"
        if ta.crossover(media_mov_rapida, media_mov_lenta)
            strategy.entry("Largo", strategy.long)
            label.new(bar_index, low, "Largo", style=label.style_label_up, color=color.green, textcolor=color.white)
    else if tres_medias and cuando_comprar == "Vela anterior cierra por encima de las medias"
        if close[1] > media_mov_rapida and close[1] > media_mov_media and close[1] > media_mov_lenta
            strategy.entry("Largo", strategy.long)
            label.new(bar_index, low, "Largo", style=label.style_label_up, color=color.green, textcolor=color.white)
    else if not tres_medias and cuando_comprar == "Vela anterior cierra por encima de las medias"
        if close[1] > media_mov_rapida and close[1] > media_mov_lenta
            strategy.entry("Largo", strategy.long)
            label.new(bar_index, low, "Largo", style=label.style_label_up, color=color.green, textcolor=color.white)

// Condición de cierre de la posición
if comprado
    if tres_medias and cuando_vender == "Cruce de medias"
        if media_mov_rapida < media_mov_media and media_mov_media < media_mov_lenta
            strategy.close("Largo")
            label.new(bar_index, high, "Cierre Largo", style=label.style_label_down, color=color.red, textcolor=color.white)
    else if not tres_medias and cuando_vender == "Cruce de medias"
        if ta.crossunder(media_mov_rapida, media_mov_lenta)
            strategy.close("Largo")
            label.new(bar_index, high, "Cierre Largo", style=label.style_label_down, color=color.red, textcolor=color.white)
    else if tres_medias and cuando_vender == "Vela anterior cierra por debajo de las medias"
        if close[1] < media_mov_rapida and close[1] < media_mov_media and close[1] < media_mov_lenta
            strategy.close("Largo")
            label.new(bar_index, high, "Cierre Largo", style=label.style_label_down, color=color.red, textcolor=color.white)
    else if not tres_medias and cuando_vender == "Vela anterior cierra por debajo de las medias"
        if close[1] < media_mov_rapida and close[1] < media_mov_lenta
            strategy.close("Largo")
            label.new(bar_index, high, "Cierre Largo", style=label.style_label_down, color=color.red, textcolor=color.white)

// Condición de entrar en corto
if not vendido and permitir_corto
    if tres_medias
        if media_mov_rapida < media_mov_media and media_mov_media < media_mov_lenta
            strategy.entry("Short", strategy.short)
            label.new(bar_index, low, "Short", style=label.style_label_up, color=color.blue, textcolor=color.white)
    else
        if ta.crossunder(media_mov_rapida, media_mov_lenta)
            strategy.entry("Short", strategy.short)
            label.new(bar_index, low, "Short", style=label.style_label_up, color=color.blue, textcolor=color.white)

// Condición de cierre de posición corta
if vendido
    if tres_medias
        if media_mov_rapida > media_mov_media and media_mov_media > media_mov_lenta
            strategy.close("Short")
            label.new(bar_index, high, "Cierre Short", style=label.style_label_down, color=color.purple, textcolor=color.white)
    else
        if ta.crossover(media_mov_rapida, media_mov_lenta)
            strategy.close("Short")
            label.new(bar_index, high, "Cierre Short", style=label.style_label_down, color=color.purple, textcolor=color.white)