Download MetaTrader 5

Strange initialization problem in the strategy tester.

To add comments, please log in or register
Keith Watford
Keith Watford  

I started a test in visual mode and a template with the same name of the EA is set on the chart.

Then I get this message

2017.01.28 02:31:27.176    VPC EURUSD,H1: array out of range in 'VPC.mq4' (121,33)

2017.01.28 02:31:27.176    VPC EURUSD,H1: global initialization failed

followed by a similar report for another indicator.

So I checked the indicators code and it is this

static datetime bar_time=Time[0];

in both indicators.

That seems really weird to me as it is executed in OnCalculate(), surely Time[0] should already be loaded in the tester?

The EA still calls the indicators correctly, but they are not displayed.

Odd thing is that changing the code to this

   static datetime bar_time=0;

there is no problem
Alain Verleyen
Alain Verleyen  
A static is initialized before OnCalculate() is call and before OnInit(), so the "global initialization". You can't be sure Time[] is already set.
To add comments, please log in or register