Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

Clock - Library for MetaTrader 5 | MT5 EA Download - MetaTrader 5 Resources

author EAcpu | 3 reads | 0 comments |

Clock - library for MetaTrader 5

Clock - library for MetaTrader 5

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

The use of this library is shown in the source code below:

 // MQL4&5 code
// Example of a cross-platform Expert Advisor that creates an analog clock on a chart

#propertystrict

#include // https://www.mql5.com/en/code/19388

Constant string object name = __file__ ; // The name of the Bitmap object that displays the clock
const string resource name = "::" + object name; // The name of the resource that will form the clock

// Create a clock clock clock ( "Clock\\Clock01\\Clock01.INI" , resource name) according to the settings of the corresponding INI file; blank start ()
{
//Create a graphical object for displaying the clock. Object creation ( 0 , object name, OBJ_BITMAP_LABEL , 0 , 0 , 0 );

//Specify the name object set string of the resource where the clock is located ( 0 , object name, OBJPROP_BMP file , 0 , resource name);

// Add possibility to select an object and drag it with the mouse object set integer ( 0 , object name, OBJPROP_SELECTABLE , true );

// Enable the second timer to update the clock event set timer ( 1 );
} Blank timer ()
{
//Set the current time on the clock clock.setTime( timelocal ());

// Refresh the chart to make changes visible chart redraw ();
}

After refreshing the following clock appears on the chart:

Clock - library for MetaTrader 5

The included cross-platform Clock.mq5 indicator allows you to use the clock immediately "out of the box".

This indicator enables interactive changes to the skin: use the up/down keys on the keyboard to toggle the clock version (unzip the ZIP archive).

The original clocks were obtained from the web by searching for flash Clock (the swf files are available in ZIP), which is convenient since they contain the required graphical representation of clock faces, hands, etc. You can use any other source. For example, you can find ready-made vector files or draw them yourself.

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

 Image name = ClockFace.bmp
Binding X = 0 // The X coordinate of the internal zero point of the bmp image (layer) Binding Y = 0 // The Y coordinate of the internal zero point of the bmp image (layer) 100 % // The value of the green channel used B = 100 % // The value of the blue channel used

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

This method of image construction allows using the library to form any static/dynamic object, not just clocks. To provide clock dynamics, we just need to set the rotation. However, other types of movement (such as panning, zooming, etc.) can be added to the code in just a few lines. The accompanying source code provides an example of how to implement this method when describing images.

As for the clock, layer-by-layer operations allow us to implement shadows for the hands and lighting (just like we did in the flash clock).

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

Clock - library for MetaTrader 5

As of the time of this article's publication, there are no analog clocks on the market. I found this variant in the code base.

New to the library is Layer::Rotate for rotation. Perhaps, this feature will lead to the creation of third-party solutions based on dynamic graphics resources similar to clocks.


Attachment download

📎 canvas.mqh (0.36 KB)

📎 color.mqh (1.48 KB)

📎 file.mqh (2.45 KB)

📎 image.mqh (1.17 KB)

📎 pixel.mqh (0.33 KB)

📎 settings.mqh (1.26 KB)

📎 clock_layer.mqh (1.55 KB)

📎 layer.mqh (2.05 KB)

📎 clock.mqh (1.65 KB)

📎 clock.mq5 (2.84 KB)

Source: MQL5 #19388

Verification code Refresh