Download MetaTrader 5

Watch how to download trading robots for free

Interesting script?
So post a link to it -
let others appraise it

You liked the script? Try it in the MetaTrader 5 terminal


Clock - library for MetaTrader 5

| English Русский 中文 Español Deutsch Português

votes: 20
2018.01.22 09:39
Canvas.mqh (0.36 KB)view
Color.mqh (1.48 KB)view
File.mqh (2.45 KB)view
Image.mqh (1.17 KB)view
Pixel.mqh (0.33 KB)view
Settings.mqh (1.26 KB)view
Layer.mqh (2.05 KB)view
Clock.mqh (1.65 KB)view
Clock.mq5 (2.84 KB)view
\MQL5\Files\ (903.45 KB)

The library (Clock.mqh) allows creating analog clocks as graphical resources.


The use of the library is shown in the following source code:

// MQL4&5-code
// An example of a cross-platform Expert Advisor, which creates an analog clock on the chart

#property strict

#include <fxsaber\Clock.mqh> //

const string ObjName = __FILE__;            // The name of the Bitmap object to display the clock
const string ResourceName = "::" + ObjName; // The name of the resource where the clock will be formed

// Creating the clock from the settings of the corresponding INI file
CLOCK Clock("Clocks\\Clock01\\Clock01.INI", ResourceName);

void OnINIt()
  // Creating a graphical object for displaying the clock
  ObjectCreate(0, ObjName, OBJ_BITMAP_LABEL, 0, 0, 0);

  // Specifying the name of the resource where the clock is located
  ObjectSetString(0, ObjName, OBJPROP_BMPFILE, 0, ResourceName);

  // Adding the possibility to select the object to drag it with the mouse
  ObjectSetInteger(0, ObjName, OBJPROP_SELECTABLE, true);

  // Enabling the second timer to update the clock

void OnTimer()
  // Setting the current time on the clock

  // Refreshing the chart to make changes visible

The following clock appears on the chart after refresh:


The attached cross-platform Clock.mq5 indicator enables the immediate "out of the box" use of the clock.

The indicator implements an interactive change of skins: clock versions (unpack the ZIP archive) are switched using the UP/DOWN keys on the keyboard.


  • Raster (not vector) clock;
  • Hour hands move without smoothing;
  • The library can be used in MetaTrader 4/5.

How the clock is formed

The originals of clock are taken from the web by searching for flash clock (swf files are available in the ZIP), which are convenient because they contain required graphical representations of clock face, hands, etc. You can use any other sources. For example, you can find ready vector files or draw them yourself.

INI files (see examples) set the parameters of clock formation layer by layer. The below settings can be edited in any text editor

ImageName = ClockFace.bmp
BoundX = 0 // the X coordinate of the zero point inside the bmp image (layer)
BoundY = 0 // the Y coordinate of the zero point inside the bmp image (layer)
X = 0      // the X coordinate of the zero point inside the image being formed of layers
Y = 0      // the Y coordinate of the zero point inside the image being formed of layers
Rotate = 0 // Speed of rotation
A = 100%   // The value of the Alpha channel used
R = 100%   // The value of the Red channel used
G = 100%   // The value of the Green channel used
B = 100%   // The value of the Blue channel used

The lower the position of a layer description in the list, the higher it is than previously described layers. There is no special limitation on the number of layers.

This image construction method allows using the library for forming any static/dynamic objects, not only the clock. To provide the clock dynamics, we only needed to set rotation. However, other types of movement (such as shift, scaling, etc.) can be added to the code in just a few lines. The attached source code provides an example of how to implement this approach when describing images.

As for the clock, the layer-by-layer operation allowed us to implement shadows of hands and illumination (as is done in flash clocks).

If you want to make the dial transparent, you should set the Alpha channel in the corresponding INI file less than 100%:

Alpha channel of the dial 90% (A = 90)

At the time of publication, there were no analog clocks in the Market. I've found this variant in the Code Base.

The new feature of this library is LAYER::Rotate used for rotation. Probably, this function will lead to the creation of third-party solutions based on dynamic graphical resources similar to the clock.

Translated from Russian by MetaQuotes Software Corp.
Original code:

JS-Chaos JS-Chaos

The Expert Advisor is based on Bill Williams' strategy.

KI_signals_v2 KI_signals_v2

A trend indicator, which receives trade signals from the XMACD histogram.

N seconds N points N seconds N points

The Expert Advisor tracks positions of all symbols with all magic numbers. If a position has been open for "Waiting for seconds" and its profit has reached "Take Profit" points, the EA closes the position. If the profit has not reached "Take Profit" points, the EA moves the take profit level.

Dtm Dtm

An oscillator in the DRAW_FILLING style, using digital filters.