How to avoid array out of range

JLLMNCHR picture JLLMNCHR · Sep 16, 2015 · Viewed 14k times · Source

Does somebody know how to avoid the error array out of range when trying to display long number of bars (lets say 7000) in an indicator buffer?

Answer

Jan Rasehorn picture Jan Rasehorn · Oct 14, 2015

I had a similar issue, that I always got "Array out of range" errors for one of my buffers. I checked with ArraySize(), which returned 0.

In the end I just forgot to call SetIndexBuffer(...) for this buffer array in onInit() {...} of my indicator.

Since I was using an internal buffer without drawing lines, I used the IndicatorBuffers() function to increase the amount of buffers first and then registered my additonal buffer using SetIndexBuffer(...).

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

   IndicatorBuffers(5);

//buffers with #properties settings
   SetIndexBuffer(0,Buffer1);
   SetIndexBuffer(1,Buffer2);
   SetIndexBuffer(2,Buffer3);
   SetIndexBuffer(3,Buffer4);

//additional buffer without #properties 
   SetIndexBuffer(4,AdditionalBuffer);