Using iMAOnArray to evaluate buffer of indicator

 

Hi all,

I am trying to create a simple indicator that tracks the movements of the account equity and provides 2 values:

Buffer 0=account equity (taken from another indicator with iCustom function)

Buffer 1= simple moving average of the account equity


For Buffer 0 everything is fine, I cross checked with the original indicator.

For Buffer 1 there is no way to get correct values...I get an extremely high value on the average, that has no sense.

can you please help me?

Thanks a lot

ciao




#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Gray
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];

extern int MAPeriod=20;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);

   ArrayInitialize(ExtMapBuffer2,EMPTY_VALUE);
   SetIndexEmptyValue(1,EMPTY_VALUE);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----

   for(int i=200;i>0;i--)
     {
      ExtMapBuffer1[i]=iCustom(NULL,0,"z_equityMonitor_no_param",0,i);
     }
   for(int a=200;a>0;a--) ExtMapBuffer2[a]=iMAOnArray(ExtMapBuffer1,0,MAPeriod,0,MODE_SMA,0);
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
for(int a=200;a>0;a--) ExtMapBuffer2[a]=iMAOnArray(ExtMapBuffer1,0,MAPeriod,0,MODE_SMA,0);

maybe you mean

for(int a=200;a>0;a--) ExtMapBuffer2[a]=iMAOnArray(ExtMapBuffer1,0,MAPeriod,0,MODE_SMA,a);

and the first buffer should be filled by at least a+MAPeriod

 
Keith Watford:

maybe you mean

and the first buffer should be filled by at least a+MAPeriod

ahaha...thanks Keith! what a dumb error! thank you!
Reason: