MQL4 - automated forex trading   /  

Code Base

ODL Securities

Code Base  Expert Advisors  Automated Trading System "Сombo" To post a new code, please log in or register

This expert is for
MetaTrader 4
Download MT4 - 3.5 Mb

Mobile trading!
Buy a license and be mobile in your trading!

Name:
Automated Trading System "Сombo" [ ru ]
Author: Reshetov (2008.03.06 10:44)
Rating: 3
Downloaded: 4975
Download:
 Combo_Right.mq4 (4.6 Kb) View
The problem is stated for this automated trading system (ATS) as follows:

Let's consider we have a basic trading system - BTS. It is necessary to create and teach a neural network to make it do things that cannot be done with the BTS. This must result in creation of a trading system consisting of two combined and mutually complementary systems: BTS and NN (neural network).

Or, the English of this is: There is no need to discover the continents again, they were all discovered. Why to teach somebody to run fast, if we have a car, or to fly, if we have a plane?

Once we have a trend-following ATS, we just have to teach the neural network in countertrend strategy. This is necessary, because a system intended for trend-based trading cannot trade on sideways trends or recognize market setbacks or reversals. You can, of course, take two ATSes - a trend-following one and a countertrend one - and attach them to the same chart. On the other hand, you can teach a neural network to complement your existing trading system.

For this purpose, we designed a two-layer neural network consisting of two perceptrons in the lower layer and one perceptron in the upper layer.
The output of the neural network can be in one of these three states:

  1. Entering the market with a long position
  2. Entering the market with a short position
  3. Indeterminate state

Actually, the third state is the state of passing control over to the BTS, whereas in the first two states the trade signals are given by the neural network.

The teaching of the neural network is divided into three stages, each stage for teaching one perceptron. At any stage, the optimized BTS must be present for perceptrons to know what it can do.

The separate teaching of perceptrons by a genetic algorithm is determined by the lack of this algorithm, namely: The amount of inputs searched in with the help of such algorithm is limited. However, each teaching stage is coherent and the neural network is not too large, so the whole optimization does not take too much time.

The very first stage, preceding the teaching of an NN, consists in optimization of the BTS.

In order not to lose ourselves, we will record the stage number in the input of the ATS identified as "pass". Identifiers of inputs corresponding with the stage number will and in the number equal to this stage number.

Thus, let's start preparations for optimization and teaching the NN. Let's set the initial deposit as $1000000 (in order not to create an artificial margin call during optimization) and the input to be optimized as "Balance" in Expert Advisor properties on the tab of "Testing" in the Strategy Tester, and start genetic algorithm.

Let's go to the "Inputs" tab of the EA's properties and specify the volume of positions to be opened by assigning the value 1 to the identifier "lots".

Optimization will be performed according to the model: "Open prices only (fastest method to analyze the bar just completed, only for EAs that explicitly control bar opening)", since this method is available in the ATS algorithm.

Stage 1 of optimization. Optimization of the BTS:

Set the value 1 for the input "pass".
We will optimize only inputs that correspond with the first stage, i.e., that end in 1. Thus, we check only these inputs for optimization, and uncheck all others.

tp1 - TakeProfit of the BTS. It is optimized with the values within the range of 10 to 100, step 1
sl1 - StopLoss of the BTS. It is optimized with the values within the range of 10 to 100, step 1
p1 - period of CCI used in the BTS. It is optimized with the values within the range of 3 to 100, step 1

Below are the results of the BTS optimization:


Stage 2. Teaching the perceptron responsible for short positions:

Set the value 2 (according to the stage number) for the input "pass".
Uncheck the inputs checked for optimization in the previous stage. Just in case, save in a file the inputs obtained at the previous stage.

Check the inputs for optimization according to our rule: their identifiers must end in 2:

x12, x22, x32, x42 - weight numbers of the perceptron that recognizes short positions. It is optimized with the values within the range of 0 to 200, step 1
tp2 - TakeProfit of positions opened by the perceptron. It is optimized with the values within the range of 10 to 100, step 1
sl2 - StopLoss of positions opened by the perceptron. It is optimized with the values within the range of 10 to 100, step 1
p2 - the period of the values of price difference to be analyzed by the perceptron. It is optimized with the values within the range of 3 to 100, step 1.

Let's start teaching it using optimization with a genetic algorithm. The obtained results are given below:

Stage 3. Teaching the perceptron responsible for long positions:

Set the value 3 (according to the stage number) for the input "pass".
Uncheck the inputs checked for optimization in the previous stage. Just in case, save in a file the inputs obtained at the previous stage.

Check the inputs for optimization according to our rule: their identifiers must end in 3:

x13, x23, x33, x43 - weight numbers of the perceptron that recognizes long positions. It is optimized with the values within the range of 0 to 200, step 1.
tp3 - TakeProfit of positions opened by the perceptron. It is optimized with the values within the range of 10 to 100, step 1
sl3 - StopLoss of positions opened by the perceptron. It is optimized with the values within the range of 10 to 100, step 1
p3 - the period of the values of price difference to be analyzed by the perceptron. It is optimized with the values within the range of 3 to 100, step 1.

Let's start teaching it using optimization with a genetic algorithm. The obtained results are given below:



Stage 4 (final). Teaching the first layer, i.e., teaching the perceptron that is in the upper layer:

Set the value 4 (according to the stage number) for the input "pass".
Uncheck the inputs checked for optimization in the previous stage. Just in case, save in a file the inputs obtained at the previous stage.

Check the inputs for optimization according to our rule: their identifiers must end in 4:

x14, x24, x34, x44 - weight numbers of the perceptron of the first layer. It is optimized with the values within the range of 0 to 200, step 1.

p4 - the period of the values of price difference to be analyzed by the perceptron. It is optimized with the values within the range of 3 to 100, step 1.

Let's start teaching it using optimization with a genetic algorithm. The obtained results are given below:


That's all, the neural network has been taught.

The ATS has one more non-optimizable input, mn - Magic Number. It is the identifier of positions for a trading system not to mix its orders with the orders opened manually or by other ATSes. The value of the magic number must be unique and not coincide with the magic numbers of positions that have not been opened by this specific Expert Advisor.

P.S.

  • The size of the initial deposit is found as the doubled absolute drawdown, i.e., we consider some safety resources for it.
  • The EA given in the source codes is not optimized.
  • If you need to replace the built-in BTS with the algorithm of another trading system, you must modify the contents of the function basicTradingSystem().
  • In order not to enter the initial and the final values and the values of steps for optimization, you can take the ready file combo.set, place it in the folder \tester MT4, and upload to the EA's properties in Tester.
  • Re-optimization of the EA is to be performed at a weekend, i.e., on Saturday or on Sunday, but only if the results of the preceding week were unprofitable. The presence of losses means that the market has changed, and the re-optimization is necessary. The presence of profits means that the ATS does not need any re-optimization and recognizes market patterns quite well.


27 comments: 1 2 3   To post a new comment, please, log in or register
warrismrazvi wrote:

i tried this combo for two weeks, pretty impressive in the beginning, many trades, but in last high floating account and then it just wipe out my demo account.

but i noticed that, every deals that were open on the evening and before the next morning was very good.

maybe you have a good ea, but it can make extreme losses on the bull and bear periods.

can you program a starttime and stoptime for trading on the ea and a automatic trailing stop?

This is exactly what shows in the backtest if you changed the Close[0] to Open[0]. And it should happen because the Close[0] can't be obtained. The patten should look like a zigzag line with a some good ups and many bad downs, in the best bet for a long run, the balance should be back to the original balance if not worse and it needs to be trained periodically.
13.05.2008 20:50 waigua2

i tried this combo for two weeks, pretty impressive in the beginning, many trades, but in last high floating account and then it just wipe out my demo account.

but i noticed that, every deals that were open on the evening and before the next morning was very good.

maybe you have a good ea, but it can make extreme losses on the bull and bear periods.

can you program a starttime and stoptime for trading on the ea and a automatic trailing stop?

13.05.2008 08:09 warrismrazvi
peen wrote:

Hi,

Which TimeFrame is best for this EA??

TIA

This EA can't be used in real trading, as I said, you will probably loose money for trading using this system. So it does not matter whichever time frame is going to use.

07.05.2008 00:36 waigua2

Hi,

Which TimeFrame is best for this EA??

TIA

06.05.2008 08:10 peen
lerned1 wrote:

Waigua2,

Close[0] is simply current price.  It's price without the spread.  He's not actually trying to predict the future.  He's simply checking the relationship between opening price and current price at any given tick.  My bet is that you are not familiar with Reshetov.  The odds of him making that basic of a mistake are very slim.  Hope this helps.

Have you read the link I gave in my first post? When I check the code from Close[0] to Open[0], the result is aweful. The reason why nobody can get Close[0] used for EA is that when using forward testing, EA can't make a decision when the bar is just opened in start(). The warning is that if "Close[0]" is predicted from Open[0] using whatever method outthere, the test by Reshetov gives the best performance possible IF Close[0] is correctly predicted.

So maybe you are right if this is the intention of the author of this system. So this EA is lack of a prediction component which "foresees" Close[0] accurately for real trading, but this system illustrates very well the idea of using feed forward NN in trading. For short term trading it seems that lagged price difference can be used. I only read some papers talking about using price percentage for trading long term with NN.

So, if anything needs to be added, one good regression method is needed to be added to replace Close[0] to finish the EA for real trading.

05.05.2008 22:35 waigua2

Was anybody successful in using this EA ? I have to admit that my results are not looking pretty. I might have missed something here. Can you use it on any pairs?

Anybody could explain further? Thanks P.

04.05.2008 21:01 avarrephil
waigua2 wrote:

Reshetov,

Thanks for the effort, but I notice in the code, you have made a big mistake, that in every perceptron, you have "Close[0]".

You CAN'T use Close[0] in the code, because you can't get it when "start()" is called when a new bar is opened. This is a serious mistake that will make the system only work in backtest, and loose real money in trading. So please don't use this system for living trading.

You can't see the future, because close[0] is in the future.

When Close[0] is changed to Close[1] or Open[0], the result is very bad. But if any correction is made, please let me know. Thanks!

There is a discussion about Close[0], which can be found here. Hope this helps.

Waigua2,

Close[0] is simply current price.  It's price without the spread.  He's not actually trying to predict the future.  He's simply checking the relationship between opening price and current price at any given tick.  My bet is that you are not familiar with Reshetov.  The odds of him making that basic of a mistake are very slim.  Hope this helps.

04.05.2008 16:49 lerned1

Reshetov,

Thanks for the effort, but I notice in the code, you have made a big mistake, that in every perceptron, you have "Close[0]".

You CAN'T use Close[0] in the code, because you can't get it when "start()" is called when a new bar is opened. This is a serious mistake that will make the system only work in backtest, and loose real money in trading. So please don't use this system for living trading.

You can't see the future, because close[0] is in the future.

When Close[0] is changed to Close[1] or Open[0], the result is very bad. But if any correction is made, please let me know. Thanks!

There is a discussion about Close[0], which can be found here. Hope this helps.

28.04.2008 01:17 waigua2
You cant read Neural network in the capital markets ,paul refenes,
30.03.2008 08:38 soros11
Thanks for the book reference Reshetov.
22.03.2008 10:08 avarrephil