Download MetaTrader 5
To add comments, please log in or register
Read the interviews of the Automated Trading Championship participants
moonsboy
889
moonsboy 2015.12.08 07:26 

Please refer to the screenshot below.  

Why does the "Experts Log" always say "array out of range" even though I changed "symbolCount" in line 37 into '0'?  

 

 

Below is the complete code.  

#property strict
input string ExClude="#";
input string Prefix="";
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
struct Valid
  {
   string            name;
   int               POS;
  };
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+         
void symbolFilter()
  {

   Valid validSymbol[];
   int i,preLen=StringLen(Prefix)-1,symbolCount=0,arraySize;
   int   totalPOS=SymbolsTotal(true);  //Dont't forget to "Show All" in "Market Watch"
   string Display=" ",symbolName;
//---  
   for(i=0;i<totalPOS;i++)
     {//use 'true' in order to be consistent with the sequence in "Market Watch"   
      //filter symbols with "ExClude" 
      symbolName=SymbolName(i,true);
      if(StringFind(symbolName,ExClude,preLen)==-1)
        {
         validSymbol[symbolCount].name=symbolName;
         validSymbol[symbolCount].POS=i;
         arraySize=ArraySize(validSymbol);
         if(++symbolCount>=arraySize) ArrayResize(validSymbol,arraySize+1);
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   Comment("");
   Print(__FUNCTION__,"_Uninitalization reason code = ",reason);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   symbolFilter();
  }
//+------------------------------------------------------------------+
ThreadHandle
105
ThreadHandle 2015.12.08 08:32  

ValidSymbol must have some value to initiate its size, so put some numbers between the brackets ;)

Just put 1 between the brackets 

whroeder1
13641
whroeder1 2015.12.08 14:53  
Keelan: ValidSymbol must have some value to initiate its size, so put some numbers between the brackets ;
That makes it a fixed array and can't be resized.
jollydragon: Why does the "Experts Log" always say "array out of range" even though I changed "symbolCount" in line 37 into '0'? 
   Valid validSymbol[];
   int symbolCount=0
   for(i=0;i<totalPOS;i++){
         validSymbol[symbolCount].name=symbolName;
You are storing into validSymbol[0], but the array has no size. Resize the array and then store.
ArrayResize(validSymbol, symbolCount + 1);
validSymbol[symbolCount].name=symbolName;
validSymbol[symbolCount].POS=i;
++symbolCount;
moonsboy
889
moonsboy 2015.12.09 02:16  
WHRoeder:
That makes it a fixed array and can't be resized.
You are storing into validSymbol[0], but the array has no size. Resize the array and then store.

 

Thanks a lot !! 

/
To add comments, please log in or register