Download MetaTrader 5

Time update in code

To add comments, please log in or register
Having difficulties in understanding the Trading Signals service? Read the article!
eevviill14
60
eevviill14 2016.11.27 09:38 

If call TimeCurrent() in start of OnTick() and in the end. Do TimeCurrent() changes if in interval of code running there will be tick?

Same question. but 1 additional thing. Between 2 TimeCurrents there RefreshRates().

void OnTick()
{
datetime time=TimeCurrent();

//new tick
//new tick+RefreshRates()

datetime time2=TimeCurrent();

//time==time2 ???????????
}

 

 

If call TimeLocal() in start of OnTimer() and in the end. Do TimeLocal() changes if in interval of code running will be 2 seconds(on timer is 1 second)?

Same question. but 1 additional thing. Between 2 TimeLocals there RefreshRates().

void OnTimer()
{
datetime time=TimeLocal();

//code running 2 seconds
//code running 2 seconds+RefreshRates()  

datetime time2=TimeCurrent();

//time==time2 ???????????
}
Ex Ovo Omnia
3151
Ex Ovo Omnia 2016.11.27 09:53  

TimeCurrent is the last server response, so any tick on any instrument in the Market Watch can update it. I do not expect the RefreshRates has any effect.

TimeLocal is just the internal clock, it increments regardless of your code.

Drazen Penic
2544
Drazen Penic 2016.11.27 10:33  

Wouldn't it be great if MQL4 has some kind of Print() command so that you can print values and inspect them yourself? 

Print - Common Functions - MQL4 Reference
Print - Common Functions - MQL4 Reference
  • docs.mql4.com
Print - Common Functions - MQL4 Reference
Keith Watford
Moderator
9627
Keith Watford 2016.11.27 10:56  

From the documentation

In the OnTick() handler, this function returns the time of the received handled tick. In other cases (for example, call in handlers OnInit(), OnDeinit(), OnTimer() and so on) this is the time of the last quote receipt for any symbol available in the "Market Watch" window, the time shown in the title of this window.


eevviill14
60
eevviill14 2016.11.27 11:38  
Keith Watford:

From the documentation

And? There is no answers.

 

Are you moderator? Why you do not delete flood? 

Keith Watford
Moderator
9627
Keith Watford 2016.11.27 11:45  
eevviill14:

And? There is no answers.

 

Are you moderator? Why you do not delete flood? 

You have been given your answer

In the OnTick() handler, this function returns the time of the received handled tick.


Yes, I am a Moderator. the word Moderator above my rating may have given you a clue. I see no evidence of flooding.
eevviill14
60
eevviill14 2016.11.27 11:51  

About TimeCurrent answers are founded.

 So new tick not changes TimeCurrent while code running, but RefreshRates do it.

 

 https://book.mql4.com/en/functions/datetime

Each tick is characterized with its own value of the server time that can be obtained using the TimeCurrent() function. During the execution, this value can only be changed as a result of the RefreshRates() function call. 

Date and Time - Standard Functions - MQL4 Tutorial
Date and Time - Standard Functions - MQL4 Tutorial
  • book.mql4.com
Date and Time - Standard Functions - MQL4 Tutorial
eevviill14
60
eevviill14 2016.11.27 11:57  

So I only need to know about TimeLocal(). 

Keith Watford
Moderator
9627
Keith Watford 2016.11.27 12:07  
eevviill14:

So I only need to know about TimeLocal(). 

Ovo Cz:

TimeLocal is just the internal clock, it increments regardless of your code.

Carl Schreiber
6590
Carl Schreiber 2016.11.27 12:20  
eevviill14:

So I only need to know about TimeLocal(). 

It depends very much on what you need! TimeCurrent() allows you to order the prices it belongs to while TimelLocal() does not e.g. in case of a varying latency.
eevviill14
60
eevviill14 2016.11.27 22:07  

TimeLocal() updates each time while code running in OnTimer().

TimeCurrent() not  updates each time while code running in OnTick(). But after RefreshRates() new call of TimeCurrent() updates it.

12
To add comments, please log in or register