MetaEditor Help

Creating an EA template

Creating an EA template

A template is a basic source code of a trading robot. It contains the standard program header, general properties and workpieces for the main event handlers: new tick arrival (OnTick), launch (OnInit) and EA deinitialization (OnDeinit). A template is created in the directory corresponding to a program type – MQL5/Experts (or MQL4/Experts). When creating a template, you can define the program inputs beforehand, as well as add them to the workpiece code for additional event handlers.

Creating an EA

Fill in the following fields:

  • Name – EA name. The same name is assigned to an EA file. Here you can also change the path to a destination file. For example, create it in the new \Experts subfolders.
  • Author – author name.
  • Link – developer's email address or website.
  • Parameters – set of EA 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.

After specifying all the necessary data, click Next.

Event handlers

At subsequent stages, select additional event handlers. The workpieces for them are to be inserted into the EA template:

  • General handlers: events of a chart, a depth of market, new trades, etc.
  • Test event handlers – managing optimization in real time.

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, OnDeninit and OnTick.

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