2. Strategy and Parameters

Bookmark and Share

1. Create New Expert Advisor

First, we need to create a new Expert Advisor file.
(Please click and follow the link above if you forgot how).

Click the Create New File button, and choose "Expert Advisor" in the setup wizard.
In the property settings screen, name the file as Breakout_1 (or whatever name you prefer). 
Enter your own name as the Author (using your nickname or leaving it blank is also fine). Leave the Link and Parameters alone for now. 

The first screen will look something like this:

新しいExpert Advisor
(The image is re-published. File name may be different but it does not matter this time.)

2. Setting Variables

Before writing the Expert Advisor program, first define the variables. 
Write lines of codes like below.  

  1. // Variables
  2. extern double Lots=1.0;
  3. extern int BreakPeriod = 10;
  4. extern int ExitTime = 10;
  5. extern int Slippage=3;
  6. extern int StopLoss=25;
  8. datetime timeprev=0;
  10. // The codes above need to be written before the line below.
  12. //+------------------------------------------------------------------+
  13. //| expert initialization function                                   |
  14. //+------------------------------------------------------------------+

Upon defining the variables, take note of the first word "extern". 
"Extern" enables the variable to be redefined later by an external program. 
For now, just add the word at the beginning; it helps greatly when back-testing. 

3. Meanings of the Variables

Let's look at each variables and their purpose. 


  1. extern double Lots=1.0;

Number of lots. It sets how much position to take when there is an upward or a downward trend. 
The units are in constructs, or 100,000 currency units. 
In the example above, 100,000USD is longed when USDJPY is assumed to be in an upward trend. 


  1. extern int BreakPeriod = 10;

In the breakout strategy, the point at which the maximum or minimum value of a given time period is exceeded is treated as the point at which the trend occurs.
The variable that defines such a "time period" is BreakPeriod.
In the example above where the Expert Advisor is tagged to a 5 minute increment chart, the trend occurs at a point in which the maximum (or minimum) value of the past 50 minutes (=5x10) is exceeded. 


  1. extern int ExitTime = 10;

Generally, trend judgement based on taking a position becomes riskier with time. 
You should question your own judgement when the currency you longed does not go in an upward trend as you expected. 

Therefore, this program can automatically settle a position if it is not settled in a certain period of time. 

ExitTime is a variable that sets the said period of time.
In the example above where the Expert Advisor is tagged to a 5 minute increment chart, the position is automatically settled 50 minutes (=5x10) after the position is taken. 


  1. extern int Slippage=3;

Prices can change even while you make a decision for a market order. This happens much less frequently for a system trade managed by a computer, but it is still quite possible for a price to be different between the moment and the moment of making the order

Slippage sets the allowance for such discrepancy in price. 
The allowed difference in price is 3 pips in the example above.


  1. extern int StopLoss=25;

Literally, it sets StopLoss.
In the example above, the order to settle is carried out automatically when the loss reaches 25 pips.