Symbol Scanner - Indicator values

 

It's been a while, but I'm back trading again.  There is something that I need to get done before I can start.  I need to calculate indicator values for every symbol that is loaded.  My code currently looks as follows to calculate the ATR< however the ATR CopyBuffer returns -1.  Any idea what I'm doing wrong?

Is it possible to do this for 500 symbols?  Can MT5 handle it?

   int symbolCount=SymbolsTotal(true);
   string symbolsList[1000];

   for(int i=0;i<symbolCount;i++)
   {
      symbolsList[i] = SymbolName(i,true);
   }

   for (int i = 0;i < symbolCount;i++)
   {
      int      MA_Period = 15;                              // The value of the averaging period for the indicator calculation
      int      Count = 5;                                   // Amount to copy
      int      ATRHandle;                                   // Variable to store the handle of ATR
      double   ATRValue[];                                  // Variable to store the value of ATR    
      ATRHandle = iATR(symbolsList[i],PERIOD_D1,MA_Period); // returns a handle for ATR
      ArraySetAsSeries(ATRValue,true);                      // Set the ATRValue to timeseries, 0 is the oldest. 

      int result =  CopyBuffer(ATRHandle,0,0,Count,ATRValue);
      Print(result);

      if(result > 0)
      {

         for( int j=0;j<Count;j++ )
         {
            Print(ATRValue[j]); // Print the value of the ATR

         } 
      }
   }
 
int    MA_Period = 15,
       Count = 5,
       symbolCount;
string symbolsList[];

struct SATR
{
     int    handle;
     double buffer[];
} atr[];

void OnInit()
{
   symbolCount=SymbolsTotal(true);
   if( ArrayResize(symbolsList, symbolCount) < symbolCount ) ExpertRemove();
   if( ArrayResize(atr,         symbolCount) < symbolCount ) ExpertRemove();

   for(int i=0;i<symbolCount;i++)
   {
      symbolsList[i] = SymbolName(i,true);
      atr[i].handle = iATR(symbolsList[i],PERIOD_D1,MA_Period);
      ArraySetAsSeries(atr[i].buffer,true);
   }
}
void OnTick()
{

   for (int i=0; i<symbolCount; i++)
   {
      if( CopyBuffer(atr[i].handle,0,0,Count,atr[i].buffer) < Count )
          continue;

      for( int j=0;j<Count;j++ )
         Print(atr[i].buffer[j]); // Print the value of the ATR
   }
}
 
Konstantin Nikitin:

Thanks appreciate the help.  The code won't execute past the CopyBuffer() line.  Do I need to force the load of historical data somehow?

 
Franco:

Do I need to force the load of historical data somehow?

https://www.mql5.com/en/docs/series/timeseries_access

Look for the function CheckLoadHistory()