After we performed actions described in the previous article we've got a skeleton code which we can change in accordance with our trading strategy and get an operable expert advisor. Let’s try to understand what we have got as the result…
//+------------------------------------------------------------------+
//| My First Expert.mq4 |
//| Copyright c 2006, Andrey Vedikhin |
//| http://www.vedikhin.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Andrey Vedikhin"
#property link "http://www.vedikhin.ru"
//---- input parameters
extern int MAPeriod=0;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
The first several lines are comments. A comment is a nonexecutable portion of a code, that is to say this is some information useful for a reader of the code. Comments are generally formatted as line comments and block comments. Line comments start with a comment delimiter //and continue until the end of the line. Block comments are specified with a start delimiter /* and an end delimiter */ .
#property copyright "Copyright © 2006, Andrey Vedikhin"
With the help of #property copyright «line» we can set the name/title of the expert advisor’s creator.
#property link "http://www.vedikhin.ru"
With the help of #property link «web-site» we will set the creator’s web-site.
extern int MAPeriod=0;
Thus we describe a variable – an expert’s parameter. This parameter has the default value 0, but this value can be changed later and for each expert advisor applied to the chart its own values can be set. This parameter is an analogue of a technical indicator parameter (for example calculation period for RSA or the period of calculation of a moving average).
The word extern in front of the definition of the variable shows that this is an external variable or parameter, which will be seen in the settings of the expert. int — the type of the variable (in our example this parameter is an integer number from -2147483648 to 2147483647 — see the previous article). And MAPeriod — is the name of the parameter. We want the default value of the parameter to be equal to zero, that’s why we will add =0 fight after the name of the parameter. Semicolon shows that we have completed the description of the expert’s parameter.
An expert advisor can have several such parameters. They all must be of one of the types described in the previous article.
Next article: "
How to create your own functions"