MetaEditor Help

Creating an indicator

Creating an indicator

A template is a basic source code of an indicator. It contains the standard program header, general properties and workpieces for the main event handlers: value re-calculation (OnCalculate) and indicator launch (OnInit). A template is created in the directory corresponding to a program type – MQL5/Indicators (or MQL4/Indicators). When creating a template, you can define the program inputs beforehand, as well as add them to the workpiece code for additional event handlers and graphical constructions.

Creating an indicator

Fill in the following fields:

  • Name – indicator name. The same name is assigned to its file. Here you can also change the path to a destination file. For example, create it in the new \Indicators subfolder.
  • Author – author name.
  • Link – developer's email address or website.
  • Parameters – set of indicator input parameters (external variables).

The input parameters are "input" class variables. To create a parameter, click Add and fill in three fields:

  • Name – input variable name.
  • Type – input variable type.
  • Initial value – initial value of a variable. It can be changed before a program launch or during operation.

Even handlers

Next, select additional event handlers. The workpieces for them are to be inserted into the EA template. OnCalculate handler is mandatory, so you can only select its type, but not delete it.

To view an extended handler description, move the cursor over it.

Select event handlers

Selected handlers are added in addition to the main ones – OnInit and OnCalculate.

Display parameters

Creating an indicator

The following parameters are specified at this stage:

  • Indicator in separate window – display indicator in a separate window. If disabled, the indicator is applied to the main chart window.
  • Minimum – lower limit of the vertical scale of indicator values. The parameter is used only when displaying the indicator in a separate window.
  • Maximum – upper limit of the vertical scale of indicator values. The parameter is used only when displaying the indicator in a separate window.

In Plots section, you can specify graphical indicator constructions: name, type (for example, line or histogram) and color. In the indicator code, the corresponding properties of constructions, as well as buffers for values are added.

Click Finish to complete template creation. A generated file is immediately opened for editing.