![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
You wait for a tick. Check if the time is 12:05. If not don't open. If so, open. When in doubt, THINK.
Dear William,
Thanks for kindly respect.
Hi
In Metatrader OnTick() function is called when forming a candle, which does not know what hour or minute the event will take place.
I think you get the current server time using TimeTradeServer (dt_struc)
Then turn it into seconds.
For example:
your clock=12:05:30
current time server=11:01:00
long TimeRemainingInSeconds=((12-11)*60*60)+((05-01)*60)+30;
and call ontimer() function:
OnTimer(1sec);
and then in OnTimer function:
if(TimeRemainingInSeconds==0)///////////////////////////At this point the server clock is equal to the clock you want(12:05:30)
{
sendorder();
}
else
{
TimeRemainingInSeconds--;
}
I hope my solution works.
If you have any questions, I'm at your service.
ِDear Milad,
thanks again for your kindly respect. It is my pleasure to have a great friend as you.
Use OnTimer Event
This is the easiest and most accurate way to open time orders
hoping a solution of your problem.
hoping a solution of your problem.
dear Mike,
thanks, I figure out how to solve my problem and your code is so easier and more technically than that I wrote.
dear Mike,
thanks, I figure out how to solve my problem and your code is so easier and more technically than that I wrote.
your Welcome!
hoping a solution of your problem.
StringToTime() will automatically add the current date when it just receives a time of day. You could shorten your function to:
or even just:
Note this may trigger several sendOrder(), or even no one at all, depending on the amount of ticks seen during that second.
StringToTime() will automatically add the current date when it just receives a time of day. You could shorten your function to:
or even just:
Note this may trigger several sendOrder(), or even no one at all, depending on the amount of ticks seen during that second.
Im very happy your extended support on this issue, and mostly happy when you trim my code. i am now replacing my old code with this one quoted "datetime targetTime() { string timeofday="12:05:00"; return StringToTime(timeofday); }". YES it is TRUE that -this may trigger several sendOrder() but i am only helping
how to open a trade at the exact time, without using pending order. lippmaje-two thumbs up for you!!