Never miss Ticks - page 2

 
Derrick Mutange #: Thank you so much , let me test it out look at the code below and let me know if I have made any mistakes
  1. When only trading the current symbol, then you don't need to use the timer event.
  2. When setting the timer event you have to verify its return value to make sure it succeeded, and if not, you have to retry after a small delay. It does not always succeed on the first attempt.
  3. Since you have not shown your code processing the CopyTicks() data, I am unable to comment on that.
 
Fernando Carreiro #:
  1. When only trading the current symbol, then you don't need to use the timer event.
  2. When setting the timer event you have to verify its return value to make sure it succeeded, and if not, you have to retry after a small delay. It does not always succeed on the first attempt.
  3. Since you have not shown your code processing the CopyTicks() data, I am unable to comment on that.
#include <Trade\SymbolInfo.mqh>
#include <Arrays\ArrayObj.mqh>

class MySymbol : public CSymbolInfo
{
protected:
   ENUM_TIMEFRAMES   m_period;
   MqlRates          m_rates[];
   datetime          m_bartime;
public:
   MySymbol(const string symbol,ENUM_TIMEFRAMES period):m_period(period)
   {
      m_name = symbol;
      ArraySetAsSeries(m_rates,true);
   }
   int BarsTotal() const { return ArraySize(m_rates);}
   bool RefreshRates()
   {
      datetime btime = (datetime)SeriesInfoInteger(m_name,m_period,SERIES_LASTBAR_DATE);
      if(m_bartime != btime || BarsTotal() < 300)
      {
         if(CopyRates(m_name,m_period,0,Bars(m_name,m_period),m_rates)<300)
            return false;
         m_bartime = btime;
      }
      return CSymbolInfo::RefreshRates();
   }
   double   Open  (const int i) const { return m_rates[i].open; }
   double   High  (const int i) const { return m_rates[i].high; }
   double   Low   (const int i) const { return m_rates[i].low ; }
   double   Close (const int i) const { return m_rates[i].close;}
   datetime Time  (const int i) const { return m_rates[i].time; }
};

class MySymbolCollection : public CArrayObj
{
public:
   MySymbol* operator[](const int index)const{return(MySymbol*)At(index);}
   bool  Init(string &syms[])
   {
      Clear();
      for(int i=0;i<ArraySize(syms);i++)
      {
         for(int j=0;j<SymbolsTotal(false);j++)
         {
            if(StringFind(SymbolName(j,false),syms[i])>=0)
            {
               Add(new MySymbol(SymbolName(j,false),Period()));
               break;
            }
         }
      }
      EventSetTimer(1);
      return true;
   }
   bool RefreshRates()
   {
      bool res = true;
      for(int i=0;i<Total();i++)
         if(!this[i].RefreshRates())  
            res = false;
      return res;
   }
};

string sym[]={    "AUDCAD","AUDCHF","AUDJPY","AUDNZD","AUDUSD","EURAUD","GBPAUD",
                  "CADCHF","CADJPY","EURCAD","GBPCAD","NZDCAD","USDCAD","CHFJPY",
                  "EURCHF","GBPCHF","NZDCHF","USDCHF","EURGBP","EURJPY","EURNZD",
                  "EURUSD","GBPJPY","GBPNZD","GBPUSD","NZDJPY","USDJPY","NZDUSD"};
MySymbolCollection symbols;
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   symbols.Init(sym);
   symbols.RefreshRates();
//---
   return(INIT_SUCCEEDED);
  }

void OnTick()
{
//---
   if(!symbols.RefreshRates())
   {
      Print(__FUNCTION__+" Waiting for data");
      return;
   }
   else
   {
      for(int i=0;i<symbols.Total();i++)
         string symbol =symbol.Name();
         CheckForOpen(symbol);
   }
   // --- stuff with symbol data....
}
//+------------------------------------------------------------------+
void OnTimer()
{
   symbols.RefreshRates();
   EventKillTimer();
}

I used the code this way sorry about that, do I need to use the CheckForOpen() function also in ontimer?

 
Derrick Mutange #: I used the code this way sorry about that, do I need to use the CheckForOpen() function also in ontimer?
Derrick Mutange #: Thanks for the reply the EA is not based on bars. How can I fix then, do I just place the EA on the individual symbols?

You stated earlier that your EA did not operate on Bars, but Ticks instead. However, your code is working with Bars and not Ticks. Please make up your mind.

If you are unable to understand the basics of a single symbol EA, it will difficult for you to code a multi-symbol one. So I suggest you first design your EA to work with only one symbol (the current symbol), and then once it is working properly and you understand how to program it, then you can move on to Multi-symbol EA.