how to backtest timebased EA

 

how to make backtest possible for this code?

if(DayOfWeek()==5 && Hour() == EntryHour && Minute()>=EntryMinute)
        {
                ticket=OrderSend(Symbol(),OP_BUYSTOP ,Lot ,Ask+Distance*Point,SlipPage,Bid-Distance*Point+SL*Point,Ask+Distance*Point+TP*Point,OrdComment,Magic,0,Blue);
        if(ticket>0)

        {

        if(OrderSelect(ticket,SELECT_BY_POS,MODE_HISTORY)) Print("order opened : ",OrderOpenPrice());
        }
        

        else Print("Error opening order : ",GetLastError()); 

        } 
        return(0);

  }
 
I don't see why this can't run in the Strategy Tester . .
 

it's working w/ live or demo but in strategy tester i don't have any results ...

in strategy tester i see results if i remove the hour and minute part like:

if(DayOfWeek()==5)

if(DayOfWeek()==5 && Hour() == EntryHour && Minute()>=EntryMinute)
 

According to the Documentation https://docs.mql4.com/dateandtime/DayOfWeek should be OK in the Strategy Tester, "Note: At the testing, the last known server time is modelled."

Before the if add a print, Print("Day of the week is: ", DayOfWeek()); see if you get what you expect to get . . . if you do then you have another issue . .

 
  1. https://www.mql5.com/en/forum/127483 reported that DayOfWeek() always returns 5 in the tester. Probably the same with Hour and Minute - returning the time of test start.
    datetime now = TimeCurrent();
    if( TimeDayOfWeek(now)==5 && TimeHour(now) == EntryHour && TimeMinute(now)>=EntryMinute)

  2. Or use my code
 

thanks, but the day part is working without hour and minute ...

the problem is:

&& Hour() == EntryHour && Minute()>=EntryMinute)

could it be that Strategy Tester is not working w/ day, hour and minute condition ?

 

but i don't get any result ... no orders ... nothing ... :-)

only if I removed hour() and minute() it's working

 
fulltilt:

but i don't get any result ... no orders ... nothing ... :-)

only if I removed hour() and minute() it's working

OK, sorry I misread your post . . . still add the print, but Print("Hour is: ", Hour(), " Minute is ", Minute()); so you can understand what is causing your issue . . . don't assume if you don't need to.
 

it starts counting the minutes from:

2011.08.09 17:18 EA EURUSD,M5: Hour is: 17 Minute is 18
to

2011.08.30 23:59 EA EURUSD,M5: Hour is: 23 Minute is 59

hm - the condition should be open pending order every friday at 23:58

on live server it is working, but in tester nothing happen ...

 
fulltilt:

it starts counting the minutes from:

2011.08.09 17:18 EA EURUSD,M5: Hour is: 17 Minute is 18
to

2011.08.30 23:59 EA EURUSD,M5: Hour is: 23 Minute is 59

hm - the condition should be open pending order every friday at 23:58

on live server it is working, but in tester nothing happen ...


Add in the Day to the Print, maybe your test data doesn't have that time on Friday . . my local Friday midnight I can't place a trade because the markets are closed . .
 
RaptorUK:
Add in the Day to the Print, maybe your test data doesn't have that time on Friday . . my local Friday midnight I can't place a trade because the markets are closed . .
Some fridays are not 23:59 market close. Some earlier by an hour. Also there are holidays.
Reason: