#property strict critical error

 

This is my Spread indicator. Can someone tell me why time[3000] is out of range when #property strict is used and how to fix it without removing #property strict

//+------------------------------------------------------------------+
//| Show Spread                                                      |
//+-----------------------------------------------------------Ndumiso+
  void spreadraw ()
  {
  Comment("");ObjectDelete("Set1");ObjectDelete("Set2");ObjectDelete("Set3");
    double time;
      double colour;
       double Bidd=MarketInfo(Symbol(),MODE_BID   );
     double Askk=MarketInfo(Symbol(),MODE_ASK   );
  double Sprea=MarketInfo(Symbol(),MODE_SPREAD);
  
  if(Spread<=MaxSpread)colour=clrLimeGreen;
  else colour=clrRed;
  
  if(Period()==1)time=60;
   if(Period()==5)time=300;
    if(Period()==15)time=900;
     if(Period()==30)time=1800;
      if(Period()==60)time=3600;
       if(Period()==240)time=14400;
     if(Period()==1440)time=86400;
    if(Period()==10080)time=604800;
  if(Period()==43200)time=2592000;
  
  ObjectCreate("Set1",OBJ_RECTANGLE,0,Time[3000]+time/2,Bidd,TimeCurrent()+time*5,Askk); //Error is here?
     ObjectSet("Set1",OBJPROP_COLOR,colour);
       ObjectCreate("Set2",OBJ_RECTANGLE,0,TimeCurrent()+time*5,Bidd,TimeCurrent()+time*1000,Askk);
        ObjectSet("Set2",OBJPROP_COLOR,colour);
       ObjectCreate("Set3",OBJ_TEXT,0,TimeCurrent()+time*10,(4*Ask+Bidd)/5);
     ObjectSetText("Set3",DoubleToStr(Sprea/10,1),8,"Lucida console",White);

  }
 
Ndumiso Mavuso:

This is my Spread indicator. Can someone tell me why time[3000] is out of range when #property strict is used and how to fix it without removing #property strict

Because in your code, time is not an array, but you are trying to access it as an array.
 

I think the Bars in your chart is less than 3000, you must use this :

//+------------------------------------------------------------------+
//| Show Spread                                                      |
//+-----------------------------------------------------------Ndumiso+
  void spreadraw()
  {
  if ( Bars < 3000 ) return;
  Comment("");ObjectDelete("Set1");ObjectDelete("Set2");ObjectDelete("Set3");
    double time=0;
      double colour;
       double Bidd=MarketInfo(Symbol(),MODE_BID   );
     double Askk=MarketInfo(Symbol(),MODE_ASK   );
  double Sprea=MarketInfo(Symbol(),MODE_SPREAD);
  
  if(Spread<=MaxSpread)colour=clrLimeGreen;
  else colour=clrRed;
  
  if(Period()==1)time=60;
   if(Period()==5)time=300;
    if(Period()==15)time=900;
     if(Period()==30)time=1800;
      if(Period()==60)time=3600;
       if(Period()==240)time=14400;
     if(Period()==1440)time=86400;
    if(Period()==10080)time=604800;
  if(Period()==43200)time=2592000;
  
  ObjectCreate("Set1",OBJ_RECTANGLE,0,Time[3000]+(int)time/2,Bidd,TimeCurrent()+(int)time*5,Askk); //Error is here?
     ObjectSet("Set1",OBJPROP_COLOR,colour);
       ObjectCreate("Set2",OBJ_RECTANGLE,0,TimeCurrent()+(int)time*5,Bidd,TimeCurrent()+(int)time*1000,Askk);
        ObjectSet("Set2",OBJPROP_COLOR,colour);
       ObjectCreate("Set3",OBJ_TEXT,0,TimeCurrent()+(int)time*10,(4*Ask+Bidd)/5);
     ObjectSetText("Set3",DoubleToStr(Sprea/10,1),8,"Lucida console",White);
  }
 
Stuart Browne:
Because in your code, time is not an array, but you are trying to access it as an array.
He isn't use time as an array, he use Time as an array.
 
biantoro kunarto:

I think the Bars in your chart is less than 3000, you must use this :

I still get an erray out of range after 3000 bars.
 
Ndumiso Mavuso:
I still get an erray out of range after 3000 bars.

You must check your history data, I have no problem using this script because my Bars = 7600, you can try this script and see what's the result:

Print( "Bar = ",Bars);
 

Ok I got it thank you for your opinions.

Seems like Time can not or not allowed to access 3000 bars, I do not need it to anyway so I reduce it to Time[300].

 
biantoro kunarto:

You must check your history data, I have no problem using this script because my Bars = 7600, you can try this script and see what's the result:

Yes my history might be less But I got it to work now thank you
 
biantoro kunarto:
He isn't use time as an array, he use Time as an array.
Yes, good point! I guess I needed to have my coffee first ;-)
 
Stuart Browne:
Yes, good point! I guess I needed to have my coffee first ;-)
wise.. :-)
 

You need to check for 3001 bars. 

For 3000 bars you can check array values with indices from 0-2999 

Try with this: 

 if ( Bars < 3001 ) return;
Reason: