Download MetaTrader 5

Believe this needs an expert familiar on the arrays of Structure !!!

To add comments, please log in or register
moonsboy
891
moonsboy  

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
104
ThreadHandle  

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

Just put 1 between the brackets 

whroeder1
16105
whroeder1  
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
891
moonsboy  
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