How to apply DEMA or TEMA on custom indicators array/buffer

 

Hello Guys,

I coded a bunch of custom indicators, but I have an issue, I can not solve myself. Hope You can help me out with some info about this.
The indicator I am working on has a custom buffer, and I would like to apply DEMA or TEMA on that buffer's data. I am looking for a way to do that like iMAOnArray(), but with DEMA or TEMA not MA, EMA, SMA, etc.

In other words, I am looking for a way to apply iDEMA, iTEMA or iCustom on a specific array buffer, not just on prices.

I am coding in MQL5.

Thanks!

 
  1. There is no iMAOnArray in MT5. Why did you post your MT4 question in the Root / MT5 Indicators section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. doubleEMA(x) = EMA(EMA(x)) So use iMAOnArray on your buffer, putting the result in a new buffer. Repeat again for doubleEMA. Repeat again for tripleEMA. Or just compute it directly:
    #define EMA(P, C, L) ((P) + ((C)-(P))*2./(L+1))
    double val  = bValue[i] = ...;
    double ema  = bEMA[i]   = EMA( bEMA[i+1],  val,  Length );
    double ema2 = bEMA2[i]  = EMA( bEMA2[i+1], ema,  Length );
    double ema3 = bEMA3[i]  = EMA( bEMA3[i+1], ema2, Length );
    Then you can compute TEMA/DEMA using the formulas Mladen Rakic gives below.
              Double exponential moving average - Wikipedia
              Triple exponential moving average - Wikipedia
 

DEMA = ( 2 * EMA(n)) - (EMA(EMA(n)) ), where n= period



 
@whroeder1

I know that there is no iMAOnArray in MQL5. My question is MQL5 related, just want to let you know what kind of feature I was looking for, thats why I mentioned an MQL4 function (most forum members are familiar with both language versions).

@Mladen Rakic
Thanks for the formula!

I was thinking there is no way to apply iDEMA, iTEMA or iCustom directly on a buffer, so I implemented DEMA and TEMA myself.

Reason: