I myself solved it like this. Hope this is useful to others.
extern int SlowPeriod=21; #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Blue #property indicator_color2 Red //---- buffers double U[]; double D[]; //Arrays instead of indicator buffers as many as you like double Price[]; double H[]; int indexbegin = 0; static datetime CurrTime; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { SetIndexBuffer(0,U); SetIndexLabel(0, "UpTrend"); SetIndexEmptyValue(0, NULL); SetIndexStyle( 0, DRAW_LINE); SetIndexBuffer(1,D); SetIndexLabel(1, "DownTrend"); SetIndexEmptyValue(0, NULL); SetIndexStyle( 1, DRAW_LINE); //All of the arrays must be initiated: ArrayResize(Price,Bars); ArraySetAsSeries(Price,true); ArrayResize(H,Bars); ArraySetAsSeries(H,true); for (int i = Bars-1; i >= 0; i--) { Price[i]=Close[i]; } 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; //Shifting all arays one cell because of new bar if(CurrTime != Time[0]) { for (i = Bars-2; i > 0; i--) { Price[i+1]=Price[i]; H[i+1]=H[i]; } //Initializing values for new bar Price[0]=Close[0]; H[0]=0; S[0]=0; } //For every thick these values must be renewed Price[0]=Close[0]; CurrTime=Time[0]; //rest of code like an Ordinary indicator. you can use H , S , other arrays the same way as indicator buffers 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--) { //Ordinary indicator } return(0); }

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Can you please help me?
for my indicator, I need to store some data Items for each bar, But the number of Items is more than 7. only two of them have to be shown on screen but about 9 others are only for back side calculations. Is it possible to use arrays like indicator buffers with automatic shifting when new bar? any solutions or code samles?
thanks.