Multi Time Frame Moving Average - Creating Squigly Lines....

 

Hi!

I am using this Multi Time Frame Moving Average, but instead of straight lines as it should it paints squigly lines where I have to refresh the chart to get them to paint as they are supposed to do.

Could someone please look into the code and see if you can spot what is wrong?

I am using MetaTrader 4 build 1260

Thanks,

GormTheOld

 

For example, if it is displaying a 5-minute MA on a one-minute chart, it will need to redraw the MA every five minutes (i.e., when the data is finalized).

int start()
  {
   datetime TimeArray[];
   int    i,limit,y=0,counted_bars=IndicatorCounted();
   int    M = TimeFrame / Period();
   if (TimeFrame == 0) M = 1;
// Plot defined timeframe on to current timeframe   
   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame); 
   
   if (counted_bars == 0)
        limit = Bars - MAPeriod * M;
   else
        limit=(Bars-counted_bars) * M;
        
   for(i=0,y=0;i<=limit;i++)
   {
   if (Time[i]<TimeArray[y]) y++; 

 
Nagisa Unada:

For example, if it is displaying a 5-minute MA on a one-minute chart, it will need to redraw the MA every five minutes (i.e., when the data is finalized).

I'm so sorry for my late reply Nagisa.

As for your coding, thank you very much for your help. The indicator seems to be working as it should.


I have tried to figure out how to make it calculate on bar close instead of every tick, but it seems like there is no straight answer on how to do that.

Could you please share/show the way you think is the best way to do this?


Thanks

 
Nagisa Unada: , if it is displaying a 5-minute MA on a one-minute chart, it will need to redraw the MA every five minutes 
Wrong. The indicator on the higher timeframe is changing its bar zero value each tick. You need to redraw all bars corresponding to that value.
          How to do your lookbacks correctly #9 - #14 & #19