EA backtest issue with reading Daily range

 

Hello,

I want to backtest  My EA on the broker IcMarkets. When I print: Print(iLow(_Symbol,PERIOD_D1,0));  In the Journal of the Strategy Tester, I receive the lowest dayily price, no matter if the day just started and that price is going to be touched only hours later. Seems like this Print gives mem a data that knows already in the future what is going to happen in the next hours of the current Day. How to fix this?

 
arimbur:

Hello,

I want to backtest  My EA on the broker IcMarkets. When I print: Print(iLow(_Symbol,PERIOD_D1,0));  In the Journal of the Strategy Tester, I receive the lowest dayily price, no matter if the day just started and that price is going to be touched only hours later. Seems like this Print gives mem a data that knows already in the future what is going to happen in the next hours of the current Day. How to fix this?

This would be a serious issue, so I have tested it for a few days period in the tester.

I just used this simple code

void OnTick()
{
  static datetime bar_time=0;
  datetime this_bar_time=Time[0];
  if(bar_time!=this_bar_time)
   {
    bar_time=this_bar_time;
    Print("Current Day Low = ",DoubleToString(iLow(_Symbol,PERIOD_D1,0),_Digits));
   }
}

The results were correct in that only the current day low at the time of the bar open was printed.

Different broker to yours but I don't see that should matter.

Please show your code which can 'look into the future'.

 
Keith Watford #: This would be a serious issue, so I have tested it for a few days period in the tester. I just used this simple code. The results were correct in that only the current day low at the time of the bar open was printed. Different broker to yours but I don't see that should matter. Please show your code which can 'look into the future'.

I made a small change to your code sample and can confirm that Strategy Tester (MT4 build 1356) is working correctly, with both standard generated virtual ticks, as well as 3rd party real tick data.

void OnTick()
{
  static datetime bar_time=0;
  datetime this_bar_time=Time[0];
  if(bar_time!=this_bar_time)
   {
    bar_time=this_bar_time;
    PrintFormat( "Current Day %s Low = %s",
      TimeToString(   iTime( _Symbol, PERIOD_D1, 0 )          ),
      DoubleToString( iLow(  _Symbol, PERIOD_D1, 0 ), _Digits )  );
   };
};

Normal MetaTrader generated virtual ticks ...

2022.08.19 02:18:50.162 2022.08.01 00:00:00  TestTester test started
2022.08.19 02:18:53.510 2022.08.01 00:05:00  TestTester EURUSD,H4: Current Day 2022.08.01 00:00 Low = 1.02115
2022.08.19 02:18:53.510 2022.08.01 04:00:00  TestTester EURUSD,H4: Current Day 2022.08.01 00:00 Low = 1.02047
2022.08.19 02:18:53.510 2022.08.01 08:00:00  TestTester EURUSD,H4: Current Day 2022.08.01 00:00 Low = 1.02047
2022.08.19 02:18:53.510 2022.08.01 12:00:00  TestTester EURUSD,H4: Current Day 2022.08.01 00:00 Low = 1.02047
2022.08.19 02:18:53.525 2022.08.01 16:00:00  TestTester EURUSD,H4: Current Day 2022.08.01 00:00 Low = 1.02047
2022.08.19 02:18:53.525 2022.08.01 20:00:00  TestTester EURUSD,H4: Current Day 2022.08.01 00:00 Low = 1.02047
2022.08.19 02:18:53.525 2022.08.02 00:05:00  TestTester EURUSD,H4: Current Day 2022.08.02 00:00 Low = 1.02579
2022.08.19 02:18:53.525 2022.08.02 04:00:00  TestTester EURUSD,H4: Current Day 2022.08.02 00:00 Low = 1.02488
2022.08.19 02:18:53.525 2022.08.02 08:00:00  TestTester EURUSD,H4: Current Day 2022.08.02 00:00 Low = 1.02488
2022.08.19 02:18:53.525 2022.08.02 12:00:00  TestTester EURUSD,H4: Current Day 2022.08.02 00:00 Low = 1.02143
2022.08.19 02:18:53.525 2022.08.02 16:00:00  TestTester EURUSD,H4: Current Day 2022.08.02 00:00 Low = 1.02062
2022.08.19 02:18:53.541 2022.08.02 20:00:00  TestTester EURUSD,H4: Current Day 2022.08.02 00:00 Low = 1.01805
2022.08.19 02:18:53.541 2022.08.03 00:05:00  TestTester EURUSD,H4: Current Day 2022.08.03 00:00 Low = 1.01658
2022.08.19 02:18:53.541 2022.08.03 04:00:00  TestTester EURUSD,H4: Current Day 2022.08.03 00:00 Low = 1.01494
2022.08.19 02:18:53.541 2022.08.03 08:00:00  TestTester EURUSD,H4: Current Day 2022.08.03 00:00 Low = 1.01494
2022.08.19 02:18:53.541 2022.08.03 12:00:00  TestTester EURUSD,H4: Current Day 2022.08.03 00:00 Low = 1.01494
2022.08.19 02:18:53.541 2022.08.03 16:00:00  TestTester EURUSD,H4: Current Day 2022.08.03 00:00 Low = 1.01494
2022.08.19 02:18:53.556 2022.08.03 20:00:00  TestTester EURUSD,H4: Current Day 2022.08.03 00:00 Low = 1.01218
2022.08.19 02:18:53.556 2022.08.04 00:05:00  TestTester EURUSD,H4: Current Day 2022.08.04 00:00 Low = 1.01669
2022.08.19 02:18:53.556 2022.08.04 04:00:00  TestTester EURUSD,H4: Current Day 2022.08.04 00:00 Low = 1.01534
2022.08.19 02:18:53.556 2022.08.04 08:00:00  TestTester EURUSD,H4: Current Day 2022.08.04 00:00 Low = 1.01534
2022.08.19 02:18:53.556 2022.08.04 12:00:00  TestTester EURUSD,H4: Current Day 2022.08.04 00:00 Low = 1.01534
2022.08.19 02:18:53.556 2022.08.04 16:00:00  TestTester EURUSD,H4: Current Day 2022.08.04 00:00 Low = 1.01534
2022.08.19 02:18:53.556 2022.08.04 20:00:00  TestTester EURUSD,H4: Current Day 2022.08.04 00:00 Low = 1.01534
2022.08.19 02:18:53.556 EURUSD,H4: 377465 tick events (24 bars, 378465 bar states) processed in 0:00:03.390 (total time 0:00:25.531)

3rd party generated FXT file with real tick data ...

2022.08.19 02:11:20.882 TestGenerator: file "C:\Trading\MetaQuotes\MetaTrader 4\tester\history\EURUSD240_0.fxt" is read-only
2022.08.19 02:11:20.882 TestGenerator: symbol EURUSD period 240 model 0 from 2022.05.19 to 2022.08.18
2022.08.19 02:11:20.991 2022.08.01 00:00:00  TestTester test started
2022.08.19 02:11:20.991 2022.08.01 00:04:00  TestTester EURUSD,H4: Current Day 2022.08.01 00:00 Low = 1.02098
2022.08.19 02:11:20.991 2022.08.01 04:00:00  TestTester EURUSD,H4: Current Day 2022.08.01 00:00 Low = 1.02053
2022.08.19 02:11:20.991 2022.08.01 08:00:00  TestTester EURUSD,H4: Current Day 2022.08.01 00:00 Low = 1.02053
2022.08.19 02:11:21.002 2022.08.01 12:00:00  TestTester EURUSD,H4: Current Day 2022.08.01 00:00 Low = 1.02053
2022.08.19 02:11:21.002 2022.08.01 16:00:00  TestTester EURUSD,H4: Current Day 2022.08.01 00:00 Low = 1.02053
2022.08.19 02:11:21.002 2022.08.01 20:00:00  TestTester EURUSD,H4: Current Day 2022.08.01 00:00 Low = 1.02053
2022.08.19 02:11:21.012 2022.08.02 00:00:00  TestTester EURUSD,H4: Current Day 2022.08.02 00:00 Low = 1.02607
2022.08.19 02:11:21.012 2022.08.02 04:00:00  TestTester EURUSD,H4: Current Day 2022.08.02 00:00 Low = 1.02560
2022.08.19 02:11:21.012 2022.08.02 08:00:00  TestTester EURUSD,H4: Current Day 2022.08.02 00:00 Low = 1.02560
2022.08.19 02:11:21.020 2022.08.02 12:00:00  TestTester EURUSD,H4: Current Day 2022.08.02 00:00 Low = 1.02149
2022.08.19 02:11:21.022 2022.08.02 16:00:00  TestTester EURUSD,H4: Current Day 2022.08.02 00:00 Low = 1.02067
2022.08.19 02:11:21.030 2022.08.02 20:00:00  TestTester EURUSD,H4: Current Day 2022.08.02 00:00 Low = 1.01810
2022.08.19 02:11:21.032 2022.08.03 00:00:01  TestTester EURUSD,H4: Current Day 2022.08.03 00:00 Low = 1.01648
2022.08.19 02:11:21.032 2022.08.03 04:00:00  TestTester EURUSD,H4: Current Day 2022.08.03 00:00 Low = 1.01498
2022.08.19 02:11:21.032 2022.08.03 08:00:00  TestTester EURUSD,H4: Current Day 2022.08.03 00:00 Low = 1.01498
2022.08.19 02:11:21.042 2022.08.03 12:00:00  TestTester EURUSD,H4: Current Day 2022.08.03 00:00 Low = 1.01498
2022.08.19 02:11:21.042 2022.08.03 16:00:00  TestTester EURUSD,H4: Current Day 2022.08.03 00:00 Low = 1.01498
2022.08.19 02:11:21.050 2022.08.03 20:00:00  TestTester EURUSD,H4: Current Day 2022.08.03 00:00 Low = 1.01226
2022.08.19 02:11:21.052 2022.08.04 00:00:00  TestTester EURUSD,H4: Current Day 2022.08.04 00:00 Low = 1.01642
2022.08.19 02:11:21.052 2022.08.04 04:00:00  TestTester EURUSD,H4: Current Day 2022.08.04 00:00 Low = 1.01542
2022.08.19 02:11:21.052 2022.08.04 08:00:00  TestTester EURUSD,H4: Current Day 2022.08.04 00:00 Low = 1.01542
2022.08.19 02:11:21.052 2022.08.04 12:00:00  TestTester EURUSD,H4: Current Day 2022.08.04 00:00 Low = 1.01542
2022.08.19 02:11:21.062 2022.08.04 16:00:00  TestTester EURUSD,H4: Current Day 2022.08.04 00:00 Low = 1.01542
2022.08.19 02:11:21.062 2022.08.04 20:00:00  TestTester EURUSD,H4: Current Day 2022.08.04 00:00 Low = 1.01542
2022.08.19 02:11:21.062 EURUSD,H4: 506388 tick events (24 bars, 6064671 bar states) processed in 0:00:00.078 (total time 0:00:00.187)
Reason: