Some ambiguity with function iMAOnArray...

 

Hi everyone,

I have some (easy) ambiguity with function iMAOnArray

My basic code is below. When I run MT platform, function Alert() write value function iMAOnArray, but this value is error. Return value very big number= 2147483647. When I do then compile again indicator code - Alert() write value iMAOnArray ok. Why? I don´t know!

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Blue

extern string Market1 = "YMM2";
extern string Market2 = "ESM2";
extern int MAPeriod = 200;

extern int MA_Period=2;
extern int MA_Shift=0;
extern int MA_Method=0;
extern double Distance_H=0.75;
extern double Distance_L=0.25;
/* 
MODE_SMA 0 Simple moving average, 
MODE_EMA 1 Exponential moving average, 
MODE_SMMA 2 Smoothed moving average, 
MODE_LWMA 3 Linear weighted moving average. 
*/
//extern int Applied_Price=0;
extern double Deviation=0.1;
//---- indicator buffers

double PomerBuf[];
int bars, i;
bool newBar=false;

int init() {

   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, PomerBuf);
   //SetIndexEmptyValue(0,0.0);

   int    draw_begin;
   string short_name;

   if(MA_Period<2) MA_Period=14;
   draw_begin=MA_Period-1;
   bars=0;
   
   return (0);
}

int deinit() 
{
   return (0);
}

int start() 
{

   int ExtCountedBars = IndicatorCounted();
   if (ExtCountedBars > 0) ExtCountedBars--;
   int limit = Bars - ExtCountedBars;
   for (i = 0; i < limit; i++) 
   {
      
      PomerBuf[i]=i%10;
      //ArraySetAsSeries(PomerBuf,false);
      
      if (i<100&& bars==0) Alert( i,"-",TimeToStr(Time[i], TIME_DATE|TIME_MINUTES),"   ",
                                  DoubleToStr(PomerBuf[i],2)," ", 
                                  DoubleToStr(iMAOnArray(PomerBuf,0,MA_Period,0,MA_Method,i),6)
                                 );           
   }
      bars=1;
   return (0);
}
 
You need two loops, one to set the buffer then another to set the iMA on the array. The point is that if any values in the iMA on array are null it will screw up the average. So the main buffer has to be complete (full) before you call iMA on Array.
 
Thanks dabbler. You are right! Indicator works good already.
Reason: