Using MT4 Strategy Tester to evaluate Trading a time slot

To add comments, please log in or register
Paxman
65
Paxman  

Hi


I have an EA (written some years back).

In the EA is a start time and end time for trading each day.

In Strategy Tester it does not allow you to increment either the start time or end time to evaluate results. It is greyed out.

When i look in the code the "time" is entered as a string and then parsed out to give hours and minutes.

So my question is can i rewrite this to allow testing of start and end time like the other variables? Or does MT4 Strategy tester not have any time functions that would work to help in this situation?

Thanks for any advice.


Neil

William Roeder
20217
William Roeder  

Since you don't show any code, we can only guess. I guess that your "start time" and "end time" are strings, thus greyed out.

If you make them an int/uint (seconds in a day,) or a double (fraction of a day,) then you can easily convert them to a datetime for comparison.
          Find bar of the same time one day ago - Simple Trading Strategies - MQL4 programming forum

Paxman
65
Paxman  
William Roeder:

Since you don't show any code, we can only guess. I guess that your "start time" and "end time" are strings, thus greyed out.

If you make them an int/uint (seconds in a day,) or a double (fraction of a day,) then you can easily convert them to a datetime for comparison.
          Find bar of the same time one day ago - Simple Trading Strategies - MQL4 programming forum

Hi William,

Yes they are string variables. I did mention in the post but i did not show any code as I wrongly assumed i would figure out what to do once i undertood what the problem was.

I found your code and have tried to understand how to use it. I have only used VBA previously and this is difficult for me to figure out what is going on.

In the EA i created two integer variables and then was hoping to use them in the code as follows.

extern int     intHourStart                        = 01; 1 somehow formatted as 01 but not sure if it is possible
extern int     intHourEnd                         = 24;

Then concatenate the intHourStart with ":30" to give a start time of "01:30"

It seems this is not a good way to try!

Existing code       
extern string  Chart_Server_Start_Time   = "10:30";
extern string  Chart_Server_End_Time     = "22:30";

So trying to understand your code it creates a variable HR2400 which is = to 86400 seconds in a 24 hour day.

Then it creates an integer value TimeOfDay but i can not figure the code logic. If when (is this a built in function) is equal to zero then set TimeOfDay to the current time.

If it is not = to zero then set it to a time derived from the number of seconds? Not sure how this works and googling has so far not helped.

I have looked through the MQL4 reference but can not find what i need to carry on as yet.

Am i along the right track?

Regards


Neil

I realise i got a bit sidetracked as I was researching and ended up refering to this post you made and did not go back to your original link. Hopefully the logic will be similar so an explanation will allow me to move forward.

https://www.mql5.com/en/forum/154022

#define HR2400 (PERIOD_D1 * 60)  // 86400 = 24 * 3600
int      TimeOfDay(datetime when=0){      if(when == 0)  when = TimeCurrent();
                                          return( when % HR2400 ); 
Timing question
Timing question
  • 2014.12.01
  • www.mql5.com
Aloha Gurus! I'd like my EA to do something every day between let's say 09:45 and 11:15, i.e...
To add comments, please log in or register