• Overview
  • Reviews (5)
  • Comments (34)
  • What's new

Neural network 2 Moving Averages

A neural network Expert Advisor based on two moving averages with the training mode. Train the Expert Advisor on selected examples and make a profit in real life. The EA can work on any instrument and in any timeframe.

Trading Algorithm of the EA

Two moving averages are analyzed by the neural network core, which produces commands to buy or sell.

the values of two moving averages, fast (FMA) and slow (SMA), are provided to the first layer, at the second layer it calculates two neurons responsible for Buy (N buy) and Sell (N sell), the decision to buy or sell is made at the third level.

Block diagram of the neural network is shown in the figure.

Expert Advisor Training

In the training mode the EA "remembers" the values of moving averages marked by the user on the chart of the currency instrument. In the future, during normal operation, it recognizes the values of the moving averages.

To train the EA mark at least one long and one short trade on the chart. To indicate a long trade use the "Buy" arrow, and for the short trade use the "Sell" arrow. You can place more arrows on the chart. The more arrows, the longer will be the process of training. Presence of any other objects on the chart other than the arrows is not desirable.

After the training, folder "NN 2MA" will be created in the common folder of the terminal. It will contain file "HHHHHH_NN_2MA.bin" with the settings of the trained neural network. XXXXXX in the file name is the name of the financial instrument. In normal operation, the EA loads the data from the file. If the file is not found, it will use the default settings. By default, the EA is trained at USDJPY and one-hour timeframe, the trades are selected in 2012.

The following input parameters are responsible for the EA training:

  1. The number of weights per neuron. Equal to the length of the MA. Default - 48. 
  2. The number of training cycles - default 100. The higher the value, the longer the training process will be. In the trial version it is 10. 
  3. Factor b - the value affects the speed of the correction of weights of neurons, is used for training the network. The default value is 0.7, does not need changing.
  4. Learning mode EA - enables the training mode of the EA.

Examples of specifying trades for training the EA are available in the figure.

The Normal Mode Settings

Settings of Moving Averages

You can adjust the settings of each moving average: the period, the price, the calculation mode.

Trade Settings

  1. Volume of order - default is 0,1.
  2. Value of slippages in points - default is 30.
  3. Number of attempts to open a position - default is 5.
  4. Level StopLoss in points - default is 0.
  5. Level TakeProfit in points - default is 0.
  6. Level TrailingStop in points - default is 650.
  7. Allow money management - control the order size to enter the market, enabled by defalt. If the mode is disabled, the order size is taken from the "Volume of order" parameter.
  8. The volume of orders as a percentage of the deposit - used to control the order size, default is 5 percent.
  9. Adding to the open position - enabled by default. If there is a signal to enter the market in the direction of an open position, the EA enters the market.

Settings of Neural Network

  1. The number of weights per neuron. Equal to the length of the MA. The higher the value, the more accurate will the current market state be recognized, but it reduces the number of trades. The lower the value, the less accurate will the current market state be recognized, but the number of trades increases. 
  2. The value of neuron activation. The value is approximately 0.75 of the value of "The number of weights per neuron". The higher the value, the stricter is the selection of neurons for making a decision. In the trial version it is 40.
  3. The number of training cycles - default is 100.
  4. Factor b – the weight correction speed, default is 0.7.
  5. Learning mode EA – the EA training mode.

During training, the maximum values ​​of the neurons will be shown in the comments on the chart. These values ​​can be used as an activation value of the neuron.

An example is shown in the figure.

Other Settings

  1. Enable comments - enables comments on the chart.
  2. Magic Number of Advisor.
  3. Pause after trading in milliseconds.

By default, the EA is trained on USDJPY H1 on two trades in 2012. The result of the Expert Advisor testing in 2013 is shown in the figure.

Suhail Chougule
Suhail Chougule 2019.11.29 22:01 

Trailing Stop does not work can you fix it ? In-fact non of the trade settings are enforced?

Wan Ping Fei
Wan Ping Fei 2019.09.29 12:05 


Nikolay Gaylis
Nikolay Gaylis 2019.01.07 19:27 

User didn't leave any comment to the rating

Andrey Litvichenko
Andrey Litvichenko 2017.10.17 06:35 

User didn't leave any comment to the rating

Rodrigo da Silva Boa
Rodrigo da Silva Boa 2016.03.11 03:33 

User didn't leave any comment to the rating

Version 1.5 2020.04.02
Версия советника скомпилированная под новый терминал MT5.
Устранены мелкие ошибки.