2 Detección de la dirección del color de la media móvil

El autor:¿ Qué pasa?, Fecha: 2022-05-20 16:44:13
Las etiquetas:La SMAEl EMALa WMAVWMAEl número de personas afectadasEl DEMATEMA (en inglés)

La opción de llenado se agrega entre los promedios móviles (se desactiva por defecto, se activa en la configuración si lo desea), si los 2 promedios son verdes el llenado será verde, si los 2 promedios son rojos el llenado será rojo, esto confirmaría una tendencia saludable en el caso de que esté utilizando un promedio rápido y un promedio lento, en el caso de que los cambios de dirección promedio rápido se llenarán en el color púrpura, esto puede indicar varias cosas: se está generando una corrección de la tendencia, posible resto del precio, posible inicio de lateralidad, posible cambio de tendencia, cuando el color es púrpura el operador tendrá que analizar el contexto general para poder definir lo que podría estar sucediendo.

Se crearon las siguientes alertas:

  • Cambio de dirección 1-MA
  • Cambio de dirección 2-MA
  • Cruce bajo 2-Ma/1-Ma
  • Cruce bajo 1-Ma/2-Ma
  • Cruce sobre el 2-Ma/1-Ma
  • Transcurrido 1-Ma/2-Ma
  • Se aplicará el método de cálculo de las emisiones.

Prueba posterior

img


//@version=3
study(shorttitle="MA_2X", title="2 Moving Average Color Direction Detection ", overlay=true)

// === INPUTS

ma_1 = input(true, title="1-MA")
ma_type   = input(defval="SMA", title="1-MA Type: ", options=["SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "ZEMA", "TMA", "SSMA"])
ma_len    = input(defval=20, title="1-MA Lenght", minval=1)
ma_src    = input(close, title="1-MA Source")
reaction_ma_1  = input(defval=3, title="1-MA Reaction", minval=1)

ma_2 = input(true, title="2-MA")
ma_type_b   = input(defval="SMA", title="2-MA Type: ", options=["SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "ZEMA", "TMA", "SSMA"])
ma_len_b    = input(defval=8, title="2-MA Lenght", minval=1)
ma_src_b    = input(close, title="2-MA Source")
reaction_ma_2  = input(defval=3, title="2-MA Reaction", minval=1)

filling = input(false, title="FILLING")

// SuperSmoother filter
// © 2013  John F. Ehlers
variant_supersmoother(src,len) =>
    a1 = exp(-1.414*3.14159 / len)
    b1 = 2*a1*cos(1.414*3.14159 / len)
    c2 = b1
    c3 = (-a1)*a1
    c1 = 1 - c2 - c3
    v9 = 0.0
    v9 := c1*(src + nz(src[1])) / 2 + c2*nz(v9[1]) + c3*nz(v9[2])
    v9
    
variant_smoothed(src,len) =>
    v5 = 0.0
    v5 := na(v5[1]) ? sma(src, len) : (v5[1] * (len - 1) + src) / len
    v5

variant_zerolagema(src,len) =>
    ema1 = ema(src, len)
    ema2 = ema(ema1, len)
    v10 = ema1+(ema1-ema2)
    v10
    
variant_doubleema(src,len) =>
    v2 = ema(src, len)
    v6 = 2 * v2 - ema(v2, len)
    v6

variant_tripleema(src,len) =>
    v2 = ema(src, len)
    v7 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len)             
    v7
    
variant(type, src, len) =>
    type=="EMA"     ? ema(src,len) : 
      type=="WMA"   ? wma(src,len): 
      type=="VWMA"  ? vwma(src,len) : 
      type=="SMMA"  ? variant_smoothed(src,len) : 
      type=="DEMA"  ? variant_doubleema(src,len): 
      type=="TEMA"  ? variant_tripleema(src,len): 
      type=="HullMA"? wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len))) :
      type=="SSMA"  ? variant_supersmoother(src,len) : 
      type=="ZEMA"  ? variant_zerolagema(src,len) : 
      type=="TMA"   ? sma(sma(src,len),len) : sma(src,len)


// === Moving Average
ma_series = variant(ma_type,ma_src,ma_len)
ma_series_b = variant(ma_type_b,ma_src_b,ma_len_b)

direction = 0
direction := rising(ma_series,reaction_ma_1) ? 1 : falling(ma_series,reaction_ma_1) ? -1 : nz(direction[1])
change_direction= change(direction,1)

direction_b = 0
direction_b := rising(ma_series_b,reaction_ma_2) ? 1 : falling(ma_series_b,reaction_ma_2) ? -1 : nz(direction_b[1])
change_direction_b= change(direction_b,1)

// Plot MA series and color it according too direction
pcol = direction>0 ? lime : direction<0 ? red : na
a=plot( ma_1? ma_series :na, color=pcol,style=line,join=true,linewidth=3,transp=10,title="1-MA Plot")

pcol_b = direction_b>0 ? lime : direction_b<0 ? red : na
b=plot( ma_2? ma_series_b :na, color=pcol_b,style=line,join=true,linewidth=2,transp=10,title="2-MA Plot")

fill(a,b,color=direction==1 and direction_b==1 and filling == true?lime:direction==-1 and direction_b==-1and filling == true?red:direction==1 and direction_b==-1and filling == true?purple:direction==-1 and direction_b==1and filling == true?purple:white,transp=80)

/////// Alerts ///////

alertcondition(change_direction,title="Change Direction 1-MA",message="Change Direction 1-MA")
alertcondition(change_direction_b,title="Change Direction 2-MA",message="Change Direction 2-MA")

alertcondition(crossunder(ma_series_b,ma_series),title="Cross Under 2-Ma/1-Ma",message="Cross Under 2-Ma/1-Ma")
alertcondition(crossunder(ma_series,ma_series_b),title="Cross Under 1-Ma/2-Ma",message="Cross Under 1-Ma/2-Ma")

alertcondition(crossover(ma_series_b,ma_series),title="Cross Over 2-Ma/1-Ma",message="Cross Over 2-Ma/1-Ma")
alertcondition(crossover(ma_series,ma_series_b),title="Cross Over 1-Ma/2-Ma",message="Cross Over 1-Ma/2-Ma")

alertcondition(cross(ma_series_b,ma_series),title="Cross 1-Ma/2-Ma",message="Cross 1-Ma/2-Ma")



if crossunder(ma_series,ma_series_b)
    strategy.entry("Enter Long", strategy.long)
else if crossunder(ma_series_b,ma_series)
    strategy.entry("Enter Short", strategy.short)

Relacionados

Más.