MqlRates close price for many symbols

 

I'm using multi symbol ea with classes and need to get close of last bar but through the usual method with MqlRates I get last close only for the 1st pair in list.

bool CTradingEngine31::SearchTradingSignals(void)
  {
        MqlRates rates[];
        ArraySetAsSeries(rates,true);

        if(CopyRates(_Symbol, _Period, 0, 3, rates) != 3)
        {
         Print("CopyRates of ",_Symbol," failed, no history");
         return(false);
        }

        if(rates[1].close >whatever)
                --do something--
}
CTradingEngine31 *multi_1=new CTradingEngine31;
   if(multi_1==NULL)
     {
      Print("Object CTradingEngine31 create error");
      return(INIT_FAILED);
     }
   m_array_obj.Add(multi_1);
   init=multi_1.OnInit(InpSymbol_1,--Inputs--);
   if(init!=INIT_SUCCEEDED)
      return(init);
//----
CTradingEngine31 *multi_2=new CTradingEngine31;
   if(multi_2==NULL)
     {
      Print("Object CTradingEngine31 create error");
      return(INIT_FAILED);
     }
   m_array_obj.Add(multi_2);
   init=multi_2.OnInit(InpSymbol_2, --Inputs--);
   if(init!=INIT_SUCCEEDED)
      return(init);
void OnTick()
  {
//---
   for(int i=0; i<m_array_obj.Total(); i++)
     {
      CTradingEngine31 *multi=m_array_obj.At(i);
      if(multi==NULL)
        {
         //--- Error reading from array
         Print("Object CMultiGrid create error");
         return;
        }
      multi.OnTick();
     }
  }
 
bool CTradingEngine31::SearchTradingSignals(void)
  {
        MqlRates rates[];
        ArraySetAsSeries(rates,true);

        if(CopyRates(_Symbol, _Period, 0, 3, rates) != 3)
        {
         Print("CopyRates of ",_Symbol," failed, no history");
         return(false);
        }

        if(rates[1].close >whatever)
                --do something--
}

You are copying rates from the current chart only, Where are your other symbols engaged?

I was expecting something like this

bool CTradingEngine31::SearchTradingSignals(void)
  {
        MqlRates rates[];
        ArraySetAsSeries(rates,true);
        
        for (int i=0; i<ArraySize(Symbols_Array); i++)
          if(CopyRates(Symbols_Array[i], _Period, 0, 3, rates) != 3)
          {
           Print("CopyRates of ",Symbols_Array[i]," failed, no history");
           return(false);
          }

        if(rates[1].close >whatever)
                --do something--
}

 
Omega J Msigwa #:

You are copying rates from the current chart only, Where are your other symbols engaged?

I was expecting something like this

You mean this?

int CTradingEngine31::OnInit(string _TradeSymbol )
  {
   ResetLastError();
   if(!m_symbol.Name(_TradeSymbol)) // sets symbol name
      return(INIT_FAILED);
   RefreshRates();
        -------code-------
}
So _TradeSymbol should be Symbols_Array?
 
timmytrade #:

You mean this?

Hold on! I don't know your entire code, just check your entire copy rates method call to ensure you copy all the symbols in a loop

 
Omega J Msigwa #:

Hold on! I don't know your entire code, just check your entire copy rates method call to ensure you copy all the symbols in a loop

Raw code without data

Files:
Example.mq5  82 kb
 
Sorry, I can read your entire code to spot bugs  I can point out what's wrong in a very specific areas so that you fix it yourself. If you can't open a freelance work for me or anyone else available by the way I have checked the code there are multiple imports and include files that I don't have in my pc so nobody can compile and debug the file anyway. I think you are better off asking about the issue than sharing the entire code
 
timmytrade:

I'm using multi symbol ea with classes and need to get close of last bar but through the usual method with MqlRates I get last close only for the 1st pair in list.

From google

Is this the original code?

 
traderz #:

From google

Is this the original code?

Could be, I don't know, I just found empty ea template and trying to fill it with my own data.

This code works well but there I also didn't find anything about copying rates. So my question remains same.

 

Something similar maybe?

string Tradesymbol[];

MqlRates rates[];
ArraySetAsSeries(rates,true);

for (int i=0; i<ArraySize(TradeSymbol); i++)
      if(CopyRates(TradeSymbol[i], _Period, 0, 3, rates) != 3)
          {
           Print("CopyRates of ",TradeSymbol[i]," failed, no history");
           return(false);
          }