Download MetaTrader 5
To add comments, please log in or register
Deposit to your account via Visa QIWI Wallet
Ndumiso Mavuso
4371
Ndumiso Mavuso 2016.02.05 19:40 

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);

  }
Stuart Browne
5780
Stuart Browne 2016.02.06 01:36  
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.
Biantoro Kunarto
14803
Biantoro Kunarto 2016.02.06 07:59  

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);
  }
Biantoro Kunarto
14803
Biantoro Kunarto 2016.02.06 08:00  
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.
Ndumiso Mavuso
4371
Ndumiso Mavuso 2016.02.06 08:54  
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.
Biantoro Kunarto
14803
Biantoro Kunarto 2016.02.06 09:02  
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);
Ndumiso Mavuso
4371
Ndumiso Mavuso 2016.02.06 09:06  

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].

Ndumiso Mavuso
4371
Ndumiso Mavuso 2016.02.06 09:09  
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
Stuart Browne
5780
Stuart Browne 2016.02.06 11:15  
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 ;-)
Roberto Jacobs
46332
Roberto Jacobs 2016.02.06 11:55  
Stuart Browne:
Yes, good point! I guess I needed to have my coffee first ;-)
wise.. :-)
Drazen Penic
2537
Drazen Penic 2016.02.06 14:17  

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;
/
To add comments, please log in or register