CopyTicksRange () does not work correctly in MQL5. a

 

I'm trying to get the marks for different times. I've been using the CopyTicksRange () function. It used to work fine.

But it suddenly stopped working. I am very disappointed with this behavior of the function.

Please explain me why this is happening? What is the best way to get ticks using Time range with guarantee?

I tried to call this function several times because I thought it takes time to load Ticks data. But all the times I tried, the length of the copied ticks was -1.

Please let me know what I can do.

I have set Tools -> Option -> Charts -> Maximum number of columns in chart to Unlimited. I tried the following code:

 int len = CopyTicksRange(Orig_Symbol_Name, ticks_add, COPY_TICKS_ALL, ulong(CURRENT_TIME)*1000, ulong(TimeCurrent() + 60) * 1000);

   if(len<=0)
     {
      string error;
      if(GetLastError() == 4401)
         error = "ERR_HISTORY_NOT_FOUND";
      else
         error = string(GetLastError());
      Print("------------------------------------------------------------------");
      Print("History Tick Length: ", len, " Error: ", error);
      Print("------------------------------------------------------------------");
      return -1;
     }
 

Do you call this code where? In what type of programme?

Where are the variable initialisations?

Where is the full MQ5 code as a file - so it can be compiled and run?

 

An example script is provided in the CopyTicks help

Cold start:

Magazine

 2021.01 . 18 09 : 59 : 17.367 Scripts script Generator Magic Number (GBPUSD,H1) loaded successfully
2021.01 . 18 09 : 59 : 17.380 Scripts script Generator Magic Number (GBPUSD,H1) removed
2021.01 . 18 11 : 47 : 13.249 Scripts script CopyTicks (EURUSD,H1) loaded successfully
2021.01 . 18 11 : 49 : 18.826 Scripts script CopyTicks (EURUSD,H1) removed

Experts:

 2021.01 . 18 11 : 49 : 18.580 CopyTicks (EURUSD,H1)   EURUSD: received 100000000 ticks in 27297 ms
2021.01 . 18 11 : 49 : 18.580 CopyTicks (EURUSD,H1)   Last tick time = 2016.02 . 29 09 : 54 : 41.000
2021.01 . 18 11 : 49 : 18.580 CopyTicks (EURUSD,H1)   First tick time = 2011.12 . 19 00 : 00 : 08.000
2021.01 . 18 11 : 49 : 18.580 CopyTicks (EURUSD,H1)   current_time= 2021.01 . 18 11 : 49
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   1 . 2021.01 . 18 00 : 02.617 Ask= 1.20879 Bid= 1.20879 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   2 . 2021.01 . 18 00 : 02.635 Bid= 1.20879 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   3 . 2021.01 . 18 00 : 02.472 Ask= 1.20884 Bid= 1.20884 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   4 . 2021.01 . 18 00 : 03.121 Ask= 1.20859 Bid= 1.20859 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   5 . 2021.01 . 18 00 : 03.218 Bid= 1.20859 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   6 . 2021.01 . 18 00 : 03.878 Ask= 1.20865 Bid= 1.20865 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   7 . 2021.01 . 18 00 : 03.628 Ask= 1.20859 Bid= 1.20859 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   8 . 2021.01 . 18 00 : 03.565 Bid= 1.20859 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   9 . 2021.01 . 18 00 : 03.630 Ask= 1.20866 Bid= 1.20866 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   10 . 2021.01 . 18 00 : 03.819 Bid= 1.20866 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   11 . 2021.01 . 18 00 : 03.313 Ask= 1.20859 Bid= 1.20859 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   12 . 2021.01 . 18 00 : 03.488 Ask= 1.2086 Bid= 1.2086 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   13 . 2021.01 . 18 00 : 03.355 Ask= 1.20865 Bid= 1.20865 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   14 . 2021.01 . 18 00 : 03.105 Ask= 1.20859 Bid= 1.20859 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   15 . 2021.01 . 18 00 : 04.061 Ask= 1.20856 Bid= 1.20856 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   16 . 2021.01 . 18 00 : 04.058 Ask= 1.20853 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   17 . 2021.01 . 18 00 : 04.062 Ask= 1.20852 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   18 . 2021.01 . 18 00 : 04.056 Bid= 1.20852 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   19 . 2021.01 . 18 00 : 04.056 Ask= 1.20853 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   20 . 2021.01 . 18 00 : 04.064 Bid= 1.20853 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   21 . 2021.01 . 18 00 : 04.058 Bid= 1.20853 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   22 . 2021.01 . 18 00 : 04.715 Ask= 1.20844 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   23 . 2021.01 . 18 00 : 04.063 Bid= 1.20844 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   24 . 2021.01 . 18 00 : 04.878 Ask= 1.20849 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   25 . 2021.01 . 18 00 : 04.034 Ask= 1.20844 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   26 . 2021.01 . 18 00 : 04.455 Ask= 1.20838 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   27 . 2021.01 . 18 00 : 05.296 Ask= 1.20837 Bid= 1.20837 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   28 . 2021.01 . 18 00 : 05.354 Ask= 1.20809 Bid= 1.20809 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   29 . 2021.01 . 18 00 : 05.464 Ask= 1.20875 Bid= 1.20875 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   30 . 2021.01 . 18 00 : 05.471 Ask= 1.20822 Bid= 1.20822 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   31 . 2021.01 . 18 00 : 05.383 Ask= 1.20818 Bid= 1.20818 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   32 . 2021.01 . 18 00 : 05.207 Ask= 1.2082 Bid= 1.2082 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   33 . 2021.01 . 18 00 : 05.913 Ask= 1.20818 Bid= 1.20818 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   34 . 2021.01 . 18 00 : 05.446 Ask= 1.20816 Bid= 1.20816 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   35 . 2021.01 . 18 00 : 05.450 Ask= 1.20818 Bid= 1.20818 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   36 . 2021.01 . 18 00 : 05.583 Ask= 1.20816 Bid= 1.20816 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   37 . 2021.01 . 18 00 : 05.478 Ask= 1.20818 Bid= 1.20818 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   38 . 2021.01 . 18 00 : 06.473 Ask= 1.2082 Bid= 1.2082 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   39 . 2021.01 . 18 00 : 06.024 Ask= 1.20819 Bid= 1.20819 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   40 . 2021.01 . 18 00 : 06.752 Ask= 1.20816 Bid= 1.20816 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   41 . 2021.01 . 18 00 : 06.752 Ask= 1.20815 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   42 . 2021.01 . 18 00 : 06.752 Ask= 1.20816 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   43 . 2021.01 . 18 00 : 06.752 Ask= 1.20815 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   44 . 2021.01 . 18 00 : 06.420 Ask= 1.2083 Bid= 1.2083 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   45 . 2021.01 . 18 00 : 06.527 Ask= 1.20829 Bid= 1.20829 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   46 . 2021.01 . 18 00 : 06.085 Ask= 1.20823 Bid= 1.20823 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   47 . 2021.01 . 18 00 : 06.485 Ask= 1.20824 Bid= 1.20824 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   48 . 2021.01 . 18 00 : 06.520 Ask= 1.20823 Bid= 1.20823 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   49 . 2021.01 . 18 00 : 06.099 Ask= 1.20824 Bid= 1.20824 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   50 . 2021.01 . 18 00 : 06.407 Ask= 1.20825 Bid= 1.20825 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   51 . 2021.01 . 18 00 : 06.506 Ask= 1.20824 Bid= 1.20824 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   52 . 2021.01 . 18 00 : 06.840 Ask= 1.20825 Bid= 1.20825 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   53 . 2021.01 . 18 00 : 06.799 Ask= 1.20824 Bid= 1.20824 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   54 . 2021.01 . 18 00 : 06.123 Ask= 1.20825 Bid= 1.20825 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   55 . 2021.01 . 18 00 : 06.572 Ask= 1.20824 Bid= 1.20824 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   56 . 2021.01 . 18 00 : 06.657 Ask= 1.20823 Bid= 1.20823 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   57 . 2021.01 . 18 00 : 06.144 Ask= 1.20824 Bid= 1.20824 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   58 . 2021.01 . 18 00 : 06.589 Ask= 1.20823 Bid= 1.20823 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   59 . 2021.01 . 18 00 : 06.096 Ask= 1.20822 Bid= 1.20822 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   60 . 2021.01 . 18 00 : 06.126 Ask= 1.20823 Bid= 1.20823 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   61 . 2021.01 . 18 00 : 07.266 Ask= 1.20817 Bid= 1.20817 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   62 . 2021.01 . 18 00 : 07.390 Ask= 1.20816 Bid= 1.20816 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   63 . 2021.01 . 18 00 : 07.666 Ask= 1.20817 Bid= 1.20817 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   64 . 2021.01 . 18 00 : 07.816 Ask= 1.20824 Bid= 1.20824 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   65 . 2021.01 . 18 00 : 07.124 Ask= 1.20828 Bid= 1.20828 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   66 . 2021.01 . 18 00 : 07.100 Bid= 1.20828 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   67 . 2021.01 . 18 00 : 07.163 Ask= 1.20827 Bid= 1.20827 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   68 . 2021.01 . 18 00 : 07.719 Ask= 1.20822 Bid= 1.20822 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   69 . 2021.01 . 18 00 : 07.342 Ask= 1.2082 Bid= 1.2082 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   70 . 2021.01 . 18 00 : 07.464 Ask= 1.20823 Bid= 1.20823 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   71 . 2021.01 . 18 00 : 08.728 Ask= 1.2082 Bid= 1.2082 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   72 . 2021.01 . 18 00 : 08.826 Ask= 1.20818 Bid= 1.20818 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   73 . 2021.01 . 18 00 : 08.510 Ask= 1.2082 Bid= 1.2082 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   74 . 2021.01 . 18 00 : 08.172 Ask= 1.20813 Bid= 1.20813 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   75 . 2021.01 . 18 00 : 08.918 Ask= 1.20817 Bid= 1.20817 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   76 . 2021.01 . 18 00 : 08.051 Ask= 1.20814 Bid= 1.20814 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   77 . 2021.01 . 18 00 : 08.527 Ask= 1.20808 Bid= 1.20808 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   78 . 2021.01 . 18 00 : 08.970 Ask= 1.20811 Bid= 1.20811 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   79 . 2021.01 . 18 00 : 08.594 Ask= 1.20814 Bid= 1.20814 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   80 . 2021.01 . 18 00 : 09.525 Bid= 1.20814 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   81 . 2021.01 . 18 00 : 09.118 Ask= 1.20817 Bid= 1.20817 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   82 . 2021.01 . 18 00 : 09.405 Ask= 1.20803 Bid= 1.20803 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   83 . 2021.01 . 18 00 : 09.745 Bid= 1.20803 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   84 . 2021.01 . 18 00 : 09.491 Ask= 1.20813 Bid= 1.20813 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   85 . 2021.01 . 18 00 : 09.582 Ask= 1.20812 Bid= 1.20812 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   86 . 2021.01 . 18 00 : 10.826 Bid= 1.20812 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   87 . 2021.01 . 18 00 : 10.328 Ask= 1.20797 Bid= 1.20797 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   88 . 2021.01 . 18 00 : 10.451 Bid= 1.20797 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   89 . 2021.01 . 18 00 : 10.559 Ask= 1.208 Bid= 1.208 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   90 . 2021.01 . 18 00 : 10.684 Ask= 1.20801 Bid= 1.20801 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   91 . 2021.01 . 18 00 : 10.412 Ask= 1.208 Bid= 1.208 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   92 . 2021.01 . 18 00 : 10.964 Ask= 1.2081 Bid= 1.2081 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   93 . 2021.01 . 18 00 : 10.228 Ask= 1.20805 Bid= 1.20805 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   94 . 2021.01 . 18 00 : 10.668 Ask= 1.20803 Bid= 1.20803 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   95 . 2021.01 . 18 00 : 10.668 Bid= 1.20803 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   96 . 2021.01 . 18 00 : 10.675 Bid= 1.20803 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   97 . 2021.01 . 18 00 : 10.675 Bid= 1.20803 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   98 . 2021.01 . 18 00 : 11.068 Ask= 1.20805 Bid= 1.20805 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   99 . 2021.01 . 18 00 : 11.068 Ask= 1.20804 (Info tick)
2021.01 . 18 11 : 49 : 18.581 CopyTicks (EURUSD,H1)   100 . 2021.01 . 18 00 : 11.497 Ask= 1.20801 (Info tick)

Документация по MQL5: Доступ к таймсериям и индикаторам / CopyTicks
Документация по MQL5: Доступ к таймсериям и индикаторам / CopyTicks
  • www.mql5.com
CopyTicks - Доступ к таймсериям и индикаторам - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
jaffer wilson:

I'm trying to get the marks for different times. I've been using the CopyTicksRange () function. It used to work fine.

But it suddenly stopped working. I am very disappointed with this behavior of the function.

Please explain me why this is happening? What is the best way to get ticks using Time range with guarantee?

I tried to call this function several times because I thought it takes time to load Ticks data. But all the times I tried, the length of the copied ticks was -1.

Please let me know what I can do.

I have set Tools -> Option -> Charts -> Maximum number of columns in chart to Unlimited. I tried the following code:

ulong(TimeCurrent() + 60) * 1000 is time in the future. There are no ticks there yet. You do not know what time you are trying to get the ticks from. Try to put it like this

int len = CopyTicksRange(Orig_Symbol_Name, ticks_add, COPY_TICKS_ALL, ulong(TimeCurrent() - 60)*1000, ulong(TimeCurrent()) * 1000);

It will be the ticks for the last 60 seconds

 
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 0
bool terminal_connected, Filled_Complete;
input int GO_BACK_HISTORY_LOAD = 30;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   string name = MQLInfoString(MQL_PROGRAM_NAME);
   IndicatorSetString(INDICATOR_SHORTNAME, name);
   terminal_connected = (bool)TerminalInfoInteger(TERMINAL_CONNECTED);
   ResetLastError();
   Filled_Complete = true;

   if(Fill_Ticks_Symbol(Symbol()) < 0)
     {
      Filled_Complete = false;
     }
   EventSetMillisecondTimer(100);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   EventKillTimer();
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
   if(terminal_connected == false || Filled_Complete == false)
     {
      if(Fill_Ticks_Symbol(Symbol()) > 0)
        {
         Filled_Complete = true;
        }
      if(TerminalInfoInteger(TERMINAL_CONNECTED) == true)
         terminal_connected = true;
     }

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTimer()
  {
   if(TerminalInfoInteger(TERMINAL_CONNECTED) == false)
      terminal_connected = false;
  }

//+------------------------------------------------------------------+
int Fill_Ticks_Symbol(string Orig_Symbol_Name)
  {
   MqlDateTime str;
   TimeToStruct(iTime(Orig_Symbol_Name, 0, 0) - GO_BACK_HISTORY_LOAD * 86400, str);
   Comment("");
   datetime start_date = datetime(StringFormat("%d.%d.01 00:00:00",str.year,str.mon));
   MqlTick ticks_add[];

   ulong time_start = GetMicrosecondCount();
//int len = CopyTicksRange(Orig_Symbol_Name, ticks_add, COPY_TICKS_ALL, ulong(start_date)*1000, ulong(TimeCurrent())*1000);

   Print("Gathering Ticks from : ", iTime(Orig_Symbol_Name, 0, 0) - GO_BACK_HISTORY_LOAD * 86400, " To: ", TimeCurrent());

   int len = CopyTicksRange(Orig_Symbol_Name, ticks_add, COPY_TICKS_ALL, ulong(start_date)*1000, ulong(TimeCurrent() + 60) * 1000);
   int count = 0;
   while(len<=0 && count<5 && !IsStopped())
     {
      Sleep(100);
      len = CopyTicksRange(Orig_Symbol_Name, ticks_add, COPY_TICKS_ALL, ulong(start_date)*1000, ulong(TimeCurrent() + 60) * 1000);
      count++;
     }
   if(len<=0)
     {
      Print("The History Len was found to be : ", len);
      return -1;
     }
   Print("Started : ",ticks_add[0].time,"  Ended : ",ticks_add[len-1].time);
   return len;
  }
//+------------------------------------------------------------------+

I won't be able to share the full code, but here's a small example I used.

 
Could you suggest me now? I have tried the example above. Sometimes it works. But not always.
 
jaffer wilson:
Could you suggest it to me now? I have tried the example above. Sometimes it works. But not always.

Try this option

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
   if(rates_total == 0)
     {
      if(Fill_Ticks_Symbol(Symbol()) <= 0)
        return 0;
     }

//--- return value of prev_calculated for next call
   return(rates_total);
  }
This way the indicator will wait for the ticks to load.
 
Alexey Viktorov :

Try this option.

This way the indicator will wait for the ticks to load.

I don't think there will be any difference. Because the problem is with the MQL5 function, not the one I created.

 
jaffer wilson:

I don't think there will be any difference. Because the problem is with the MQL5 function, not the one I created.

This is not the first time you've expressed an unverified opinion. What prevents you from checking?

Try to count how many mql5 programmers are working with CopyTicksRange() function and no one has problems. You are the only one, you are the only one who has such behavior of the function.

 
Alexey Viktorov #:

This is not the first time you have given an unverified opinion. What prevents you from checking?

Try to count how many mql5 programmers are working with the CopyTicksRange() function and no one has problems. You're the only one who has such behavior of the function.


A very bold statement, Alexey.


I work with CopyTicksRange() function and it constantly works incorrectly. To make it work properly, I have to adjust input parameters so that it gives a sensible result. I have been using this function for two years and keep finding new glitches. Support keeps ignoring all the questions about this function. Most likely they are too lazy to do it, as there is one glitch after another.

As an example, what this function can do unexpectedly:


1) return the ticks not included into requested range

2) return all the ticks of the current bar instead of the requested part of this bar

3) return the rubbish, i.e. it is not clear what ticks are returned

4) to skip a part of ticks


The best thing was an advice of someone from support to make crutches - i.e. if I know in which situations a function glitches, I should reword the request so that it wouldn't glitch. I've been doing that ever since :)


Here's yesterday's example, against which I'm now looking for a crutch:


MqlTick Ticks[1000000];

int AddTicks(ulong tFrom_msc,ulong tTo_msc,ulong &lt)
{

   int  received=CopyTicksRange("@BR",Ticks,COPY_TICKS_ALL,tFrom_msc,tTo_msc);
   
   PrintFormat("CopyTicksRange:  %s:%d - %s:%d  received %d",TimeToString(tFrom_msc/1000),tFrom_msc%1000,TimeToString(tTo_msc/1000),tTo_msc%1000,received);
   
   if(received>0)
   {
       PrintFormat("%s:%d - first tick, %s:%d - last tick", 
                              TimeToString(Ticks[0].time_msc/1000),           Ticks[0].time_msc%1000, 
                              TimeToString(Ticks[received-1].time_msc/1000),  Ticks[received-1].time_msc%1000
                              );
                              
       lt= Ticks[received-1].time_msc ;                   
   }
   return received;
}

And here's the crutch:

2021.09.18 18:10:26.541 TesterEx ($BR,H1)       CopyTicksRange:  2021.01.29 23:56:864 - 2021.01.31 23:59:999  received 109425
2021.09.18 18:10:26.541 TesterEx ($BR,H1)       2021.01.29 00:02:782 - first tick, 2021.01.29 23:56:863 - last tick

I.e. function, used by thousands of programmers, personally returned to me all ticks from the beginning of the current bar, but not included into requested range

 
RusPro #:


That's a very bold statement, Alexey.


I'm working with CopyTicksRange() function and it's not working correctly all the time. To make it work properly, I have to adjust input parameters so that it gives a sensible result. I have been using this function for two years and keep finding new glitches. Support keeps ignoring all the questions about this function. Most likely they are too lazy to do it, as there is one glitch after another.

As an example, what this function can do unexpectedly:


1) return the ticks not included into requested range

2) return all the ticks of the current bar instead of the requested part of this bar

3) return the rubbish, i.e. it is not clear what ticks are returned

4) to skip a part of ticks


The best thing was an advice of someone from support to make crutches - i.e. if I know in which situations a function glitches, I should reword the request so that it wouldn't glitch. I've been doing that ever since :)

I highlighted the keywords.

Do NOT request ticks that don't already exist by definition. If you request ticks even one millisecond beyond current time in milliseconds, you will get the very g.........y in the form of your problems.

Reason: