Array out of range. Please help. Please help.

To add comments, please log in or register
Siew Fei Wong
188
Siew Fei Wong  

How to solve the problem "Array out of range"?

Below is the error happening during running stage.

Please help. I'm not a programmer. 

------------------------------------------------------ 

datetime time;

bool IsNewBar()

{

   bool retVAR = false;

   if(time != Time[0])

   {

      time = Time[0];

      retVAR = true;

   }

   return (retVAR;

------------------------------------------------------  

Stanislav Korotky
31699
Stanislav Korotky  
There can be perfectly a situation when you have no bars in history, so Time[0] is out of bounds. You should check available bar number via Bars.
Siew Fei Wong
188
Siew Fei Wong  

So what can i do in order to overcome this error?

Can show me the way? =( 

Alain Verleyen
39055
Alain Verleyen  
Jason:

So what can i do in order to overcome this error?

Can show me the way? =( 

You just got the answer, please do some efforts to understand it or pay someone to code it for you.
Bartlomiej Gorski
11104
Bartlomiej Gorski  
Siew Fei Wong:

So what can i do in order to overcome this error?

Can show me the way? =( 

To check if you have any bars on chart use this snippet:

datetime time;

bool IsNewBar()
{

   bool retVAR = false;
   if(Bars>0)
   {
      if(time != Time[0])
      {
         time = Time[0];
         retVAR = true;
      }
   }
   return (retVAR);

} 
To add comments, please log in or register