Download MetaTrader 5
To add comments, please log in or register
Do you have idle PCs? Connect them to MQL5 Cloud Network and earn money!
Carl Schreiber
5930
Carl Schreiber 2014.10.06 08:09 

Hi,

I realized that the mt4 built-in function iMaOnArray(..) seems not to update the average with the new ticks of the actual bar. It seem to calc. only at the beginning of the bar - quasi at open - and then the average is not updated each time a new tick arrives.

Hmm  ????

So I wrote a little 'indicator' (attached) and now both iMaOnArray(..) averages are 0.0000 - Am I doing s.th. wrong?

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
        int per2=2, per5=5;
   int i,counted_bars=IndicatorCounted();
   int limit = Bars-counted_bars-1;
   double iMa2,iMa5,xMa2,xMa5;
   for(i=limit; i>=0; i--) {
        if (Bars-i<per5+1)continue;
        iMa2 = iMAOnArray(Close,0,per2,0,MODE_SMA,i);
        iMa5 = iMAOnArray(Close,0,per5,0,MODE_SMA,i);
        xMa2 = (Close[i]+Close[i+1])*0.5;
        xMa5 = (Close[i]+Close[i+1]+Close[i+2]+Close[i+3]+Close[i+4])*0.2;
                Comment(
                        "Ma2[",i,"] iMa2:",DoubleToStr(iMa2,Digits),"  -  xMa2: ",DoubleToStr(xMa2,Digits),"  =  ",DoubleToStr(iMa2-xMa2,Digits),
                        "Ma5[",i,"] iMa5:",DoubleToStr(iMa5,Digits),"  -  xMa5: ",DoubleToStr(xMa5,Digits),"  =  ",DoubleToStr(iMa5-xMa5,Digits)
                );
                DebugBreak();
   }
        Comment(
                "Ma2[",i,"] iMa2:",DoubleToStr(iMa2,Digits),"  -  xMa2: ",DoubleToStr(xMa2,Digits),"  =  ",DoubleToStr(iMa2-xMa2,Digits),
                "Ma5[",i,"] iMa5:",DoubleToStr(iMa5,Digits),"  -  xMa5: ",DoubleToStr(xMa5,Digits),"  =  ",DoubleToStr(iMa5-xMa5,Digits)
        );
        DebugBreak();
//--- return value of prev_calculated for next call
   return(rates_total);
  }
Files:
/
To add comments, please log in or register