Morning All
So I have a snippet of code set up to prompt a MessageBox to make itself known at a certain time (closingTime) which is formatted to an Integer on the 24 hour clock, which in this case is 17 (or 1700 GMT).
I am aware that the terminal works to EET and that I have to make an adjustment to local time, which I have done, but the terminal still prompts the MessageBox at random times, and sometimes, it doesn't prompt at all, which makes no sense at all:
I can confirm that the localTime and the mql4Time (EET) times are correct from the print function.
What am I missing here?
Pip pip!
I think your GMTAdjustment may be wrong.
I usually do it like this:
int localTimeGMToffset = int(TimeGMT() - TimeLocal()); int MQLTimeGMToffset = int(TimeGMT() - TimeCurrent()); int localToMQLoffset = localTimeGMToffset - MQLTimeGMToffset;
But an easier way could be something like this:
int closingTime = 17; //1700 GMT MqlDateTime timeLocStruct; TimeToStruct(TimeLocal(), timeLocStruct); if(timeLocStruct.hour == closingTime) { //message... }
I think your GMTAdjustment may be wrong.
I usually do it like this:
But an easier way could be something like this:
Thanks for this, this does not work, but I can't expect you to troubleshoot this for me for free (unless it's intriguing enough for you to do so). :)
All the best,
MqlDateTime timeLocStruct; TimeToStruct(TimeLocal(), timeLocStruct); printf("The timeLocStruct is %d",timeLocStruct.hour); int closingTime = 8; if(timeLocStruct.hour == closingTime){ bool isSaveWork = MessageBox( "...", "...", MB_ICONINFORMATION | MB_OK | MB_TOPMOST ); if(!isSaveWork){ printf("Error sent %d", GetLastError()); }
Thanks for this, this does not work, but I can't expect you to troubleshoot this for me for free (unless it's intriguing enough for you to do so). :)
All the best,
These seem to work for me, so you would need to be more specific when you say it does not work, but I think you are more than capable of debugging and fixing it yourself so please do post the working version
These seem to work for me, so you would need to be more specific when you say it does not work, but I think you are more than capable of debugging and fixing it yourself so please do post the working version
Yep, you're right, I am capable & should have posted this in the first place. Sorry about that, and so I have posted my working here.
Good - I now see you have posted your latest code. When you say it does not work, what is the problem you are experiencing?
Great, the problem is that the MessageBox is not appearing, nor are there any errors in the journal in the event that
(!isSaveWork)
returns true.
The same also applies when
if(timeLocStruct.min == 33){...} //33 Minutes past the hourBut it's printing the correct Hour time:
2022.07.22 08:42:46.243 xxxxxx USDZAR,H4: The timeLocStruct is 8:00 GMT
Great, the problem is that the MessageBox is not appearing, nor are there any errors in the journal in the event that
returns true.
The same also applies when
OK so the timing check works - this is a secondary problem.
I ran the code you posted - I got the message box (see pic)
The isSaveWork is thus true, so no final print
Good! I am sure you appreciate you need to add more filters/delays to ensure you don't get too many frequent messages during the hour, unless you want them... good luck
Yes! I've just done a control check, as follows. Initialised isSent to false, checked this on the OnTick section, then set this to true.
Work's a good'un :)
onInit(){ isSent = false; } onTick(){ MqlDateTime timeLocStruct; TimeToStruct(TimeLocal(), timeLocStruct); int timeClosing = 10; if(timeLocStruct.hour == timeClosing){ if(!isSent){ bool isSaveWork = MessageBox( StringFormat(".....(Time %d:00 GMT)",timeLocStruct.hour), "....", MB_ICONINFORMATION | MB_OK | MB_TOPMOST ); isSent = true; } } }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
So I have a snippet of code set up to prompt a MessageBox to make itself known at a certain time (closingTime) which is formatted to an Integer on the 24 hour clock, which in this case is 17 (or 1700 GMT).
I am aware that the terminal works to EET and that I have to make an adjustment to local time, which I have done, but the terminal still prompts the MessageBox at random times, and sometimes, it doesn't prompt at all, which makes no sense at all:
I can confirm that the localTime and the mql4Time (EET) times are correct from the print function.
What am I missing here?
Pip pip!