Input storage classes are global variables and must be declared outside of blocks and functions. In the concept of MQL4 and MQL5, these input storage classes are also often named “external variables” as these variables are accessible externally from the code. The purpose of these external variables is to provide an interface to tweak and modify the parameters of your robot or expert advisor without altering the code. External variables can be accessed from the MetaTrader interface as per Fig.47, tab “Inputs.”

Expert Advisor Input, external variables.
Fig.47 Expert Advisor Input, external variables.
Input, external variables declaration
Fig.48 Input, external variables declaration.
Note

  • All types of variables can be used except arrays.
  • Input variables must be declared as global variables before functions.

Let us take the example of our simple moving average strategy. You would like to test the moving average robot with different periods, for instance, 20, 50, or 100. Instead of modifying the code every time you are running the robot, you can instead change the expert advisor settings from the MetaTrader interface. This allows you to easily implement a trading strategy that can be adapted and tuned to market conditions over time. To access the Expert Advisor’s input tab from MetaTrader, locate the chart where your robot is attached to (Fig.49). The name of the attached Expert Advisor should be displayed in the upper right corner of the chart. From the chart, right-click and select the menu “Expert List” if you are on MetaTrader 5 or “Expert Advisors/Properties” if you are on MetaTrader 4 (Fig.50).

Expert Advisor attached to the chart
Fig.49 Expert Advisor attached to the chart
Access to Expert Advisor’s properties, MetaTrader 5 (left), MetaTrader 4 (right) Access to Expert Advisor’s properties, MetaTrader 5 (left), MetaTrader 4 (right)

Fig. 50 Access to Expert Advisor’s properties, MetaTrader 5 (left), MetaTrader 4 (right).

In MetaTrader 5, you have an additional step to reveal the Expert Advisor properties, press the button “properties” to reveal the list of input variables from the “Experts dialog” (Fig.51).

Metatrader 5 Experts dialog
Fig.51 Metatrader 5 Experts dialog
Important

  • All types of variables can be used except arrays for input variables.
  • Input variables must be declared as global variables before functions.
  • As input variables are global variables, they are accessible from the entire scope of the Expert Advisor.

Leave a Reply

5  +  1  =