There is no guarantee that there will be a time with zero seconds.
The TimeCurrent is reported as the trade server time and it is only updated when a new tick arrives, so there is no guarantee that a tick will arrive at exactly that time with zero seconds.
In fact, a tick could arrive only after several minutes, or even several hours or even days (weekend).
So all you can do, is detect when the TimeCurrent has changed in respect to the minutes and ignoring the seconds.
void OnTick() { static int nMinutesCurrent = WRONG_VALUE; int nMinutesPrevious = nMinutesCurrent; nMinutesCurrent = TimeCurrent() / 60; bool bMinutesNew = nMinutesCurrent != nMinutesPrevious; if( bMinutesNew ) { // A new minute was detected }; };
I know of no such function called "TimeSeconds()". There is nothing about it in the documentation. In fact TimeCurrent() is already in seconds.
Also, please edit your post and use "</>" or Alt-S for the code.
I know of no such function called "TimeSeconds()". There is nothing about it in the documentation. In fact TimeCurrent() is already in seconds.
Also, please edit your post and use "</>" or Alt-S for the code.
Hi All,
If I run the onTick function to tell me CurrentTime, how can I filter the EA to do actions only when the time is :00 seconds?
Thanks for the answers
Hi , Binary options ? you would have to anticipate the "hypothetical" start of the next bar assuming you are in sync with the BO platform .
The following is just a showcase of counting down to the next bar .
#property version "1.00" //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ /* the countdown string assembler */ string return_two_digits(int value){ if(value<10){return("0"+IntegerToString(value));} return(IntegerToString(value)); } string countdown_text(datetime next_bar, datetime time_now){ //difference in seconds int secs=(int)next_bar-(int)time_now; //days //how many full days fit in the seconds difference int days=(int)MathFloor(((double)secs)/86400); //remove the seconds of the full days from the seconds difference secs-=days*86400; //hours int hours=(int)MathFloor(((double)secs)/3600); secs-=hours*3600; //minutes int minutes=(int)MathFloor(((double)secs)/60); secs-=minutes*60; //format return("D:"+return_two_digits(days)+"|H:"+return_two_digits(hours)+"|M:"+return_two_digits(minutes)+"|S:"+return_two_digits(secs)); } ENUM_TIMEFRAMES tfs[]={PERIOD_M1,PERIOD_M5,PERIOD_M15,PERIOD_M30,PERIOD_H1,PERIOD_H4,PERIOD_D1,PERIOD_W1,PERIOD_MN1}; string tf_texts[]={"M1","M5","M15","M30","H1","H4","D1","W1","MN1"}; int OnInit() { while(!EventSetTimer(1)){ Sleep(24); } return(INIT_SUCCEEDED); } void OnTimer() { //--- string comm=""; datetime now=0,server=TimeTradeServer(); for(int i=0;i<ArraySize(tfs);i++){ ResetLastError(); now=iTime(_Symbol,tfs[i],0); if(GetLastError()==0&&(server-now)<=PeriodSeconds(tfs[i])){ comm+=tf_texts[i]+":"+countdown_text((datetime)(now+PeriodSeconds(tfs[i])),TimeCurrent())+"\n"; } } Comment(comm); } void OnDeinit(const int reason) { EventKillTimer(); } void OnTick() { }
There is no guarantee that there will be a time with zero seconds.
The TimeCurrent is reported as the trade server time and it is only updated when a new tick arrives, so there is no guarantee that a tick will arrive at exactly that time with zero seconds.
In fact, a tick could arrive only after several minutes, or even several hours or even days (weekend).
So all you can do, is detect when the TimeCurrent has changed in respect to the minutes and ignoring the seconds.
Yes, a tick could arrive later, but in the time period I'm going to select, the time in Market Watch 99.9% of the time changes from :59 -> :00 -> :01, so can the EA detect the change in Market Watch clock and perform action when the time on Market watch is :00?
The function "TimeSeconds()" in MQL4 has a different functionality and it returns only the seconds part of the time, not the time in seconds. TimeCurrent() already returns the time in seconds.
PS! My solution above works on both MQL5 and MQL4.
Hi All,
If I run the onTick function to tell me CurrentTime, how can I filter the EA to do actions only when the time is :00 seconds?
Thanks for the answers
Hello,
There's a very simple method.
Here's the code:
void OnTick() { datetime timestamp; datetime time = iTime(_Symbol,PERIOD_M1,0); if(timestamp != time) { timestamp = time; // Function =>> } }// OnTick end
Greetings, Igor
I myself use also the iTime comparison. So far it works nicely but I still don´t know if iTime technically only transmits time comparisons or if it is somehow connected with new tick event or/and trading server also.
Seems OnTick event triggers iTime newbar event also after bar forming time, even much later when new tick finally arrives, it still points to the last bar formed. But what about using the TimeCurrent() function, does it work the same way when we used it in the OnTick function? I believe I'm not the only one who has used such logic but hasn't thought about how it actually works because it just works and that's it...
Maybe someone could explain it technically?
Anyway, there seems to be additional built-in synchronization logic here, otherwise these things wouldn't work in such a simplified form. Imagine what happens when the time ticks down, the iterator cycle is started but the bar itself has not appeared, for example, due to latency in the connection or technical problems with the broker. If there is no new bar then there is nothing to process.

- 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 All,
If I run the onTick function to tell me CurrentTime, how can I filter the EA to do actions only when the time is :00 seconds?
Thanks for the answers