MTC Сombo – EA MetaTrader 5

Below is the author’s descriptions along with my minor edits since five digits are already used for currency pairs nowadays.

The EA’s objective is as follows:

Suppose that we have a basic trading system (BTS). We should design and train a neural network (NN) so that it can supplement BTS by performing actions inaccessible for the latter. As a result, we are to get a trading system consisting of the two combined and complementary BTS and NN.

There is no need to reinvent the wheel when it has long been invented. What is the point in teaching anyone to run fast, if there is a car, or fly, if you have a helicopter? 

If we have a trend TS, it is necessary to teach the neural network a counter-trend strategy only. The system meant for trends cannot trade during flats, as well as define roll-backs and reversals adequately. Of course, we may use two trading strategies (trend and counter-trend ones) and launch them on a single chart. On the other hand, we can train a neural network so that it supplements a trading system.

For this purpose, we have developed the two-layer neural network consisting of two bottom-layer perceptrons and one upper-layer perceptron. 
The neural network may be in one of the three states:

  1. Entering long
  2. Entering short
  3. Undefined

The third status means the control is passed to the BTS, while trading signals are generated by the network in the first two states.

The neural network training is divided into three stages. One perceptron is trained at each of them. The optimized BTS is present on each stage to let the perceptrons know what it can do.

Separate training of the perceptrons using the genetic algorithm is caused by the algorithm’s drawback, namely a limited number of parameters that can be selected with its help. Anyway, each training stage is logically consistent and the neural network is not too large, therefore the entire optimization process occurs within a reasonable amount of time.

But the very first stage preceding the NN training is meant for the BTS optimization.

To avoid confusion, the stage number is specified in the EA input with the “pass” ID. The input IDs corresponding to the stage number end in that exact number.

Let’s make preliminary preparations for the NN optimization and training.

Set the initial deposit in the tester to $100 (not to create an artificial margin call during optimization), optimized “Balance + max Sharpe Ratio” parameter, “Fast genetic algorithm” optimization type. 

Now, go to the Inputs tab of the EA properties. 
Set the lot size of opened positions by assigning the value of 0.01 to the “lots” ID.

Optimization is to be performed according to the “Open prices only” model. This method has been selected for its high speed. Besides, the EA algorithm features the new bars management.

Alternative:  Open BUY v2 - script MetaTrader 4

First optimization stage. BTS optimization:

Set pass to 1. 
Optimize only the inputs corresponding to the first stage with all their IDs ending in one. Therefore, set the optimization marks on them only removing the marks from the rest of the parameters.

tp1 – BTS take profit. Optimized with the values from 100 to 1000 with the step of 10
sl1 – BTS stop loss. Optimized with the values from 100 to 1000 with the step of 10
p1 – period of CCI oscillator applied in the BTS. Optimized with the values from 3 to 100 with the step of 1

Start training via the genetic algorithm optimization. 

The second stage. Training the perceptron responsible for short positions:

Set the ‘pass’ input to 2 (so that it matches the stage number). 
Remove optimization marks set at the previous stage. Save the inputs obtained during the previous stage to file just in case.

Set optimization marks for the second stage parameters (IDs ending in two):

x12, x22, x32, x42 – weight ratios of the perceptron recognizing short positions. Optimized with the values from 0 to 200 with the step of 1.
tp2 – take profit of positions opened by the perceptron. Optimized with the values from 100 to 1000 with the step of 10
sl2 – stop loss of positions opened by the perceptron. Optimized with the values from 100 to 1000 with the step of 10
p2 – period of price difference values analyzed by the perceptron. Optimized with the values from 3 to 100 with the step of 1.

Start training via the genetic algorithm optimization.

The third stage. Training the perceptron responsible for long positions:

Set the ‘pass’ input to 3 (so that it matches the stage number). 
Remove optimization marks set at the previous stage. 
Save the inputs obtained during the previous stage to file just in case.

Set optimization marks for the third stage parameters (IDs ending in three):

x13, x23, x33, x43 – weight ratios of the perceptron recognizing long positions. Optimized with the values from 0 to 200 with the step of 1.
tp3 – take profit of positions opened by the perceptron. Optimized with the values from 100 to 1000 with the step of 10
sl3 – stop loss of positions opened by the perceptron. Optimized with the values from 100 to 1000 with the step of 10
p3 – period of price difference values analyzed by the perceptron. Optimized with the values from 3 to 100 with the step of 1.

Start training via the genetic algorithm optimization. 

The final fourth stage.

Alternative:  Double smoothed EMA - floating levels (multi time frame) - indicator MetaTrader 5

Training the first layer (the upper-layer perceptron):

Set the ‘pass’ input to 4 (so that it matches the stage number). 
Remove optimization marks set at the previous stage. 
Save the inputs obtained during the previous stage to file just in case.

Set optimization marks for the fourth stage parameters (IDs ending in four):

x14, x24, x34, x44 – weight ratios of the first-layer perceptron. Optimized with the values from 0 to 200 with the step of 1.
p4 – period of price difference values analyzed by the perceptron. Optimized with the values from 3 to 100 with the step of 1.

Start training via the genetic algorithm optimization. 

That is all. The neural network is trained.

The EA features yet another non-optimizable ‘mn’ input – magic number allowing the system to distinguish its own orders among the ones opened manually or by other EAs. The magic number should be unique.

P.S.

  • The initial deposit size is defined as an absolute drawdown multiplied by two (safety margin). 
  • The EA’s source code has not been optimized 
  • Change the contents of the basicTradingSystem() function if you want to replace the built-in BTS by the algorithm of another trading system
  • Re-optimize the EA during weekends if the previous week’s results were unprofitable. Losses signal of the market changes and the need for re-optimization. If the EA is profitable, no re-optimization is needed since the robot recognizes the market patterns quite well.


📈 ROBOTFX MetaTrader Expert Advisors and Indicators to maximize profits and minimize the risks