GetTickCount() in tester? How to inject mili-second delays in tester...

 

As far as I can tell GetTickCount() does not work in Tester (if I'm wrong then PLEASE correct me). So my question is, how can I "inject" a delay into Tester? For example, let's I want a more realistic OrderClose() function - obviously in Live/Demo closing an order takes time - a few 100 mili-seconds. Is there a way to put this delay in the Tester? I've tried using GetTickCount() to do this, but it doesn't seem to work in Tester (and Sleep() doesn't work as mentioned in the documentation). Any way to achieve this?


Anybody know a better source of history data than downloading it from MetaQuotes in History Center (in the MT4 program)...?

 

I'm not sure if that makes sense at all. The backtesting engine doesn't work with tick data. The smallest unit is M1, means you only use 4 "Ticks" each minute. Do you see the problem?

The basic idea however is good. I always "calculate myself poorer" when I'm evaluating the result of a backtest.


You can get great history data from Bloomberg, Reuters and many more.

 
schnappi:

I'm not sure if that makes sense at all. The backtesting engine doesn't work with tick data. The smallest unit is M1, means you only use 4 "Ticks" each minute. Do you see the problem?

The basic idea however is good. I always "calculate myself poorer" when I'm evaluating the result of a backtest.


You can get great history data from Bloomberg, Reuters and many more.

No, that's not accurate. The backtester interpolates M1 data into more data and simulates actual ticks. As proof, try to run this simple expert advisor:

int tick;
datetime time;

int init()
{
tick = 0;
time = TimeCurrent();
}

int start()
{
tick++;
Print("Current price = ", DoubleToStr(Bid,5));

if( TimeMinute(TimeCurrent()) >= TimeMinute(time) )
{
Print( "Number of ticks in minute = ", tick );

tick = 0;
time = TimeLocal();
}
}


All the expert does is count ticks and print current price as proof that price actually changed. It also outputs and resets the tick counter once a minute. Example of output (log file):

10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.39900
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40200
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40100
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40000
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.39900
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40100
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40300
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40600
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40800
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41000
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40900
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40800
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40700
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40900
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41100
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41400
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41600
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41800
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41700
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41600
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41500
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41400
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41300
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41400
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41300
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41500
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41400
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41500
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41300
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41200
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41000
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40900
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40700
10:37:54 2009.05.11 18:59 test USDJPY,M1: Current price = 97.40800
10:37:54 2009.05.11 18:59 test USDJPY,M1: Number of ticks in minute = 2064


You can clearly see that prices change many times within a minute (price change is the definition of a tick, no?) and that the backtester has up to about 3000 ticks per minute (from what I've seen anyway).


Ok, so let's say I want to simulate code that closes all open orders. Let's say we have 10 of those. In Live/Demo, even if we have excelent internet connection, a very fast broker with very fast servers, this would still take at least 1 second to perform; a more realistic figure is ~2-5 seconds. In the backtester this always takes almost zero time. Obviously this is a big difference which would affect simulation accuracy... So how do I "inject" mili-second delays after each close operation into the backtester?

 
gordon:

No, that's not accurate. The backtester interpolates M1 data into more data and simulates actual ticks. As proof, try to run this simple expert advisor:

int tick;
datetime time;

int init()
{
tick = 0;
time = TimeCurrent();
}

int start()
{
tick++;
Print("Current price = ", DoubleToStr(Bid,5));

if( TimeMinute(TimeCurrent()) >= TimeMinute(time) )
{
Print( "Number of ticks in minute = ", tick );

tick = 0;
time = TimeLocal();
}
}


All the expert does is count ticks and print current price as proof that price actually changed. It also outputs and resets the tick counter once a minute. Example of output (log file):

10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.39900
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40200
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40100
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40000
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.39900
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40100
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40300
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40600
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40800
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41000
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40900
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40800
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40700
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40900
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41100
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41400
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41600
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41800
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41700
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41600
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41500
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41400
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41300
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41400
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41300
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41500
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41400
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41500
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41300
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41200
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.41000
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40900
10:37:54 2009.05.11 18:58 test USDJPY,M1: Current price = 97.40700
10:37:54 2009.05.11 18:59 test USDJPY,M1: Current price = 97.40800
10:37:54 2009.05.11 18:59 test USDJPY,M1: Number of ticks in minute = 2064


You can clearly see that prices change many times within a minute (price change is the definition of a tick, no?) and that the backtester has up to about 3000 ticks per minute (from what I've seen anyway).


Ok, so let's say I want to simulate code that closes all open orders. Let's say we have 10 of those. In Live/Demo, even if we have excelent internet connection, a very fast broker with very fast servers, this would still take at least 1 second to perform; a more realistic figure is ~2-5 seconds. In the backtester this always takes almost zero time. Obviously this is a big difference which would affect simulation accuracy... So how do I "inject" mili-second delays after each close operation into the backtester?

Since GetTickTime() doesn't work in the tester you can probably use some useless pice of code like an empty loop or anything else to create a delay.

 
That won't work... On the contrary, u can get the Tester to be "stuck" if u loop in the same tick (the same run of start() ) and never get out of it. I found that out the hard way...
 
gordon:
That won't work... On the contrary, u can get the Tester to be "stuck" if u loop in the same tick (the same run of start() ) and never get out of it. I found that out the hard way...

Interesting comment. Why won't that work?

 
cloudbreaker:

Interesting comment. Why won't that work?

From my experience, no matter how many loops and calculations or how intensive they are, the tester still does them in a single tick. Of course the tester run time would be longer, but the tester still assumes that the calculations are done in a single tick's time (I'm talking about the interpolated ticks...).


Furthermore, if u do a loop that relies on the time passing (for example - if u to tell the tester to wait until TimeCurrent() is some specific time), but u do it WITHOUT exiting start(), then the Tester gets "stuck". Of course in demo/live the same code would work just fine, cause time actually moves, but in the tester time does not exist... There are only interpolated ticks; start() always starts and ends in a single tick. If the code is such that start() doesn't finish (because it relies on time actually passing) then the Tester simply gets "stuck" in that tick.


Anyway, all this is from my experience... But I might be wrong. But back to the subject, so let's say I want to introduce some kind of delay after an operation that in reality takes a relatively long time (for example opening orders, closing, etc.) and in the Tester takes zero time (it's all done in a single tick in the tester anyway) - how do I do it???


Another question - how does the Tester decide how many ticks to interpolate within a single minute? And how is this interpolation done? I've gone through most if not all of the articles about Tester... Problem is they are a poor translation of Russian articles. A lot of what's written there doesn't make sense and generally I find it lacks the technical details I'm looking for.

 

GetTickTime() ? where it is ?

no such function.

the time function in MT now only based on second.

 
DxdCn:

GetTickTime() ? where it is ?

no such function.

the time function in MT now only based on second.

I think GetTickCount() is discussed actually.

 
robofx.org:

I think GetTickCount() is discussed actually.

I ment GetTickCount() of course.... Sorry. I updated the Topic header.

 
gordon:

From my experience, no matter how many loops and calculations or how intensive they are, the tester still does them in a single tick. Of course the tester run time would be longer, but the tester still assumes that the calculations are done in a single tick's time (I'm talking about the interpolated ticks...).


Furthermore, if u do a loop that relies on the time passing (for example - if u to tell the tester to wait until TimeCurrent() is some specific time), but u do it WITHOUT exiting start(), then the Tester gets "stuck". Of course in demo/live the same code would work just fine, cause time actually moves, but in the tester time does not exist... There are only interpolated ticks; start() always starts and ends in a single tick. If the code is such that start() doesn't finish (because it relies on time actually passing) then the Tester simply gets "stuck" in that tick.


Anyway, all this is from my experience... But I might be wrong. But back to the subject, so let's say I want to introduce some kind of delay after an operation that in reality takes a relatively long time (for example opening orders, closing, etc.) and in the Tester takes zero time (it's all done in a single tick in the tester anyway) - how do I do it???


Another question - how does the Tester decide how many ticks to interpolate within a single minute? And how is this interpolation done? I've gone through most if not all of the articles about Tester... Problem is they are a poor translation of Russian articles. A lot of what's written there doesn't make sense and generally I find it lacks the technical details I'm looking for.

Okay, I think what you are saying is that in reality, there are occasions (such as file access) which introduce delays.

Let's say that this particular file access takes about 3 ticks.

In the tester, in a period of say 10 ticks, you may find that ticks 6 and 7 are spread apart by the file access, but all 10 ticks are executed.

In reality ticks 7,8 and 9 are ignored whilst the file access operation is being performed.

What you could do is to set a tick counter when you do a labour intensive function. Then when start() is next executed that counter is decremented by one before a return() call. In effect you'd be guessing how many ticks a process would take and causing that number of ticks to be ignored.

Would that do what you want?

Reason: