Download MetaTrader 5

Strategy Tester not giving correct rates.

To add comments, please log in or register
NoCool14
239
NoCool14  

Hello guys, I have a question... the following is my code:

 

void onStart()
{
MqlRates rates[];
 
     int copied=CopyRates(Symbol(),PERIOD_M1,0,100,rates);
     if(copied<=0)
       Print("Error copying price data ",GetLastError());
    else Print("Copied ",ArraySize(rates)," bars");
    
    for (int i = 99; i >0; i--)
    {
    Print("OPEN: " + rates[i].open + "CLOSE: " + rates[i].close + "TIME: " + rates[i].time + "TIME LOCAL: " + TimeLocal());
    }
}

 

Here is the strategy tester settings:

 Settings

 

But when it prints it prints this (It prints September 30 rates instead of the last months rates starting TIME LOCAL:

 

2013.10.15 21:36:21 Core 1 2013.10.01 00:00:00   OPEN: 1.35233CLOSE: 1.35225TIME: 2013.09.30 22:21:00TIME LOCAL: 2013.10.01 00:00:00
2013.10.15 21:36:21 Core 1 2013.10.01 00:00:00   OPEN: 1.35224CLOSE: 1.35222TIME: 2013.09.30 22:22:00TIME LOCAL: 2013.10.01 00:00:00
2013.10.15 21:36:21 Core 1 2013.10.01 00:00:00   OPEN: 1.35222CLOSE: 1.35221TIME: 2013.09.30 22:23:00TIME LOCAL: 2013.10.01 00:00:00
2013.10.15 21:36:21 Core 1 2013.10.01 00:00:00   OPEN: 1.3522CLOSE: 1.35215TIME: 2013.09.30 22:24:00TIME LOCAL: 2013.10.01 00:00:00
2013.10.15 21:36:21 Core 1 2013.10.01 00:00:00   OPEN: 1.35219CLOSE: 1.35238TIME: 2013.09.30 22:25:00TIME LOCAL: 2013.10.01 00:00:00
2013.10.15 21:36:21 Core 1 2013.10.01 00:00:00   OPEN: 1.35237CLOSE: 1.3524TIME: 2013.09.30 22:26:00TIME LOCAL: 2013.10.01 00:00:00
2013.10.15 21:36:21 Core 1 2013.10.01 00:00:00   OPEN: 1.35241CLOSE: 1.35236TIME: 2013.09.30 22:27:00TIME LOCAL: 2013.10.01 00:00:00
2013.10.15 21:36:21 Core 1 2013.10.01 00:00:00   OPEN: 1.35236CLOSE: 1.35239TIME: 2013.09.30 22:28:00TIME LOCAL: 2013.10.01 00:00:00

What am I doing wrong?


 

Thanks ahead of time. 

Simon Gniadkowski
Moderator
18021
Simon Gniadkowski  
NoCool14:

Hello guys, I have a question... the following is my code:

Here is the strategy tester settings:

But when it prints it prints this (It prints September 30 rates instead of the last months rates starting TIME LOCAL:

 

 From here:  https://www.mql5.com/en/docs/runtime/testing

Simulation of Time in the Strategy Tester

During testing, the local time TimeLocal() is always equal to the server time TimeTradeServer(). In turn, the server time is always equal to the time corresponding to the GMT time -TimeGMT(). This way, all of these functions display the same time during testing.

The lack of a difference between the GMT, the Local, and the server time in the Strategy Tester is done deliberately in case there is no connection to the server. The test results should always be the same, regardless of whether or not there is a connection. Information about the server time is not stored locally, and is taken from the server.

Documentation on MQL5: MQL5 programs / Testing Trading Strategies
Documentation on MQL5: MQL5 programs / Testing Trading Strategies
  • www.mql5.com
MQL5 programs / Testing Trading Strategies - Documentation on MQL5
NoCool14
239
NoCool14  
I understand that. But why does it always give me September rates even when I change the date to a custom date say January 1 to February 20. It still gives back the September rates.
Simon Gniadkowski
Moderator
18021
Simon Gniadkowski  
NoCool14:
I understand that. But why does it always give me September rates even when I change the date to a custom date say January 1 to February 20. It still gives back the September rates.
I'm not sure why . . . have you checked that you have the M1 data for the date range in question ?  open an M1 chart for the symbol you are looking at and scroll back to Jan 1st
Alain Verleyen
Moderator
32774
Alain Verleyen  
NoCool14:
I understand that. But why does it always give me September rates even when I change the date to a custom date say January 1 to February 20. It still gives back the September rates.

From the data posted, I don't see a problem. On 2013.10.01 00:00, you are copying 100 M1 rates, so you get data from 2013.09.30 22:21 to 2013.10.01 00:00.

If you get this result with others custom date, please post logs/screenshot to demonstrate this. Also, where and when you function onStart was called ?

NoCool14
239
NoCool14  

I don't know what to say guys....Now it works, same code same everything. Maybe I just needed to restart the MQL and MT5, I think that did the trick. Thank you very much for everything guys.

To add comments, please log in or register