CopyTicksRange() in strategy tester

 

I have an EA which makes decisions based on several diferent symbols. The primary symbol the EA is attached to is EURUSD, but it uses tick data from EURCHF. USDJPY, XAUUSD,... 

I use CopyTicksRange() to get data from other symbols. And this works fine when trading live. However when I attempt to use this in the Strategy Tester it fails for the secondary symbols. 

Is this a limitation of Metatrader? I.e., is it not possible to test a strategy that relies upon tick data from other symbols? Or am I missing something.

Thanks in advance!

 
Yes, it's possible to test a multisymbol strategy by ticks. You need to be more specific about what's going wrong in your case, probably provide a test case. Make sure that you're using the model by real ticks in the tester settings, and the required tick history is available (for all symbols used).
 
Stanislav Korotky #:
Yes, it's possible to test a multisymbol strategy by ticks. You need to be more specific about what's going wrong in your case, probably provide a test case. Make sure that you're using the model by real ticks in the tester settings, and the required tick history is available (for all symbols used).

Ok great. Thanks for the quick response.

The EA works fine when live (on a demo account). However when I attempt to backtest it fails. I am using the “Every tick based on real ticks” option and the Symbol chosen is the one I am trading on (EURUSD).

The EA uses CopyTicksRange to load 220 minutes of tick history for 7 symbols (EURUSD_SB, USDJPY_SB, GBPUSD_SB, EURCHF_SB, USDCAD_SB, XAUUSD_SB, XAGUSD_SB) on every tick (I use a UK based spreadbetting company, hence the “_SB” suffix). In the Strategy Tester, CopyTicksRange returns <= 0 for all secondary symbols (everything except the chart symbol EURUSD_SB).

The relevant section of RefreshTickData is:

for(int i = 0; i < N_SYMBOLS; i++)
   {
       MqlTick tempTicks[];
       int n = CopyTicksRange(Symbols[i], tempTicks, COPY_TICKS_ALL,
                              loadFromMs, anchorMs);
       if(n <= 0)
       {
           Print("CopyTicksRange returned ", n, " for ", Symbols[i]);
           return false;
       }
       // ... age and lag checks follow
   }

Crucially, when I the backtester, the marketwatch window on the left is populated with symbol names but the bid/ask are blank for all symbols besides EURUSD_SB (apologies I cannot work out how to paste an image of this).


My concerns / questions:

1. Does CopyTicksRange for non-chart symbols work in the Strategy Tester, or is there a different function I should use?

2. Is there anything required beyond SymbolSelect(symbol, true) in OnInit to make secondary symbol tick data available in the tester?

 
johnboy85 #:

My concerns / questions:

1. Does CopyTicksRange for non-chart symbols work in the Strategy Tester, or is there a different function I should use?

2. Is there anything required beyond SymbolSelect(symbol, true) in OnInit to make secondary symbol tick data available in the tester?

CopyTicksRange works ok both online and in the tester.

Instead (or in addition to SymbolSelect) call iClose(Symbols[i], _Period, 0) once in OnInit.

If you still get errors check _LastError just after CopyTicksRange - this will give you a specific identificator of the error, for example, some of the symbols may have different trade shedule, hence ticks may be unavailble for specific hours.

 
johnboy85 #:

Ok great. Thanks for the quick response.

The EA works fine when live (on a demo account). However when I attempt to backtest it fails. I am using the “Every tick based on real ticks” option and the Symbol chosen is the one I am trading on (EURUSD).

The EA uses CopyTicksRange to load 220 minutes of tick history for 7 symbols (EURUSD_SB, USDJPY_SB, GBPUSD_SB, EURCHF_SB, USDCAD_SB, XAUUSD_SB, XAGUSD_SB) on every tick (I use a UK based spreadbetting company, hence the “_SB” suffix). In the Strategy Tester, CopyTicksRange returns <= 0 for all secondary symbols (everything except the chart symbol EURUSD_SB).

The relevant section of RefreshTickData is:

Crucially, when I the backtester, the marketwatch window on the left is populated with symbol names but the bid/ask are blank for all symbols besides EURUSD_SB (apologies I cannot work out how to paste an image of this).


My concerns / questions:

1. Does CopyTicksRange for non-chart symbols work in the Strategy Tester, or is there a different function I should use?

2. Is there anything required beyond SymbolSelect(symbol, true) in OnInit to make secondary symbol tick data available in the tester?

Please provide the Tester log file.
 
Stanislav Korotky #:

CopyTicksRange works ok both online and in the tester.

Instead (or in addition to SymbolSelect) call iClose(Symbols[i], _Period, 0) once in OnInit.

If you still get errors check _LastError just after CopyTicksRange - this will give you a specific identificator of the error, for example, some of the symbols may have different trade shedule, hence ticks may be unavailble for specific hours.

Thanks very much indeed. Adding iClose(Symbols[i], _Period, 0) in OnInit immediately after each SymbolSelect call fixed the issue completely. All secondary symbols now show populated bid/ask in the visualiser and CopyTicksRange returns data correctly for all of them.

For anyone finding this thread later: SymbolSelect alone is not sufficient to trigger tick history synchronisation for non-chart symbols in the Strategy Tester. The iClose call forces MT5 to synchronise the price series for that symbol, which as a side effect ensures tick history is available before the EA starts receiving ticks.

Thanks again for the quick and precise answer!
 
Alain Verleyen #:
Please provide the Tester log file.

I have now solved the issue (thanks to Stanislav Korotky) but I have pasted the original log file (before applied fix) for completeness.


CS 0 11:19:55.156 Startup MetaTester 5 build 5660, 27 Feb 2026

CS 0 11:19:55.157 Startup Windows 11 build 26100, 4 x Intel Core i5-7500T  @ 2.70GHz, AVX2, 11 / 15 Gb memory, 106 / 446 Gb disk, UAC, GMT+0

CS 0 11:19:55.160 Server MetaTester 5 started on 127.0.0.1:3000

CS 0 11:19:55.166 Startup cloud network mode is off

CS 0 11:19:55.166 Startup initialization finished

CS 0 11:19:55.329 127.0.0.1 login (build 5660)

CS 0 11:19:55.538 Network 11604 bytes of account info loaded

CS 0 11:19:55.538 Network 1478 bytes of tester parameters loaded

CS 0 11:19:55.538 Network 8900 bytes of input parameters loaded

CS 0 11:19:55.541 Network 15798 bytes of symbols list loaded (1660 symbols)

CS 0 11:19:55.541 Tester expert file added: Experts\Model7Tester.ex5. 68770 bytes loaded

CS 0 11:19:55.559 Tester 11912 Mb available, 148 blocks set for ticks generating

CS 0 11:19:55.559 Tester initial deposit 10000.00 GBP, leverage 1:30

CS 0 11:19:55.559 Tester successfully initialized

CS 0 11:19:55.559 Network 79 Kb of total initialization data received

CS 0 11:19:55.559 Tester Intel Core i5-7500T  @ 2.70GHz, 16267 MB

CS 0 11:19:55.587 Symbols EURUSD_SB: symbol to be synchronized

CS 0 11:19:55.588 Symbols EURUSD_SB: symbol synchronized, 3720 bytes of symbol info received

CS 0 11:19:55.591 History EURUSD_SB: history synchronization started

CS 0 11:19:55.596 History EURUSD_SB: load 33 bytes of history data to synchronize in 0:00:00.002

CS 0 11:19:55.596 History EURUSD_SB: history synchronized from 2002.01.01 to 2025.12.31

CS 0 11:19:55.600 Ticks EURUSD_SB: ticks synchronization started

CS 0 11:19:55.601 Ticks EURUSD_SB: load 40 bytes of tick data to synchronize in 0:00:00.000

CS 0 11:19:55.601 Ticks EURUSD_SB: history ticks synchronized from 2023.04.03 to 2025.12.30

CS 0 11:19:55.655 History EURUSD_SB,M1: history cache allocated for 749568 bars and contains 372058 bars from 2023.01.02 01:04 to 2023.12.29 23:25

CS 0 11:19:55.655 History EURUSD_SB,M1: history begins from 2023.01.02 01:04

CS 0 11:19:55.679 Tester EURUSD_SB,M1 (PepperstoneUK-Demo): generating based on real ticks

CS 0 11:19:55.679 Tester EURUSD_SB,M1: testing of Experts\Model7Tester.ex5 from 2024.01.01 00:00 to 2024.12.31 00:00 started with inputs:

CS 0 11:19:55.679 Tester   ModelFileName=model7_EURUSD.cbm

CS 0 11:19:55.679 Tester   EntryThreshold=0.3

CS 0 11:19:55.679 Tester   EntryMaxSignal=2.0

CS 0 11:19:55.679 Tester   ExitThreshold=0.15

CS 0 11:19:55.679 Tester   FlipThreshold=0.3

CS 0 11:19:55.679 Tester   MinHoldSeconds=60

CS 0 11:19:55.679 Tester   MaxDurationSeconds=1800

CS 0 11:19:55.679 Tester   BaseLotSize=0.01

CS 0 11:19:55.679 Tester   MaxLotSize=0.1

CS 0 11:19:55.679 Tester   MaxSignal=1.0

CS 0 11:19:55.679 Tester   StopLossATRMult=2.0

CS 0 11:19:55.679 Tester   EmergencyStopATRMult=10.0

CS 0 11:19:55.679 Tester   TakeProfitBP=10.0

CS 0 11:19:55.679 Tester   TrailingStopBP=3.0

CS 0 11:19:55.679 Tester   SessionStartUTC=60

CS 0 11:19:55.679 Tester   SessionEndUTC=1200

CS 0 11:19:55.679 Tester   TradeComment=Model7

CS 0 11:19:55.701 Model7Tester (EURUSD_SB,M1) 2024.01.01 00:00:00   Model loaded: C:\Program Files\MetaTrader 5\model7_EURUSD.cbm

CS 0 11:19:55.701 Symbols USDJPY_SB: symbol to be synchronized

CS 0 11:19:55.702 Symbols USDJPY_SB: symbol synchronized, 3720 bytes of symbol info received

CS 0 11:19:55.702 Symbols GBPUSD_SB: symbol to be synchronized

CS 0 11:19:55.703 Symbols GBPUSD_SB: symbol synchronized, 3720 bytes of symbol info received

CS 0 11:19:55.703 Symbols EURCHF_SB: symbol to be synchronized

CS 0 11:19:55.703 Symbols EURCHF_SB: symbol synchronized, 3720 bytes of symbol info received

CS 0 11:19:55.703 Symbols USDCAD_SB: symbol to be synchronized

CS 0 11:19:55.704 Symbols USDCAD_SB: symbol synchronized, 3720 bytes of symbol info received

CS 0 11:19:55.704 Symbols XAUUSD_SB: symbol to be synchronized

CS 0 11:19:55.704 Symbols XAUUSD_SB: symbol synchronized, 3720 bytes of symbol info received

CS 0 11:19:55.704 Symbols XAGUSD_SB: symbol to be synchronized

CS 0 11:19:55.704 Symbols XAGUSD_SB: symbol synchronized, 3720 bytes of symbol info received

CS 0 11:19:55.712 Model7Tester (EURUSD_SB,M1) 2024.01.01 00:00:00   Model7 EA initialised. Waiting for data...

CS 3 11:19:56.598 Ticks EURUSD_SB : 2024.04.29 23:59 - real ticks absent for 1 minutes out of 1320 total minute bars within a day

CS 3 11:19:56.598 Ticks EURUSD_SB : 2024.04.29 23:59 - real ticks discarded for 1318 minutes out of 1320 total minute bars within a day

CS 3 11:19:56.598 Ticks EURUSD_SB : 2024.04.29 23:59 - 99916 tick prices mismatch for 1318 minute bars

CS 3 11:19:56.696 Ticks EURUSD_SB : 2024.05.14 23:59 - real ticks absent for 630 minutes out of 1438 total minute bars within a day

CS 3 11:19:56.696 Ticks EURUSD_SB : 2024.05.14 23:59 - real ticks discarded for 774 minutes out of 1438 total minute bars within a day

CS 3 11:19:56.696 Ticks EURUSD_SB : 2024.05.14 23:59 - 174237 tick prices mismatch for 774 minute bars

CS 0 11:19:57.823 Ticks EURUSD_SB : real ticks begin from 2023.04.03 00:00:00

CS 3 11:19:57.823 Ticks EURUSD_SB : 2024.01.01 00:00 - 2024.12.31 00:00  real ticks absent for 631 minutes of 371867 total minute bars, every tick generation used

CS 3 11:19:57.823 Ticks EURUSD_SB : 2024.01.01 00:00 - 2024.12.31 00:00  real ticks discarded for 2092 minutes of 371867 total minute bars, every tick generation used

CS 3 11:19:57.823 Ticks EURUSD_SB : 2024.01.01 00:00 - 2024.12.31 00:00  tick volumes not matched for 2049 minute bars

CS 3 11:19:57.823 Ticks EURUSD_SB : 2024.01.01 00:00 - 2024.12.31 00:00  tick prices of 175555 ticks not matched for 2092 minute bars

CS 3 11:19:57.823 Ticks EURUSD_SB : 2024.01.01 00:00 - 2024.12.31 00:00  last prices absent for 2084 minute bars, bid prices used

CS 0 11:19:57.853 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:01:06   Waiting for sufficient tick history...

CS 0 11:20:03.216 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:02:01   Waiting for sufficient tick history...

CS 0 11:20:03.225 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:02:56   Waiting for sufficient tick history...

CS 0 11:20:03.236 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:03:00   Waiting for sufficient tick history...

CS 0 11:20:03.298 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:04:38   Waiting for sufficient tick history...

CS 0 11:20:03.306 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:05:02   Waiting for sufficient tick history...

CS 0 11:20:03.310 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:05:16   Waiting for sufficient tick history...

CS 0 11:20:03.324 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:06:11   Waiting for sufficient tick history...

CS 0 11:20:03.339 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:06:29   Waiting for sufficient tick history...

CS 0 11:20:03.404 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:07:06   Waiting for sufficient tick history...

CS 0 11:20:03.417 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:08:01   Waiting for sufficient tick history...

CS 0 11:20:03.428 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:09:46   Waiting for sufficient tick history...

CS 0 11:20:03.443 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:10:27   Waiting for sufficient tick history...

CS 0 11:20:03.593 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:10:46   Waiting for sufficient tick history...

CS 0 11:20:03.602 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:11:00   Waiting for sufficient tick history...

CS 0 11:20:03.607 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:12:36   Waiting for sufficient tick history...

CS 0 11:20:03.614 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:13:01   Waiting for sufficient tick history...

CS 0 11:20:03.625 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:14:01   Waiting for sufficient tick history...

CS 0 11:20:03.628 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:14:48   Waiting for sufficient tick history...

CS 0 11:20:03.633 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:15:07   Waiting for sufficient tick history...

CS 0 11:20:03.639 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:15:42   Waiting for sufficient tick history...

CS 0 11:20:03.644 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:16:00   Waiting for sufficient tick history...

CS 0 11:20:03.648 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:16:26   Waiting for sufficient tick history...

CS 0 11:20:03.653 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:17:00   Waiting for sufficient tick history...

CS 3 11:20:04.241 Tester stopped by user

CS 0 11:20:04.241 Model7Tester (EURUSD_SB,M1) 2024.01.02 00:17:00   Waiting for sufficient tick history...

CS 0 11:20:04.242 Tester test Experts\Model7Tester.ex5 on EURUSD_SB,M1 thread finished

CS 0 11:20:04.247 127.0.0.1 prepare for shutdown

CS 0 11:20:04.247 127.0.0.1 shutdown finished


 
johnboy85 #:

I have now solved the issue (thanks to Stanislav Korotky) but I have pasted the original log file (before applied fix) for completeness.

Thanks. I reported this issue as a bug to MetaQuotes.