Slight flaw in what I wrote; the clock face is designed with Minute and Hour arms. I assumed it would animate a seconds arm.
So I update it once a second while in the current shape it would need a 1 minute timer.
I will update the code so the clock get a seconds arm as well.
It seems my ability to update the post got disabled ?
So I update it once a second while in the current shape it would need a 1 minute timer.
I will update the code so the clock get a seconds arm as well.
It seems my ability to update the post got disabled ?

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
My first MQL5 programming article ever :-()
I found this piece of code in a MQL5 forum that animates a primitive clock face in the chart.
I am not sure who created it, if you know tell me so I can give due credit.
This represents an example of how to render graphical objects on the trading chart.
In the shape I found this code it runs as a single task script to illustrate chart graphic display techniques.
See this original for reference, attached as 'ClockTest.mq5'.
As a monolith script it does not allow anything else to happen at the same time.
So I figured it could be possible to integrate this clock widget into an EA by dividing it into two parts,
(1) a short initialization step run part of OnInit(), + a few EA global varables, and (2) a timer task that runs the update portion.
And it worked !
So this article describes how I turned the clockface script into a EA timer task.
A timer task "ClockTime()" runs once a second to update the clock face (See attached).
In the global variables section of the EA I place some runtime variables for the clock:
In the OnInit() method of the EA
I start a timer task ClockTime:
ClockInit() looks like this:
And here is ClockTime(), the timer job that updates the watch face in the chart:
This is pretty much the untouched code by its author, I only adjusted some font sizes so the watch face displays well.
So to summarize :
By dividing up the original script into an Init part, some global variables, and the interval timer run "ClockTime()" function
the clock can now run on the chart while the rest of the EA works undisturbed.
I tweaked the location of the watch face using a crude offset so it appears on the right hand.
See this line
of the ClockInit() code where the "2700" value is a vertical pixel offset on chart to where the clockface rendering starts.
If you try this code for basic learning you could experiment with OBJPROP_XDISTANCE , OBJPROP_YDISTANCE values to position your clock.
What is missing to make it a full fledged watch is the Hour indicator
So I will try to add this soon :)
So this can be an example of the kind of threaded activity a timer tasks will enable.
Why do this ? I found it a fun test case to gain courage in placing custom stuff on the chart.
The primitive clock face was a ready-made gimmick that lended itself to experimentation.