Time[0] in the backtester

 

Does anyone know if the backtester handles the Time array properly? i.e., if i run a backtest starting July 1st, will calls to Time[0] in the EA return July 1st, or whatever time it is now?

 
it will of course return the time in the chart not the current time. You cannot access (not even intentionally) any data from the outside world (current time, curent price, etc) when you are running a backtest. Everything is modeled according to the chart and time you are backtesting on. The only thing that annoyingly always sneaks in from the outside world is the current bid-ask spread so you should perform reliably repeatable backtests always with a disconnected MT4.
 

I thought certain things like DayOfWeek() are carried through the backtest with the "last known server time". I was wondering if there were any other backtest suprises for an EA that does some time-based filtering based on session, day of week, etc.

I'm asking this because i've noticed some unusual behaviour during backtesting. My EA counts the number of bars in the chart on every iteration, to use during statistics gathering, and just for the hell of it i had it Print Time[Bars-1]. You'd expect this value to be the same as the first date in the chart and remain constant every iteration. Instead, Even though the chart data goes all the way back to January, Time[Bars-1] is printing some time at the end of June. This is making me doubt wether the backtest is good for anything other than debugging my MM modules, since the EA is a purely statistical-driven system and it looks like the backtester is gathering messed-up stats.

 

gatornuke:Time[Bars-1] is printing some time at the end of June. This is making me doubt wether the backtest is good for anything other than debugging my MM modules, since the EA is a purely statistical-driven system and it looks like the backtester is gathering messed-up stats.

Do also a Print(Bars) to see how many bars are there in the chart. The backtest chart might not be initialized with all available history, I think it only gets something like a maximum of 200 bars or so before the date of the test-start.
 
7bit:
Do also a Print(Bars) to see how many bars are there in the chart. The backtest chart might not be initialized with all available history, I think it only gets something like a maximum of 200 bars or so before the date of the test-start.

Thanks, I'll do that. If that turns out to be the case, i think my system is "unbacktestable" for the most part. That would also explain some of the zero division errors I was getting during backtesting when i was trying different things.
 

I recently solved a similar problem by starting the test earlier and then letting it skip the first 2000 bars: if (Bars < 2000) return(0);

It won't throw away bars, the available history will grow as the test proceeds.

 

Hi

I need help on how to write MT 4 formula for MS Excel worksheet in multiple time-frames to be able to see what a currency pair has done in the last 12 hours, 24 hours, last week and month in the for of heat-map visually just like it is presented on this website http://finviz.com/forex_performance.ashx so that you know the strength and weakness of different pairs over a period of time, be able to know which one is trending, consolidating and stall.

Thanks.

 
Arborfx:

Hi

I need help on how to write MT 4 formula for MS Excel worksheet in multiple time-frames to be able to see what a currency pair has done in the last 12 hours, 24 hours, last week and month in the for of heat-map visually just like it is presented on this website http://finviz.com/forex_performance.ashx so that you know the strength and weakness of different pairs over a period of time, be able to know which one is trending, consolidating and stall.

Thanks.


Why bother with excel? just work with arrays in MQL4 instead. It's a lot faster and cleaner.
 
7bit:

I recently solved a similar problem by starting the test earlier and then letting it skip the first 2000 bars: if (Bars < 2000) return(0);

It won't throw away bars, the available history will grow as the test proceeds.


Thanks for the tip. I might do that instead.
 
The tester starts with 100 bars.
I thought certain things like DayOfWeek() are carried through the backtest with the "last known server time". I was wondering if there were any other backtest suprises for an EA that does some time-based filtering based on session, day of week, etc.
This was reported at https://www.mql5.com/en/forum/127483 I haven't seen it. Possible he was executing a non-returning EA which would have one server time and thus can't be backtested. Anyway I modified my code just in case
datetime now = Time[0]; // or TimeCurrent()
int DOW = TimeDayOfWeek(now);   /* https://forum.mql4.com/33851
// reports DayOfWeek() always returns 5 in the tester. No refresh?*/
Reason: