Ehler's ZMA

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #50378 quote
    supertiti
    Participant
    Master
    
    
    ZMA, Ehler’s Zero-Lag Moving Average, an EMA with a correction term for removing lag. This is the source code: 
    var ZMA(var *Data,int Period)
    {
      var *ZMA = series(Data[0]);
      var a = 2.0/(1+Period);
      var Ema = EMA(Data,Period);
      var Error = 1000000;
      var Gain, GainLimit=5, BestGain=0;
      for(Gain = -GainLimit; Gain < GainLimit; Gain += 0.1) {
         ZMA[0] = a*(Ema + Gain*(Data[0]-ZMA[1])) + (1-a)*ZMA[1];
         var NewError = Data[0] - ZMA[0];
         if(abs(Error) < newError) {
           Error = abs(newError);
           BestGain = Gain;
         }
      }
      return ZMA[0] = a*(Ema + BestGain*(Data[0]-ZMA[1])) + (1-a)*ZMA[1];
    ////////////////////////////////////////////////////////////////////////
    

    Bonjour à tous,

    Il est possible de traduire pour Prorealtime cette moyenne zéro retard de John Ehlers ?

    d’avance merci

    #50383 quote
    zen83
    Participant
    Senior

    Bonjour Supertiti,

    n’est ce pas la #65 de ce post suivant ?

    Indicateur AFR – Average Filter Regression

    bonne journée

    Zen

    #50387 quote
    supertiti
    Participant
    Master

     

    Voici le code de Laurenzo , Nicolas nous dira si cela correspond

    //-----------------------------//
    // 65 - ZLJE - Zero Lag John Ehlers //
    //-----------------------------//
    
    IF MAType = 65 THEN
    
    Period = MAX(Period, 2)
    
    alpha = 2 / (1 + Period)
    per = ROUND((Period - 1) / 2)
    
    IF BarIndex < per THEN
       AFR = Series
    ELSE
       AFR = AFR[1] + alpha * (2 * Series - Series[per] - AFR[1])
    ENDIF
    
    ENDIF
    #50624 quote
    Nicolas
    Keymaster
    Master

    Je pense qu’il s’agit bien de la même moyenne mobile en effet. La seule différence c’est l’utilisation d’un facteur fixe en lieu et place du ‘bestgain’ de la version initiale, en effet pour obtenir le ‘bestgain’, soit le meilleur gain pour l’amplification du signal, il faudrait faire une boucle en complément du code de Laurenzo. Je vais essayer de voir si je peux le recoder de zéro.

    #50627 quote
    Nicolas
    Keymaster
    Master

    Bon, après avoir recodé ce type de moyenne mobile à l’aide du code fournit par Supertiti, on constate en effet une grosse différence (jaune celle du code de Laurenzo et en blanche la nouvelle).

    Voici donc le code selon ma propre interprétation:

    Period=20
    Data = customclose
    once ZMA = customclose
    once a = 2.0/(1+Period)
    Ema = average[Period,1](Data)
    once Error = 1000000
    once GainLimit = 5
    BestGain = 0
    Gain = -GainLimit
    
    if barindex>Period then 
    While Gain < GainLimit do 
    Gain = Gain+0.1 
    ZMA = a*(Ema + Gain*(Data-ZMA[1])) + (1-a)*ZMA[1]
    NewError = Data - ZMA
    if(abs(Error) < newError) then
    Error = abs(newError)
    BestGain = Gain
    endif
    wend
    
    ZMA = a*(Ema + BestGain*(Data-ZMA[1])) + (1-a)*ZMA[1]
    endif
    
    return ZMA

    Bizarrement, je la trouve pas si réactive pour une moyenne mobile “sans lag” à période égale avec d’autres, il faudrait pouvoir vérifier avec une autre plateforme/code pourquoi pas …

    zero-lag-moving-average-john-ehlers.png zero-lag-moving-average-john-ehlers.png
    #50684 quote
    supertiti
    Participant
    Master

    Bonjour Nicolas,

    C’est vrai juste à l’oeil on voit que ça ressemble plus a une moyenne pondérée qu’à autre chose.

    J’ai mis les trois moyennes sur les prix et le code que je propose est indentique à un moyenne pondérée de PRT.

    en jaune celle de laurenzo

    en rose   celle de Nicolas

    en bleu pointillée  celle de PRT où p = 56

    merci Nicolas pour ton soutien

    Bonne journée

    ZMA-PRC.jpg ZMA-PRC.jpg
    #50704 quote
    Nicolas
    Keymaster
    Master

    Je ne sais pas où tu as récupéré le code que tu proposes, peut-être que l’on peut trouver une autre version quelque part ailleurs ?

    #50723 quote
    supertiti
    Participant
    Master
    #50727 quote
    Nicolas
    Keymaster
    Master

    Bon, je viens de retrouver un code d’une version en EasyLanguage, et je pense que cette fois on tient la bonne (version ProBuilder ci-dessous):

    Length=20
    GainLimit=50
    alpha=0
    Gain=0
    BestGain=0
    EC=0
    Error=0
    LeastError=0
    EMA=0
    alpha = 2 / (Length + 1)
    
    if barindex>Length then 
    EMA = alpha*Close + (1 - alpha)*EMA[1]
    LeastError = 1000000
    For Value1 = -GainLimit to GainLimit do
    Gain = Value1 / 10
    EC = alpha*(EMA + Gain*(Close - EC[1])) + (1 - alpha)*EC[1]
    Error = Close - EC
    If Abs(Error) < LeastError Then 
    LeastError = Abs(Error)
    BestGain = Gain
    Endif
    next
    EC = alpha*(EMA + BestGain*(Close - EC[1])) + (1 - alpha)*EC[1]
    endif
    
    return EC
    Ehlers-ZeroLag-moving-average.png Ehlers-ZeroLag-moving-average.png
    #50746 quote
    supertiti
    Participant
    Master

    Oui celle est plus réactive que celle de Laurenzo

    merci pour ton support

    Bonne soirée

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

Ehler's ZMA


ProBuilder : Indicateurs & Outils Personnalisés

New Reply
Author
author-avatar
supertiti @supertiti Participant
Summary

This topic contains 9 replies,
has 3 voices, and was last updated by supertiti
8 years, 4 months ago.

Topic Details
Forum: ProBuilder : Indicateurs & Outils Personnalisés
Language: French
Started: 10/24/2017
Status: Active
Attachments: 3 files
Logo Logo
Loading...