Script runs too slow

 

Any idea why a script is taking hours to scan through 500+ symbols? Yes 500 symbols! 

At first, it didn't have any issue with that except occasionally displaying "Error out of range" so I fixed it by using the lines of codes inserted below and suddenly the script is now so slow. Please any suggestion is gladly welcome.

for(int i = 0; i < SymbolsTotal(true); i++)
    
    { 
     MqlRates PriceInfo[];        // defines closePrice. Source: https://www.youtube.com/watch?v=H10QFIZoUYA
     ArraySetAsSeries(PriceInfo,true);
     int Data = CopyRates(SymbolName(i,1),PERIOD_D1, 0, 1,PriceInfo);
                                                        //--- Check the number of values copied
     if(Data!=1)
     continue;
// what you are reading is a snippet
 
Chioma Obunadike:

Any idea why a script is taking hours to scan through 500+ symbols? Yes 500 symbols! 

At first, it didn't have any issue with that except occasionally displaying "Error out of range" so I fixed it by using the lines of codes inserted below and suddenly the script is now so slow. Please any suggestion is gladly welcome.

I would say it is running slow because loading historical ticks with CopyRate takes time. Probably because ticks are not available.