MQL4 Real Time Clock (second by second)

 

It is my understanting that the Start() function works tick by tick.

Is there a way to use real-time data from the computer clock and update every second? Not tick by tick but every second?

If so please give me some help.

thanks

 

explain

 

MQL4 uses TimeLocal() ; TimeCurrent() which are based on tick per tick even iTime....

What I really want is to be able to display on my graph a real-time clock that will update every second, probably using my computer clock or a remote server.

 

TimeCurrent() is not tick based.

But the start function is tick based. You can use a endless loop in combinations with sleep. there is an article published here on mql4.com explaining advantages and solutions.

Since the whole mt4 is tick driven i don't like implementing time sensitive logic. in the past i combined these two in my Custom Timeframe indicators. It is just a simple work but you might get an idea. If you want a watch updated every second then my work is useless for you. https://www.mql5.com/en/code/10080

//z

 

The idea is to get a watch to update every second not just call functions in the Start() as your program i.e.

if(TimeCurrent()>(t+TimeInSeconds))

from your explanation; I can use a while loop in the init() function and then what about when I call it in the start() function; it will still be tick by tick !

 

you will need something like this your start function. The loop gets executed on the first tick. after that it will be tick independ

while(true){
 updateWatch();
 Sleep(1000);
} 
 

zzuegg; this will be an endless loop and will limit the metatrader indicator to doing one thing... count.

So if you choose to use the sleep function in combination with the TimeCurrenet called from a funtion to add a second every Sleep(1000); this program will not be able to do anything else.

It will just count....so you will be limiting yourself to one function.

 

and yes metatrader doesnt like endless loops; it crashes as I experienced now lol it should have a break somewhere :)

 

You are not limited to one function. You can do anything you want inside the loop. you might need some recalculations to guarantee 1sec execution time. but in general it works.

I have never done it with indicatos, but in EA's it works.

Another option is to use an external program to send fake ticks to your terminal in an 1sec interval. by that you have guaranteed that the start function is called at least once every second. In combination with my code from the Custom Timeframe Candles you should get your result.

 
while( !(IsTesting() || IsStopped()) ){
    updateWatch();
    RefreshRates();
    if (...)  doTrading();
    Sleep(1000);
} 


and yes metatrader doesnt like endless loops; it crashes as I experienced now lol it should have a break somewhere :)
No endless loops in indicators. For scripts and EAs it's ok if you update internals first (as in the above.)
 

Use MQL5

Reason: