Conversion indicateur TradingView “Impulse MACD” de LazyBear

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #209565 quote
    Louloute
    Participant
    Average

    Bonjour,

    J’ai converti le code de l’indicateur TradingView “Impulse MACD” de LazyBear

    mais j’ai du me tromper car je n’obtiens pas de graph. en retour. Quelqu’un peut-il jeter un coup d’œil ?

    J’ai un doute sur ma conversion de la ligne “smma=na(smma[1]) ? sma(src, len) : (smma[1] * (len – 1) + src) / len” car je n’ai pas pris en compte la partie “na(smma[1]) ” que je ne comprend pas bien.

    En pièce jointe mon code.

    Ci-dessous le lien ainsi que le code de l’indicateur “Impulse MACD” de LazyBear :

    https://fr.tradingview.com/v/qt6xLfLi/

    Code TradingView “Impulse MACD” de LazyBear :

    //
    // @author LazyBear
    //
    // List of my public indicators: http://bit.ly/1LQaPK8
    // List of my app-store indicators: http://blog.tradingview.com/?p=970
    //
    //
    study(“Impulse MACD [LazyBear]”, shorttitle=”IMACD_LB”, overlay=false)
    lengthMA = input(34)
    lengthSignal = input(9)
    calc_smma(src, len) =>
    smma=na(smma[1]) ? sma(src, len) : (smma[1] * (len – 1) + src) / len
    smma

    calc_zlema(src, length) =>
    ema1=ema(src, length)
    ema2=ema(ema1, length)
    d=ema1-ema2
    ema1+d

    src=hlc3
    hi=calc_smma(high, lengthMA)
    lo=calc_smma(low, lengthMA)
    mi=calc_zlema(src, lengthMA)

    md=(mi>hi)? (mi-hi) : (mi<lo) ? (mi – lo) : 0
    sb=sma(md, lengthSignal)
    sh=md-sb
    mdc=src>mi?src>hi?lime:green:src<lo?red:orange
    plot(0, color=gray, linewidth=1, title=”MidLine”)
    plot(md, color=mdc, linewidth=2, title=”ImpulseMACD”, style=histogram)
    plot(sh, color=blue, linewidth=2, title=”ImpulseHisto”, style=histogram)
    plot(sb, color=maroon, linewidth=2, title=”ImpulseMACDCDSignal”)

    ebc=input(false, title=”Enable bar colors”)
    barcolor(ebc?mdc:na)

    //

     

    Merci.

    #209572 quote
    Nicolas
    Keymaster
    Master

    C’est un bloc conditionnel IF THEN ENDIF en 1 seule ligne. Ici le na() test si la variable smma[1] (donc dans la bougie qui précède) est Non Available (soit nulle), si c’est le cas alors on fait une moyenne mobile simple sans cette valeur, sinon on utilise dans un calcul plus élaboré.

    En ProBuilder, cette fonction n’existe pas, on peut soit attendre une bougie (en faisant IF BARINDEX>1 ou en testant si la variable n’est pas égale à 0).

    Je regarde ton code.

    #209575 quote
    Nicolas
    Keymaster
    Master

    Ton code est correct, félicitations ! Le problème c’est en effet l’impossibilité de calculer quelquechose dés les premiers chandeliers car on a des valeurs nulles, donc il faut ajouter une condition sur le barindex, en général j’utilise la valeur la plus élevé des périodes de calcul, ici “lengthMA”, soit attendre 34 chandeliers avant de lancer des calculs:

    // @author LazyBear
    
    // Paramètres en entrée
    lengthMA = 34
    lengthSignal = 9
    
    //src=hlc3
    src = (high + low + close)/3
    //
    
    if barindex>lengthMA then 
    //calc_smma(src, len) =>
    //smma=na(smma[1]) ? sma(src, len) : (smma[1] * (len - 1) + src) / len
    //smma
    //hi=calc_smma(high, lengthMA)
    hi = (hi[1] * (lengthMA - 1) + high) / lengthMA
    //lo=calc_smma(low, lengthMA)
    lo = (lo[1] * (lengthMA - 1) + low) / lengthMA
    
    //calc_zlema(src, length) =>
    //ema1=ema(src, length)
    //ema2=ema(ema1, length)
    //d=ema1-ema2
    //ema1+d
    //mi=calc_zlema(src, lengthMA)
    ema1 = ExponentialAverage[lengthMA](src)
    ema2 = ExponentialAverage[lengthMA](ema1)
    d = ema1 - ema2
    mi = ema1 + d
    
    //md = (mi>hi) ? (mi-hi) : (mi<lo) ? (mi-lo) : 0
    if mi > hi then
    md = mi - hi
    elsif mi < lo then
    md = mi - lo
    else
    md = 0
    endIf
    
    //sb = sma(md, lengthSignal)
    //sh = md - sb
    sb = Average[lengthSignal](md)
    sh = md - sb
    
    //mdc = src>mi ? src>hi ? lime : green : src<lo ? red : orange
    if src > mi then
    if src > hi then
    //mdc = lime
    mdcR = 0
    mdcG = 255
    mdcB = 0
    else
    //mdc = green
    mdcR = 0
    mdcG = 128
    mdcB = 0
    endIf
    elsIf src < lo then
    //mdc = red
    mdcR = 255
    mdcG = 0
    mdcB = 0
    else
    //mdc = orange
    mdcR = 255
    mdcG = 165
    mdcB = 0
    endIf
    
    //plot(0, color=gray, linewidth=1, title="MidLine")
    //plot(md, color=mdc, linewidth=2, title="ImpulseMACD", style=histogram)
    //plot(sh, color=blue, linewidth=2, title="ImpulseHisto", style=histogram)
    //plot(sb, color=maroon, linewidth=2, title="ImpulseMACDCDSignal")
    
    //ebc=input(false, title="Enable bar colors")
    //barcolor(ebc?mdc:na)
    endif 
    
    return 0 as "MidLine", md COLOURED(mdcR, mdcG, mdcB) style(histogram,1) as "ImpulseMACD", sh COLOURED("blue") style(histogram,2) as "ImpulseHisto", sb COLOURED("maroon") style(line,2) as "ImpulseMACDCDSignal"//, ema1, ema2
    
    Louloute thanked this post
    #209578 quote
    Louloute
    Participant
    Average

    Merci !!

    J’ai eu du mal aussi avec la partie ci-dessous en jaune :

    On utilise hi[1] (ou encore lo[1]) alors qu’on ne l’a jamais calculé auparavant ?

    #209583 quote
    Nicolas
    Keymaster
    Master

    Oui dans ce cas c’est égal à 0 pour le premier calcul.

    Mais comme indiqué dans mon premier message, dans le code initial il ne l’utilise pas si égale à 0, en langage ProBuilder ce serait comme ceci:

    if hi[1] = 0 then //NA
    hi = average[lengthMA](high) //je remplis ma variable avec une valeur "quelconque"
    else
    hi= (hi[1] * (lengthMA - 1) + high) / lengthMA //hi[1]existe alors je commence mes vrais calculs
    endif
    Louloute thanked this post
    #209600 quote
    Louloute
    Participant
    Average

    OK ! Merci.

    A+

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

Conversion indicateur TradingView “Impulse MACD” de LazyBear


ProBuilder : Indicateurs & Outils Personnalisés

New Reply
Author
author-avatar
Louloute @louloute Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by Louloute
2 years, 11 months ago.

Topic Details
Forum: ProBuilder : Indicateurs & Outils Personnalisés
Language: French
Started: 02/13/2023
Status: Active
Attachments: 4 files
Logo Logo
Loading...