MQL5 indicator wrong buffer indexing

 

Hello,

I wrote a few days ago about an indicator i was working to show several TF bollinger bands on the chart of the least selected time frame. I fixed the issue for data retrieving, but there is something else - the information when put into buffers is wrongly outputted.

I printed every value of the BB(for every TF), but for some unknown for me reason, what comes on chart is completely wrong.

   BB_M5 = iBands(_Symbol,PERIOD_M5,BBperiodM5,0,BBdevM5,BBpriceM5);
   BB_M15 = iBands(_Symbol,PERIOD_M15,BBperiodM15,0,BBdevM15,BBpriceM15);
   BB_H1 = iBands(_Symbol,PERIOD_H1,BBperiodH1,0,BBdevH1,BBpriceH1);
   BB_D1 = iBands(_Symbol,PERIOD_D1,BBperiodD1,0,BBdevD1,BBpriceD1);

this is how i get my handles,

double bbM5(int mode,int shift)
  {
   double value[];
   ArrayResize(value,1);
// ArraySetAsSeries(value,true);
   if(CopyBuffer(BB_M5,mode,shift,1,value)<0)
     {
      //Print("Can not copy BB M5  shift ",shift," ",GetLastError());
     }
   return NormalizeDouble(value[0],Digits());
  }

this is how i pick the data for the selected index, i tested this with the normal BB, it works.

      for(int i=0; i<rates_total; i++)
        {
         datetime time = iTime(_Symbol,0,i);
         int m5time = iBarShift(_Symbol,PERIOD_M5,time);
         bbm5[i] = bbM5(0,m5time);
         }

but when i test with something like to code above, the result is unexplicable for me.

I tested several variations of the loop, it worked the same way, except when i loop from 0 to rates_total, the value does not reset the next iteration. This is some other issue im experiencing, but i suppose its connected.

Well, I really hope this can be fixed, thank you for the time

Best Regards Everyone

 

Hi please see here.

And also read this.

ArraySetAsSeries - Array Functions - MQL4 Reference
ArraySetAsSeries - Array Functions - MQL4 Reference
  • docs.mql4.com
The AS_SERIES flag can't be set for multi-dimensional arrays or static arrays (arrays, whose size in square brackets is preset already on the compilation stage). Indexing in timeseries differs from a common array in that the elements of timeseries are indexed from the end towards the beginning (from the newest to oldest data...
 
Marco vd Heijden:

Hi please see here.

And also read this.

wait, what ? It worked. Hmm , i tried it,but it did not work before. 

Thanks for the help Marco

 
The iBands indicator documentation has an error. The correct index for bands : 0 -> Middle , 1 -> Upper and 2 -> Lower

MQL5 documetation says: 
"
SetIndexBuffer(0,UpperBuffer,INDICATOR_DATA);
SetIndexBuffer(1,LowerBuffer,INDICATOR_DATA);
SetIndexBuffer(2,MiddleBuffer,INDICATOR_DATA);
"