Indicators: MultiMA

 

MultiMA:

Shows - in this version - up to 3 MA from different timeframes. Maybe is usefulll for someone. Enter the period for the ma's in Minute of the desired timeframe, f.e ma2_periode=15 shows you the ma for the timeframe M15. Enter in ma2 the Calculte Perio

Author: r.v.

 

ATTENTION: this indicator is WRONG!


You cannot call iMA on different timeframes using the same barshift of the current timeframe.... what you get is a senseless series of numbers.

The correct way to address data from different timeframes is to get, in the current timeframe, the time of opening of the bar you want to process (i) and using iBarshift find out to which bar of  another timeframe that opening time belongs.

Visually you should expect to see MA of bigger timeframes moving by steps, ie you need 5 M1 bars to make an M5 bar... and if the current timeframe is M1 the displayed MA for M5 shall remain constant for 5 bars... and so on :)


Here a sample code which will fix your indicator:

I used same MA periods and methods for different timeframes. Also added the option to change applied prices from external.

//--------------------------------------------------------------------
   Counted_bars=IndicatorCounted(); 
   i=Bars-Counted_bars-1;           
               
   while(i>=0)                      
     {
      time=iTime(Symbol(),0,i);
      iM1=iBarShift(Symbol(),ma1_TF,time,false);
      iM2=iBarShift(Symbol(),ma2_TF,time,false);
      iM3=iBarShift(Symbol(),ma3_TF,time,false);
      Buf_0[i]=iMA(Symbol(),ma1_TF,MA_Period,0,MA_Method,MA_AppliedPrice,iM1);
      Buf_1[i]=iMA(Symbol(),ma2_TF,MA_Period,0,MA_Method,MA_AppliedPrice,iM2);
      Buf_2[i]=iMA(Symbol(),ma3_TF,MA_Period,0,MA_Method,MA_AppliedPrice,iM3);
      i--;                          
     }
//--------------------------------------------------------------------
Reason: