Líneas horizontales según MACD

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #234224 quote
    dratzither
    Participant
    New

    Querría obtener una línea horizontal en el precio cada vez que MACD alcance un máximo y después un mínimo o viceversa (soporte en verde, resistencia en rojo), ¿es posible programarlo?

    Actualmente pongo las líneas a mano, pero cuando a veces necesito ver el ajuste por dividendos y estas líneas mueven la referencia.

    Gracias

    #234228 quote
    druby
    Participant
    New

    Pruebe esto, vea si dibuja líneas en la posición correcta. Si necesitas un cambio, trata de ser específico.

    La variable llamada “línes” limitaba el número de líneas dibujadas.
    “Lastbars” limitaba el número de barras utilizadas en los cálculos. Cero significa usar todas las barras. 100 significa comenzar en el compás 100.

     

     

    defparam drawonlastbaronly = true
    
    lastbars = 0
    lines = 7
    
    once below = 0
    once above = 1
    once id = 0
    
    // indicators
    iMacd   = MACDline[12,26,9](close)
    iSignal = MACDSignal[12,26,9](close)
    
    if barindex > min(30,lastbars) then
    
    // conditions
    
    xover = below
    if iMacd > iSignal then
    xover = above
    
    if iMacd crosses over iSignal then
    id = id + 1
    endif
    endif
    
    
    if xover = above then
    if iMacd > iMacd[1] then
    $hi[id] = barindex
    endif
    endif
    
    if xover = below then
    if iMacd < iMacd[1] then
    $lo[id] = barindex
    endif
    endif
    
    endif
    
    // drawing
    if islastbarupdate then
    
    for i = max(0,lastset($hi)-lines+1) to lastset($hi)
    hi = high[$hi[i]]
    x1 = barindex-$hi[i]
    y1 = high[x1]
    x2 = 0
    y2 = y1
    
    drawsegment(barindex[x1],y1,barindex[x2]+5,y2) coloured("red")style(dottedline,1)
    //drawtext(i,barindex[x2]+11,y1) coloured("red")
    drawtext(y1,-120,y1) anchor(right,xshift,value) coloured("red")
    next
    
    for i = max(0,lastset($lo)-lines+1) to lastset($lo)
    x1 = barindex - $lo[i]
    y1 = low[x1]
    x2 = 0
    y2 = y1
    
    drawsegment(barindex[x1],y1,barindex[x2]+5,y2) coloured("lime")style(dottedline,1)
    //drawtext(i,barindex[x2]+12,y1) coloured("lime")
    drawtext(y1,-50,y1)anchor(right,xshift,value) coloured("lime")
    next
    
    endif
    
    //drawtext(xover,barindex,20)anchor(bottom,index,yshift)coloured("yellow")
    
    return
    dratzither and Iván González thanked this post
    #234230 quote
    dratzither
    Participant
    New

    Muchas gracias, es exactamente lo que buscaba.

    Si quisiera cambiar el timeframe para que las líneas fuesen siempre en base al MACD mensual (aunque cambie la vista a diario o semanal),  ¿dónde tendría que ponerlo?

    #234231 quote
    druby
    Participant
    New

    Su solicitud no es fácil de implementar. El comando “Período de tiempo” no es compatible con los tres “períodos de tiempo”.

    Además, el código escrito necesitaría muchos cambios para mostrarse correctamente en los otros marcos temporales.

    Actualmente, la única solución que se me ocurre es derivar un MACD mensual personalizado a partir del marco temporal del gráfico y, a partir de ahí, calcular las líneas.

    No es una solución rápida. Lo investigaré.

    Si alguien tiene una solución, que se sume.

    #234358 quote
    dratzither
    Participant
    New

    He probado a multiplicar los iMACD e iSIGNAL por 365/12/7, es una aproximación pero cuanto más te alejas de la fecha actual menos preciso es respecto al timeframe mensual.

    #234395 quote
    druby
    Participant
    New

    Hola… Prueba esta versión.
    Solo funciona en marcos temporales de 1 día, 1 semana y 1 mes.

    Los mejores resultados se obtienen con las unidades 1 mes = 25, 1 semana = 1000 y 1 fecha = 10 000.

    Compara las líneas con lo que dibujarías.

    Si detectas algún problema, publícalo y lo analizaré.

     

     

    lines = 5  // 0 or positve integer, smaller than lines drawn!
    error = 1  // display error message
    
    if barindex = 0 then
    once below = 0
    once above = 1
    once Hid = 0
    once Lid = 0
    $hi[0]=0
    $lo[0]=0
    
    gTF = getTimeframe
    
    if gtf = 86400 then       // 1day
    m = 30.416667          // days   365/12 days/month     10,000 units
    TF=1
    elsif gtf = 604800 then   // 1week
    m = 4.333334           // weeks  365/52 weeks/month   1000 units
    TF=2
    elsif gtf >= 2419200 and gtf <= 2678400 then // 1 month  25units
    m = 1                  //  months
    TF=0
    else
    TF = -1
    if error = 1 then
    Drawtext("Monthly,<br> Weekly,  <br> Daily    <br> Timeframes only!"/*
    */  ,0,0,monospaced,bold,30) /*
    */  coloured("red") anchor(middle,xshift,yshift)
    endif
    endif
    
    a = 12 * m
    b = 26 * m
    c = 9  * m
    
    endif
    
    if barindex > b and TF >= 0 then
    
    iMacd   =   MACDline[max(1,a),max(1,b),max(1,c)](close)
    iSignal = MACDSignal[max(1,a),max(1,b),max(1,c)](close)
    
    // is macd line crosses above 
    if iMacd > iSignal and iMacd [1] < iSignal[1] then
    Hid = Hid + 1
    HH=high
    HHb = barindex
    xOver = above
    endif
    
    // is macd line crosses below
    if iMacd < iSignal and iMacd [1] > iSignal[1] then
    Lid = Lid + 1
    LL = low
    LLb = barindex
    xOver = below
    endif
    
    // highs
    if xover = above then
    if high > HH then
    HH = high
    HHb = barindex
    endif
    endif
    
    if openmonth <> openmonth[1] then
    $hi[Hid] = HHb
    endif
    
    // lows
    if xover = below then
    if low < LL then
    LL = low
    LLb = barindex
    endif
    endif
    
    if openmonth <> openmonth[1] then
    $lo[Lid] = LLb
    endif
    
    
    if islastbarupdate then
    
    // drawing highs
    for i = max(0,lastset($hi)-lines+1) to lastset($hi)
    
    x1 = barindex-$hi[i]
    y1 = high[x1]
    x2 = 0
    y2 = y1
    
    drawsegment(barindex[x1],y1,barindex[x2]+5,y2) coloured("red")style(dottedline,1)
    drawtext(y1,-120,y1+5) anchor(right,xshift,value) coloured("red")
    next
    
    // drawing lows
    
    for i = max(0,lastset($lo)-lines+1) to lastset($lo)
    x1 = barindex - $lo[i]
    y1 = low[x1]
    x2 = 0
    y2 = y1
    
    drawsegment(barindex[x1],y1,barindex[x2]+5,y2) coloured("lime")style(dottedline,1)
    drawtext(y1,-50,y1)anchor(right,xshift,value) coloured("lime")
    next
    endif
    
    endif
    return 
    /**/
    #234422 quote
    dratzither
    Participant
    New

    En algunos tickers fallan algunas líneas. Por ejemplo en el ticker HOME (BME):

    • Las líneas en 16 y 14 no se generan en base al MACD
    • en mensual dibuja unas líneas entre 2020 y 2022 que en semanal no aparecen

    Trabajo con zonas visibles de 145U (145 meses y 145 semanas), no sé si tendrá algo que ver.

    Gracias por tu dedicación.

    #234438 quote
    druby
    Participant
    New

    Hola..
    La imagen 1 muestra el número predeterminado en las barras visibles, tanto para el gráfico semanal como para el mensual, y también se representan mediante rectángulos azules. Las líneas del gráfico semanal se alinean con las líneas correspondientes del gráfico mensual. Sin embargo, algunas líneas mensuales parecen faltar en el gráfico semanal. En la parte inferior de los gráficos, se encuentran el código MACD y el MACD de acciones, todos para el gráfico mensual.

    Imagen 2: El gráfico semanal se amplía en el eje x para mostrar todas las barras. La línea vertical representa el punto de inicio de la línea faltante más reciente. Sin embargo, al observar el código MACD, aún no está definido y no se puede detectar el punto de cruce para esa línea.

    Imagen 3: Se amplía el gráfico mensual para mostrar todas las barras. La línea vertical se mueve al inicio del gráfico semanal y se refleja en el gráfico mensual. Las otras líneas faltantes no solo no están cubiertas por el código MACD semanal, sino que esas barras ni siquiera están presentes.

    Para que el gráfico semanal represente todas las líneas mensuales, tiene que haber suficientes datos históricos cargados para capturar el código MACD de cruce, que luego dibuja su línea.

    En 145 unidades, eso significa que se cargaron 650 barras históricas y se necesitan 150 barras para calcular el inicio de la señal MACD. Y luego esperar el cruce.

    En este momento, la única solución es aumentar los datos históricos hasta que se representen todas las líneas requeridas.

    No se muestra, noté que dos líneas no coincidían en absoluto. Esto se debió a que, cuando recorrí las matrices para dibujar las líneas, comenzó en el índice cero, y esto no era válido y debería haber comenzado en ‘1’.

    Además, para el gráfico diario, habrá un escenario similar, pero se necesitan incluso más barras para representar todas las líneas mensuales.

    Espero que esto explique lo que está sucediendo.

     

     

    once iMacd = undefined
    once iSignal = undefined
    
    lines = 5  // 0 or positve integer, smaller than lines drawn!
    error = 1  // display error message
    
    if barindex = 0 then
    once below = 0
    once above = 1
    once Hid = 0
    once Lid = 0
    $hi[0]=0
    $lo[0]=0
    
    gTF = getTimeframe
    
    if gtf = 86400 then       // 1day
    m = 30.416667          // days   365/12 days/month     10,000 units
    TF=1
    elsif gtf = 604800 then   // 1week
    m = 4.333334           // weeks  365/52 weeks/month   1000 units
    TF=2
    elsif gtf >= 2419200 and gtf <= 2678400 then // 1 month  25units
    m = 1                  //  months
    TF=0
    else
    TF = -1
    if error = 1 then
    Drawtext("Monthly,<br> Weekly,  <br> Daily    <br> Timeframes only!"/*
    */  ,0,0,monospaced,bold,30) /*
    */  coloured("red") anchor(middle,xshift,yshift)
    endif
    endif
    
    a = 12 * m
    b = 26 * m
    c = 9  * m
    
    endif
    
    if barindex > b and TF >= 0 then
    
    iMacd   =   MACDline[max(1,a),max(1,b),max(1,c)](close)
    iSignal = MACDSignal[max(1,a),max(1,b),max(1,c)](close)
    
    // is macd line crosses above
    if iMacd > iSignal and iMacd [1] < iSignal[1] then
    Hid = Hid + 1
    HH=high
    HHb = barindex
    xOver = above
    endif
    
    // is macd line crosses below
    if iMacd < iSignal and iMacd [1] > iSignal[1] then
    Lid = Lid + 1
    LL = low
    LLb = barindex
    xOver = below
    endif
    
    // highs
    if xover = above then
    if high > HH then
    HH = high
    HHb = barindex
    endif
    endif
    
    if openmonth <> openmonth[1] then
    $hi[Hid] = HHb
    endif
    
    // lows
    if xover = below then
    if low < LL then
    LL = low
    LLb = barindex
    endif
    endif
    
    if openmonth <> openmonth[1] then
    $lo[Lid] = LLb
    endif
    
    
    if islastbarupdate then
    
    // drawing highs
    for i = max(1,lastset($hi)-lines+1) to lastset($hi)
    
    x1 = barindex-$hi[i]
    y1 = high[x1]
    x2 = 0
    y2 = y1
    
    drawsegment(barindex[x1],y1,barindex[x2]+5,y2) coloured("red")style(dottedline,1)
    drawtext(y1,-120,y1+5) anchor(right,xshift,value) coloured("red")
    next
    
    // drawing lows
    
    for i = max(1,lastset($lo)-lines+1) to lastset($lo)
    x1 = barindex - $lo[i]
    y1 = low[x1]
    x2 = 0
    y2 = y1
    
    drawsegment(barindex[x1],y1,barindex[x2]+5,y2) coloured("lime")style(dottedline,1)
    drawtext(y1,-50,y1)anchor(right,xshift,value) coloured("lime")
    next
    endif
    
    endif
    return
    /**/
    dratzither thanked this post
    #234465 quote
    dratzither
    Participant
    New

    Gracias por la explicación, un saludo.

    #234470 quote
    druby
    Participant
    New

    Aquí hay otra versión, donde calculé valores precisos para el número de días/semanas en un mes y también si es un saltoAquí hay otra versión, donde calculé valores precisos para el número de días/semanas en un mes y también si es un año bisiesto.

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.

Líneas horizontales según MACD


ProBuilder: Indicadores y Herramientas

New Reply
Author
author-avatar
dratzither @dratzither Participant
Summary

This topic contains 9 replies,
has 2 voices, and was last updated by druby
1 year, 7 months ago.

Topic Details
Forum: ProBuilder: Indicadores y Herramientas
Language: Spanish
Started: 06/22/2024
Status: Active
Attachments: 7 files
Logo Logo
Loading...