Problem with iMAOnArray; It doesn't function. - page 2

 
Amount of processed bars can be increased. If You process the same amount of bars every time you can resize array once or define with constant dimension (2)
 
Resizing on every bar doesn't work, As i mentioned in my previous posts, once resizing in init() also was not working:

extern int SlowPeriod=100;
extern int FastPeriod=15;
extern int MaMethod=MODE_SMA;
 
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Blue
//---- buffers
double L1[];
 
double Price[];
 
 
int indexbegin = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   SetIndexBuffer(0,L1);
   SetIndexLabel(0, "L1");   
   SetIndexStyle( 0, DRAW_HISTOGRAM);
 
   ArraySetAsSeries(Price,true);   
 
   indexbegin = Bars - 20;
   if (indexbegin < 0)
       indexbegin = 0;
    
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int i,j,k;
   
    int counted_bars = IndicatorCounted();    
    //---- check for possible errors
    if (counted_bars < 0) counted_bars = 0;
    //---- last counted bar will be recounted
    if (counted_bars > 0) counted_bars--;
    if (counted_bars > indexbegin) counted_bars = indexbegin;
 
    ArrayResize(Price,Bars);
    
    for (i = indexbegin-counted_bars; i >= 0; i--)
    {    
      ArrayCopySeries(Price,MODE_CLOSE,Symbol(),Period());
      
      L1[i]=-iMAOnArray(Price,0,SlowPeriod,0,MaMethod,i)+iMAOnArray(Price,0,FastPeriod,0,MaMethod,i);
 
      //if instead of the above line I use this:
      //L1[i]=Price[i];
      //a histogram is ploted. so there is not any problem with other parts of code. Only iMAOnArray has a problem.
   }
   return(0);
}
//+------------------------------------------------------------------+
defining the array size at the beginning also deoesn't work.

extern int SlowPeriod=100;
extern int FastPeriod=15;
extern int MaMethod=MODE_SMA;
 
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Blue
//---- buffers
double L1[];
 
double Price[1046];
 
 
int indexbegin = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   SetIndexBuffer(0,L1);
   SetIndexLabel(0, "L1");   
   SetIndexStyle( 0, DRAW_HISTOGRAM);
 
   ArraySetAsSeries(Price,true);   
 
   indexbegin = Bars - 20;
   if (indexbegin < 0)
       indexbegin = 0;
    
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int i,j,k;
   
    int counted_bars = IndicatorCounted();    
    //---- check for possible errors
    if (counted_bars < 0) counted_bars = 0;
    //---- last counted bar will be recounted
    if (counted_bars > 0) counted_bars--;
    if (counted_bars > indexbegin) counted_bars = indexbegin;
    
    for (i = indexbegin-counted_bars; i >= 0; i--)
    {    
      ArrayCopySeries(Price,MODE_CLOSE,Symbol(),Period());
      
      L1[i]=-iMAOnArray(Price,0,SlowPeriod,0,MaMethod,i)+iMAOnArray(Price,0,FastPeriod,0,MaMethod,i);
 
      //if instead of the above line I use this:
      //L1[i]=Price[i];
      //a histogram is ploted. so there is not any problem with other parts of code. Only iMAOnArray has a problem.
   }
   return(0);
}
//+------------------------------------------------------------------+
1046 was the number of bars in my terminal and I got it by Alert(Bars);

In both cases

L1[i]=Price[i];

was working. So there was no problem in initialization of array L1[i]

after all discussions, I think this is correct to conclude there is a bug in iMaOnArray.
 

ArrayCopySeries does not copy real data, acess redirected only. This is not good idea to use series with iMAOnArray. Use standard iMA!

If You need real copying then use ArrayCopy