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:
externintSlowPeriod=100;
externintFastPeriod=15;
externintMaMethod=MODE_SMA;
#property indicator_separate_window#property indicator_buffers 1#property indicator_color1 Blue//---- buffersdoubleL1[];
doublePrice[];
intindexbegin = 0;
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intinit(){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 |//+------------------------------------------------------------------+intdeinit(){return(0);
}//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+intstart(){inti,j,k;
intcounted_bars = IndicatorCounted();
//---- check for possible errorsif(counted_bars < 0)counted_bars = 0;
//---- last counted bar will be recountedif(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.
externintSlowPeriod=100;
externintFastPeriod=15;
externintMaMethod=MODE_SMA;
#property indicator_separate_window#property indicator_buffers 1#property indicator_color1 Blue//---- buffersdoubleL1[];
doublePrice[1046];
intindexbegin = 0;
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intinit(){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 |//+------------------------------------------------------------------+intdeinit(){return(0);
}//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+intstart(){inti,j,k;
intcounted_bars = IndicatorCounted();
//---- check for possible errorsif(counted_bars < 0)counted_bars = 0;
//---- last counted bar will be recountedif(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.
defining the array size at the beginning also deoesn't work.
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