Problems with iMaOnArray

 
hello,
i am currently developing a entry strategy based on bollingerbands.
for trend direction i use the BB-main line as signal line and a iMaOnArray(14) of the BB-main.
for better explanation here is a pic:

Blue line is the BB-band 31
Red line is iMaOnArray(14) of BB-band31

as you can see in the code below i am using this 2 functions for filling the buffers:
      ExtMapBuffer3[pos]=iBands(Symbol(),Period(),31,2,0,PRICE_OPEN,MODE_MAIN,pos);
      ExtMapBuffer4[pos]=iMAOnArray(ExtMapBuffer3,0,14,pos,MODE_SMA,0);
the first thing i don't understand why i have to insert "pos" in the iMaOnArray funtion as argument nr. 4 instead of nr. 7.
second is that this funtion requires a imense amount of calculation time. so backtesting/optimizing is not a option.

what is tried i using
      ExtMapBuffer4[pos]=iMAOnArray(ExtMapBuffer3,0,14,0,MODE_SMA,pos);
instead of
      ExtMapBuffer4[pos]=iMAOnArray(ExtMapBuffer3,0,14,pos,MODE_SMA,0);
results in the strategy-tester are the same, but option 1 seems to be faster.
but in visual mode, the second indicator line is drawn only after the time the indicator is addet. (as seen on the screenshot)



can anyone explain me the correct use of iMaOnArray since it wont work as the documantation let asume. also i dont understand why it would be so "expensive" to calculate?
i hope you get my point.

//Michael


here is the whole souce code:
//+------------------------------------------------------------------+
//|                                              AAA-EntryPoints.mq4 |
//|                                                                i |
//|                                                              n/a |
//+------------------------------------------------------------------+
#property copyright "i"
#property link      "n/a"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 DodgerBlue
#property indicator_color2 Red

#property indicator_color3 DodgerBlue
#property indicator_color4 Red
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW,STYLE_SOLID,3);
   SetIndexArrow(0,217);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,3);
   SetIndexArrow(1,218);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(1,0.0);

   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexEmptyValue(2,0.0);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexEmptyValue(3,0.0);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
 if(Period()!=PERIOD_M1&&Period()!=PERIOD_M5)  
   for(int pos=counted_bars;pos>=0;pos--){
      ExtMapBuffer3[pos]=iBands(Symbol(),Period(),31,2,0,PRICE_OPEN,MODE_MAIN,pos);
//      ExtMapBuffer4[pos]=iMAOnArray(ExtMapBuffer3,0,14,pos,MODE_SMA,0);
      ExtMapBuffer4[pos]=iMAOnArray(ExtMapBuffer3,0,14,0,MODE_SMA,pos);
      if(ExtMapBuffer3[pos]>ExtMapBuffer4[pos]){
         if(Low[pos]<ExtMapBuffer3[pos])
            if(High[pos]>ExtMapBuffer3[pos])
               if(Open[pos]<Close[pos])
                  if(Open[pos]>ExtMapBuffer4[pos])
                     ExtMapBuffer1[pos]=ExtMapBuffer3[pos];
      }

      if(ExtMapBuffer3[pos]<ExtMapBuffer4[pos]){
         if(High[pos]>ExtMapBuffer3[pos])
            if(Low[pos]<ExtMapBuffer3[pos])
               if(Open[pos]>Close[pos])
                  if(Open[pos]<ExtMapBuffer4[pos])
                     ExtMapBuffer2[pos]=ExtMapBuffer3[pos];      
      }
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
      ExtMapBuffer4[pos]=iMAOnArray(ExtMapBuffer3,0,14,pos,MODE_SMA,0);
the first thing i don't understand why i have to insert "pos" in the iMaOnArray funtion as argument nr. 4 instead of nr. 7.
From the manual:
limit=Bars-counted_bars;
for(i=limit-1; i>=0; i--)
ExtBuffer[i]=iMAOnArray(ExtMABuffer,Bars,5,0,MODE_SMA,i);
The last parameter is the starting position to use. leave 4 as a zero.
But for this work EXTMapBuffer3 must be filled so iMAonArray can function
but your loop only calculated indicator_counted bars not ALL bars
Count down like the above example
 
WHRoeder:
From the manual: The last parameter is the starting position to use. leave 4 as a zero.
But for this work EXTMapBuffer3 must be filled so iMAonArray can function
but your loop only calculated indicator_counted bars not ALL bars
Count down like the above example

works! thx

Reason: