Bugs and suggestions for improving CopyTicks() and CopyTicksRange() after build 1485. - page 4

 
Yury Kirillov:
Try to use in your Expert Advisor all possible ways to receive ticks and OnTick and CopyTicks, and then compare the results and use the most adequate one.
And what does OnTick() have to do with it? It's not intended to receive all ticks, but for processing of the fact of ticks receipt. You don't even need to compare anything here, OnTick() won't be called at every tick and it won't allow to receive all data of MqlTick structure.
 
Service Desk offered to try it on the new build, 1545. But the result has not changed, as before, requesting ticks from 10 am to 11 am for some papers returns zero arrays, and then the data starts coming from 11.00 for some reason. Maybe after that the ticks are already "normal" when querying, but there is no relevance.
 
That's pretty much the only message they send. It's been quite a while now, the service desk is not responding. Is ignoring my messages normal?
 
antru:
That's pretty much the only message they send. It's been quite a while now, the service desk is not responding. Is ignoring my messages normal?
About ignoring your messages - you have the wrong branch. There's a separate thread about SD. In fact, remind them by writing a comment on the application. Have you attached the code and other evidence to the BOD?
 
Alexey Kozitsyn:
About ignoring your posts - you have the wrong thread. There is a separate thread about SD. In fact, remind them by writing a comment on the application. Did you attach the code and other evidence to the BOD?

Yes, of course, even explained the code... silence... Thanks for the tip, I'll put it in a separate thread
 

Made debugging code to check CopyTicksRange. While the service desk is permanently silent, I wondered if there' s an error in the code. My eyes must have glazed over... Please look at it with fresh eyes.

Below is the code, attache the results. First zip - start of Metatrader before trading, the second zip - start at 10:30 pm EST (time in debug files was 3 hours less).

I don't understand why in the first zip no ticks came back on any paper.

At all. Folks, how do you get the tape in real time? Maybe I'm reinventing the wheel and doing something wrong, can you give me an example code on how to get ticks on papers in real time?

//+------------------------------------------------------------------+
//|                                                     Smelchak.mq5 |
//|                                                      Pavel&Antru |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Pavel&Antru"
#property link      ""
#property version   "1.00"

bool g_bEnterInfoSent = false;

datetime g_dEndOfTheDay;
datetime g_dDayBegin;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
   EventSetTimer(3);
   
   MqlDateTime startTime;
   TimeGMT(startTime);
   startTime.hour = 7;
   startTime.min = 0;
   startTime.sec = 0;
   g_dDayBegin = StructToTime(startTime);
   
   startTime.hour = 17;
   startTime.min = 0;
   startTime.sec = 0;
   g_dEndOfTheDay = StructToTime(startTime);
   
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
}
//+------------------------------------------------------------------+

void OnTimer()
{
   MqlDateTime mdt;
   datetime dCurrent = TimeCurrent(mdt);
   
   if (!g_bEnterInfoSent && mdt.hour + 3 == 9)
   {
      MqlDateTime startTime;
      TimeGMT(startTime);
      startTime.hour = 7;
      startTime.min = 0;
      startTime.sec = 0;
      g_dDayBegin = StructToTime(startTime);
      
      startTime.hour = 17;
      startTime.min = 0;
      startTime.sec = 0;
      g_dEndOfTheDay = StructToTime(startTime);
      
      g_bEnterInfoSent = true;
   }
   
   if (g_bEnterInfoSent && mdt.hour + 3 == 22)
   {
      g_bEnterInfoSent = false;
   }
   
   datetime lastTime = TimeCurrent();
   
   MqlDateTime dayBegin;
   TimeToStruct(g_dDayBegin, dayBegin);

   MqlDateTime dayEnd;
   TimeToStruct(g_dEndOfTheDay, dayEnd);
   
   MqlDateTime curTime;
   TimeToStruct(lastTime, curTime);
   
   if (true) //(lastTime >= g_dDayBegin && lastTime < g_dEndOfTheDay)
   {
      MqlTick tick[];
      int nResult = CopyTicksRange(Symbol(), tick, COPY_TICKS_ALL, (ulong)g_dDayBegin*1000, (ulong)g_dEndOfTheDay*1000);
      int nLastError = GetLastError();
      
      string sDebugFileName = StringFormat("%s.debug.%.04d.%.02d.%.02d.csv", Symbol(), dayBegin.year, dayBegin.mon, dayBegin.day);
   
      int nDebugOutputFile = FileOpen(sDebugFileName, FILE_READ | FILE_WRITE | FILE_CSV, ',');
      if (nDebugOutputFile == INVALID_HANDLE) nDebugOutputFile = FileOpen(sDebugFileName, FILE_WRITE | FILE_CSV, ',');
      
      if (nDebugOutputFile != INVALID_HANDLE)
      {
         FileSeek(nDebugOutputFile, 0, SEEK_END);

         MqlDateTime tickTime;
         
         if (ArraySize(tick))
         {
            TimeToStruct(tick[0].time, tickTime);
            
            FileWrite(nDebugOutputFile, StringFormat("%.04d.%.02d.%.02d %.02d:%.02d:%.02d.000", dayBegin.year, dayBegin.mon, dayBegin.day,
                                                                                                dayBegin.hour, dayBegin.min, dayBegin.sec),
                                        StringFormat("%.04d.%.02d.%.02d %.02d:%.02d:%.02d.000", dayEnd.year, dayEnd.mon, dayEnd.day,
                                                                                                dayEnd.hour, dayEnd.min, dayEnd.sec),                                                        
                                        StringFormat("%.04d.%.02d.%.02d %.02d:%.02d:%.02d.000", curTime.year, curTime.mon, curTime.day,
                                                                                                curTime.hour, curTime.min, curTime.sec),
                                        StringFormat("%.04d.%.02d.%.02d %.02d:%.02d:%.02d.000", tickTime.year, tickTime.mon, tickTime.day,
                                                                                                tickTime.hour, tickTime.min, tickTime.sec),
                                        ArraySize(tick),
                                        nResult,
                                        nLastError);
                                        
            /////////////////////////////////////////////////////////
            string sTicksFileName = StringFormat("%s.ticks.%.04d.%.02d.%.02d.csv", Symbol(), dayBegin.year, dayBegin.mon, dayBegin.day);
         
            int nTicksOutputFile = FileOpen(sTicksFileName, FILE_READ | FILE_WRITE | FILE_CSV, ',');
            if (nTicksOutputFile == INVALID_HANDLE) nTicksOutputFile = FileOpen(sTicksFileName, FILE_WRITE | FILE_CSV, ',');
            
            if (nTicksOutputFile != INVALID_HANDLE)
            {
               FileSeek(nDebugOutputFile, 0, SEEK_END);
      
               MqlDateTime tickTime;
            
               for (int i = 0; i<ArraySize(tick); i++)
               {
                  TimeToStruct(tick[i].time, tickTime);
                  
                  FileWrite(nTicksOutputFile, StringFormat("%.04d.%.02d.%.02d %.02d:%.02d:%.02d.000", tickTime.year, tickTime.mon, tickTime.day,
                                                                                                      tickTime.hour, tickTime.min, tickTime.sec),
                                              tick[i].bid,
                                              tick[i].ask,
                                              tick[i].last,
                                              tick[i].volume,
                                              ((tick[i].flags & TICK_FLAG_BUY) ? "Buy" : "") + 
                                              ((tick[i].flags & TICK_FLAG_SELL) ? "Sell" : ""));
               }
               
               FileClose(nTicksOutputFile);
            }
            /////////////////////////////////////////////////////////                                        
                                        
            g_dDayBegin = dCurrent;                                   
         }
         else
         {
            FileWrite(nDebugOutputFile, StringFormat("%.04d.%.02d.%.02d %.02d:%.02d:%.02d.000", dayBegin.year, dayBegin.mon, dayBegin.day,
                                                                                                dayBegin.hour, dayBegin.min, dayBegin.sec),
                                        StringFormat("%.04d.%.02d.%.02d %.02d:%.02d:%.02d.000", dayEnd.year, dayEnd.mon, dayEnd.day,
                                                                                                dayEnd.hour, dayEnd.min, dayEnd.sec),
                                        StringFormat("%.04d.%.02d.%.02d %.02d:%.02d:%.02d.000", curTime.year, curTime.mon, curTime.day,
                                                                                                curTime.hour, curTime.min, curTime.sec),
                                        "No ticks",
                                        ArraySize(tick),
                                        nResult,
                                        nLastError);
               
         }
         FileClose(nDebugOutputFile);
      }
   }
}

Files:
backup.01.zip  292 kb
backup.02.zip  271 kb
 
antru:

Folks, how do you get the feed in real time?

Forum on trading, automated trading systems and trading strategy testing

Mysterious stock indicator

fxsaber, 2016.10.04 11:28

long LastTime = 0; // time_msc-время последнего тика (самого свежего), полученного из истории
int Count = 0;     // Количество тиков в последенем запросе, у которых time_msc == LastTime

// Возвращает свежие тики, пришедшие после предыдущего вызова
int GetFreshTicks( MqlTick &Ticks[], const uint flags = COPY_TICKS_TRADE, const uint count = 100000 )
{
  int Res = 0;

  MqlTick NewTicks[];
  const int NewAmount = CopyTicks(Symbol(), NewTicks, flags, LastTime, count);

  if ((NewAmount > 0) && (Count < NewAmount))
  {
    Res = ArrayCopy(Ticks, NewTicks, 0, Count);

    // Взяли крайнее время из текущей истории
    LastTime = NewTicks[NewAmount - 1].time_msc;
    Count = 1;

    // Находим (Count) в текущей истории количество тиков со временем LastTime
    for (int i = NewAmount - 2; i >= 0; i--)
    {
      if (NewTicks[i].time_msc < LastTime)
        break;

      Count++;
    }
  }

  return(Res);
}
 
fxsaber:

For some reason, the ticks for the current day are no longer displayed at all, both according to the old algorithm and the new one... and regardless of whether the ribbon is enabled in the window or not...

here's the code where I inserted your function...

//+------------------------------------------------------------------+
//|                                                     Smelchak.mq5 |
//|                                                      Pavel&Antru |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Pavel&Antru"
#property link      ""
#property version   "1.00"

bool g_bEnterInfoSent = false;

datetime g_dEndOfTheDay;
datetime g_dDayBegin;

long LastTime = 0; // time_msc-время последнего тика (самого свежего), полученного из истории
int Count = 0;     // Количество тиков в последенем запросе, у которых time_msc == LastTime

// Возвращает свежие тики, пришедшие после предыдущего вызова
int GetFreshTicks( MqlTick &Ticks[], const uint flags = COPY_TICKS_TRADE, const uint count = 100000 )
{
  int Res = 0;

  MqlTick NewTicks[];
  const int NewAmount = CopyTicks(Symbol(), NewTicks, flags, LastTime, count);

  if ((NewAmount > 0) && (Count < NewAmount))
  {
    Res = ArrayCopy(Ticks, NewTicks, 0, Count);

    // Взяли крайнее время из текущей истории
    LastTime = NewTicks[NewAmount - 1].time_msc;
    Count = 1;

    // Находим (Count) в текущей истории количество тиков со временем LastTime
    for (int i = NewAmount - 2; i >= 0; i--)
    {
      if (NewTicks[i].time_msc < LastTime)
        break;

      Count++;
    }
  }

  return(Res);
}
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
   EventSetTimer(3);
   
   MqlDateTime startTime;
   TimeGMT(startTime);
   startTime.hour = 7;
   startTime.min = 0;
   startTime.sec = 0;
   g_dDayBegin = StructToTime(startTime);
   
   startTime.hour = 17;
   startTime.min = 0;
   startTime.sec = 0;
   g_dEndOfTheDay = StructToTime(startTime);
   
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
}
//+------------------------------------------------------------------+

void OnTimer()
{
   MqlDateTime mdt;
   datetime dCurrent = TimeCurrent(mdt);
   
   if (!g_bEnterInfoSent && mdt.hour + 3 == 9)
   {
      MqlDateTime startTime;
      TimeGMT(startTime);
      startTime.hour = 7;
      startTime.min = 0;
      startTime.sec = 0;
      g_dDayBegin = StructToTime(startTime);
      
      startTime.hour = 17;
      startTime.min = 0;
      startTime.sec = 0;
      g_dEndOfTheDay = StructToTime(startTime);

      g_bEnterInfoSent = true;
   }
   
   if (g_bEnterInfoSent && mdt.hour + 3 == 22)
   {
      g_bEnterInfoSent = false;
   }
   
   datetime lastTime = TimeCurrent();
   
   if (true)
   {
      MqlTick tick[];
      int nResult = GetFreshTicks(tick);
      
      MqlDateTime tickTime;
      
      if (ArraySize(tick))
      {
         TimeToStruct(tick[0].time, tickTime);
         
         string sTicksFileName = StringFormat("%s.ticks.%.04d.%.02d.%.02d.csv", Symbol(), tickTime.year, tickTime.mon, tickTime.day);
      
         int nTicksOutputFile = FileOpen(sTicksFileName, FILE_READ | FILE_WRITE | FILE_CSV, ',');
         if (nTicksOutputFile == INVALID_HANDLE) nTicksOutputFile = FileOpen(sTicksFileName, FILE_WRITE | FILE_CSV, ',');
         
         if (nTicksOutputFile != INVALID_HANDLE)
         {
            FileSeek(nTicksOutputFile, 0, SEEK_END);
   
            MqlDateTime tickTime;
         
            for (int i = 0; i<ArraySize(tick); i++)
            {
               TimeToStruct(tick[i].time, tickTime);
               
               FileWrite(nTicksOutputFile, StringFormat("%.04d.%.02d.%.02d %.02d:%.02d:%.02d.000", tickTime.year, tickTime.mon, tickTime.day,
                                                                                                   tickTime.hour, tickTime.min, tickTime.sec),
                                           tick[i].bid,
                                           tick[i].ask,
                                           tick[i].last,
                                           tick[i].volume,
                                           ((tick[i].flags & TICK_FLAG_BUY) ? "Buy" : "") + 
                                           ((tick[i].flags & TICK_FLAG_SELL) ? "Sell" : ""));
            }
            
            FileClose(nTicksOutputFile);
         }
                                     
         g_dDayBegin = dCurrent;                                   
      }
   }
}

As a result, I ran it on two papers, ALRS and AFLT. The ticks only came back for the previous days. None for today. What could be the problem?

Files:
Files.zip  843 kb
 
antru:

For some reason, the ticks for the current day are no longer displayed at all, both according to the old algorithm and the new one... and regardless of whether the ribbon is enabled in the window or not...

here's the code where I inserted your function...

As a result, I ran it on two papers, ALRS and AFLT. The ticks only came back for the previous days. None for today. What could it be?

There are ticks in the windows in the ribbon, I save 100000 last ticks - no ticks for today

Files:
Documents.zip  812 kb
 
But now the tics have appeared. What could it be? Whose fault is it? The broker? Metatrader?