We can find dial gauges in cars and airplanes, in industrial production
and everyday life. They are used in all spheres which require quick
response to behavior of a controlled value. This article describes the
library of dial gauges for MetaTrader 5.
It all started when I first acquainted myself with the CCanvas
class. When it came to practice, I stumbled upon an idea to draw a
gauge indicator. My first gauges were pretty crude, but eventually they
have been supplemented by new elements and become visually pleasing. And
as a result, I have a small library now which allows to add a dial
gauge to an indicator or an EA in a simple and easy manner. In this
article, we will give consideration to structure of gauges, get
acquainted with functions necessary for drawing and setting visual
appearance, and assess resource intensity.
1. Coordinates and Anchor
There are two types of positioning a gauge on a chart: absolute and relative.
In case of absolute positioning, coordinates represent distances in pixels from an anchor corner along X and Y axis.
In case of relative positioning, local origin of coordinates
is created according to the specified type of the relative positioning.
When the vertical type is selected, the origin is located below or above
a reference object (if an upper or a lower anchor corner is selected
respectively). When the vertical type is selected, it is located on the
left or on the right in the direction from the anchor corner. In this
case, specified coordinates represent an offset from their local origin.
Positive offsets lead to moving an object away from the reference
object. In case of negative offsets, the object will encroach on the
reference one.
The reference object can be represented only by an object of another
gauge. It is essential that both objects will have the same anchor
corner.
Fig. 2 depicts an example of relative positioning.
New article Drawing Dial Gauges Using the CCanvas Class has been published on mql5.com:
We can find dial gauges in cars and airplanes, in industrial production and everyday life. They are used in all spheres which require quick response to behavior of a controlled value. This article describes the library of dial gauges for MetaTrader 5.
It all started when I first acquainted myself with the CCanvas class. When it came to practice, I stumbled upon an idea to draw a gauge indicator. My first gauges were pretty crude, but eventually they have been supplemented by new elements and become visually pleasing. And as a result, I have a small library now which allows to add a dial gauge to an indicator or an EA in a simple and easy manner. In this article, we will give consideration to structure of gauges, get acquainted with functions necessary for drawing and setting visual appearance, and assess resource intensity.
1. Coordinates and Anchor
There are two types of positioning a gauge on a chart: absolute and relative.
In case of absolute positioning, coordinates represent distances in pixels from an anchor corner along X and Y axis.
In case of relative positioning, local origin of coordinates is created according to the specified type of the relative positioning. When the vertical type is selected, the origin is located below or above a reference object (if an upper or a lower anchor corner is selected respectively). When the vertical type is selected, it is located on the left or on the right in the direction from the anchor corner. In this case, specified coordinates represent an offset from their local origin. Positive offsets lead to moving an object away from the reference object. In case of negative offsets, the object will encroach on the reference one.
The reference object can be represented only by an object of another gauge. It is essential that both objects will have the same anchor corner.
Fig. 2 depicts an example of relative positioning.
Fig.2. Relative positioning of gauges
Author: Serhii Shevchuk