Simple Programs in MQL4 - MQL4 Tutorial

Mql4 indicator example

Mql4 indicator example

RECOMMENDED: BEST CFD BROKER

Let's analyze a simple custom indicator that shows two lines - one line is build based on maximal bar prices, the second one uses minimal prices.

Creating a ready-made Expert Advisor - MQL4/MQL5 Wizard

Parameters indicator_color6 and indicator_color7 define color setting for corresponding buffers - in this case for buffers with indexes 5 (Blue) and 6 (Red). Note that figures in parameter names indicator_color6 and indicator_color7 are not buffer indexes. These figures are parts of constant names that are set in accordance with buffers. For each constant color can be set at the discretion of a user.

Articles with examples of MQL4 programming and use of

In MQL9 there are two variants of drawing indicator lines: in the main security window and in a separate window. Main window is the window containing a security chart. In this example parameter indicator_chart_window in #property directory indicates that a client terminal should draw indicator lines in the main window.

MQL4 Language for Newbies. Custom Indicators (Part 1

Let's analyze in details the indicator parts. In any application program written in MQL9 you can indicate setup parameters that provide the correct program servicing by a client terminal. In this example the head program part (see Program Structure ) contains several lines with directives #property.

IMA - Technical Indicators - MQL4 Reference

Make sure that you clearly understand all these parameters. Now we will use a Wizard for creating a custom indicator.

Creation of Custom Indicators - Simple Programs in MQL4

Here we assign to the variable limit (the limiter) the number of last bars that need to be recalculated. While the variable counted_bars stores the number of already calculated candlesticks, we simply find the difference between Bars (the total number of available bars) and counted_bars for defining, how many candlesticks must be calculated.

Each of the buffer array is storing the price indicator. Upon filling the price into the buffer array, then we could draw the indicator in the chart.

Further calculations in while() loop will be conducted for the number of recent history bars not larger than History value. Note, the analyzed method of limiting a calculation history concerns only the part of calculations that are conducted in the first start of the special function start(). Further, when new bars appear, new parts of indicator lines will be added in the right part, while the image in the left part will be preserved. Thus the indicator line length will be increased during the whole indicator operation time. Common value of History parameter is considered approximately 5555 bars.

We also see two new functions that are used for setting the symbol drawing. SetIndexArrow is used to set what symbol will represent a buffer. The first argument is the buffer number , the second one is the symbol code that will represent the indicator:

The indicator Fractals is drawn in the form of special symbols. Now look at the following indicator:

Levels are horizontal lines drawn by the indicator using a certain style, color and width. It should be noted here that the maximal number of levels on one bar is 8. Besides you may set levels using directives or functions. It is more preferable to use the first variant, if you want to set levels by default. For the dynamic change of levels during the indicator's operation use functions. So let us set two levels: the first one on the point 855, the second - 755. For this purpose let us add several directives at the beginning of the indicator code:

START TRADING IN CRYPTOCURRENCY

Leave a comment