I think you misunderstand IsTradeAllowed have a read here: https://docs.mql4.com/check/IsTradeAllowed
You can't set it, you read it and it tells you if trading is allowed . . .
bool MyEAIsAllowedToTrade; MyEAIsAllowedToTrade = IsTradeAllowed(); if (MyEAIsAllowedToTrade) Print("Yipee, my EA is allowed to trade . . .");
There is no Time() function . . . (check here: https://docs.mql4.com/dateandtime )
ray2955:
if( time()==12:00 ){ IsTradeAloud="true" } if( IsTradeAloud=="true" ){ // Trade Logic }
- Use SRC for code
datetime now = Time[0]; int tod = now % 86400; // Time of day datetime bod = now - tod; // Beginning of the day #define HR1200 43200 // 12 * 3600 bool isTimeToOpen = (tod == HR1200); if(isTimeToOpen){ // Trade Logic }
Good on TFs H1 and lower.- If you want to trade a specific range of times (and days) use my code.
- Don't use IsTradeAloud as it's too close to IsTradeAllowed which has a completely different meaning.
- You would never say "if ( (var > 0) == true)." You would only say "if (var > 0)." "if (bool == true)" is redundant, just use if (bool)
Basically the time between (4:00 to 12:00) mon-fri metatrader chart time
is what i need using the 4hr bar.
#define HR4 14400 // is this how to use the 4hr bar (4*3600)
now =Time[0], // is this in secs
bod=now % 86400; // not sure is the present time of day a % of 86400 secs
I look at your code and im not sure where to set the desired time and date .
Thanks
You didn't mention anything about 04:00 in your original post . . . follow WHRoeder's point 3, it will give you what you need.
To answer your questions . . .
- times and dates in MT4 are always in seconds and are the number of seconds since Jan 1st 1970 see: https://docs.mql4.com/dateandtime
- now is the open time of the current bar on the chart, i.e. Time[0]
- 86400 is the number of seconds in 24 hours, take the now time, divide it by the number of seconds in a day take the remainder and that gives the number of seconds since midnight. ( % gives the remainder not a percentage)
- the desired time of day is set at the #define 12 hours * 60 mins * 60 secs = 43200 HR = hour, 1200 = 12:00
when anyone gives you some code to use you always need to read it, understand it . . before you use it . . . it might be wrong or it may just not do what you wanted. This especially applies to any code I post . . . ;-)
PS. I suspect this code does have an error . . . I think bod is already what tod is meant to be . . .
now is date+time (a datetime,) bod is date+0000 hours (midnight, a datetime) same thing you would get from iTime(NULL, PERIOD_D1, 0), tod is seconds from midnight (an int.)
Isn't bod the number of seconds between the start of the current 0 bar and last midnight ? i.e. not a datetime ?
To get midnight shouldn't you have done this ?
bod = now - (now % 86400); // Beginning of the day
I ran your code and got this (server time is local + 1 hr so 15:00 candle) :
2011.08.22 14:30:27 tradeat12 EURCAD,H1: now= 1314025200 bod = now % 86400 = 54000 tod = now - bod = 1313971200
Early in the morning, coffee hadn't kicked in and then I go post the same error 5 different places. :( Of course, (now % 86400) is seconds since midnight.
I use to say I could write that type of code in my sleep. Apparently not.
Early in the morning, coffee hadn't kicked in. Of course, (now % 86400) is seconds since midnight.
I have a time advantage over you, it's afternoon here :-) had plenty of coffee already ;-)
Thanks for the confirmation, reading and understanding you code has helped me lots, thank you for sharing.
I don't know the code; a little vague for me. I hope you could ran it well. I am just a newbie here; hope I could have a positive feedback from you.
I am a scumbag SPAMMER . . . . please delete my post so that it no longer pollutes this thread . . .
I don't know the code; a little vague for me. I hope you could ran it well. I am just a newbie here; hope I could have a positive feedback from you.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi I'm trying learn how to code this. There is time() and Istradealoud().
Here are my thoughs. Please help.
Example:
if( time()==12:00 )
{ IsTradeAloud="true" }
if( IsTradeAloud=="true" )
{
Trade Logic