Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

Gold Dust - MetaTrader 5 Expert | Gold EA Download - MT4/MT5 Resources

author EAcpu | 3 reads | 0 comments |

Gold Dust - expert for MetaTrader 5

Gold Dust - expert for MetaTrader 5

Idea by Yuri Reshetov

mq5 code author - Bara Bashkakon

Gold Dust - expert for MetaTrader 5

A little theory

To determine the likelihood of overfitting, you can use so-called classic forward testing, which is described in Robert Pardo's book [1]. The idea of ​​the classic method is as follows: select two disjoint historical intervals for the trading system. The trading system is optimized in one of the intervals and in the second interval performs a forward test of the parameters optimized in the first interval. If the test in the second (forward) history interval is unsuccessful, the trading system is considered over-optimized and not suitable for automated trading. If the forward test gives positive results, additional analysis is performed to check the behavior of the trading system during the test interval - this analysis allows the identification of system characteristics.

But a system that can pass all the tests described in Robert Pardo's book [1] does not actually exist. Therefore the author does not give specific examples. Optimization in one interval and forward testing in different intervals and further analysis of the forward testing do not provide any guarantees:

Since the classic method of checking a trading system has many shortcomings, I developed and tested another method that I consider more reliable: gold dust .

The difference between the new method and the classic method is that the optimization of the trading system is not carried out in one interval, but in two or more intervals. Therefore, we obtain a different set of trading system parameters for each interval. Some of them are the same, others are different. It may be that some of these parameter sets are over-optimized and others are not. This can be found through forward testing.

What can this bring?

Here we need to determine the robustness of the trading system. Trading systems may be potentially robust, i.e. their probability of passing forward testing in classical methods is higher than zero, and not robust, i.e. the probability of overfitting is very high.

We will not consider non-robust trading systems here because even if their signals are filtered based on consistency, the results of non-optimized intervals are not stable enough to trade. Such a trading system is more suitable to try.

Let's move on to a powerful trading system, which can be found in the attachment. The trading system is based on predictions of future price direction, implemented by selecting the weight coefficients of a basic single-layer neural network (perceptron based on historical data) using the standard MetaTrader Strategy Tester genetic algorithm.

Optimization, testing and robustness detection methods of trading system parameters

We will use EURUSD historical data for the past 9 months or more in the first half of the year time frame. Let us divide the entire period into three separate intervals, each separated by three months. The first interval will be used for final testing and the other two intervals will be used for historical optimization. I combined the two perceptrons into a trading system so I don't need to start the system separately each time.

The Supervisor() switcher function in the EA code enables three modes of EA operation, depending on the "pass" input parameter:

The following weight coefficients of the perceptron are being optimized: x11, x12…x42, as well as MA: average period and stop loss . This stop input parameter is constant for all intervals. This is the stop loss level for all open positions. Another input parameter MA: Average Period represents the lag period of the opening price difference; it is also constant.

Market entry is performed at the beginning of the formation of a new bar, i.e. the opening of the bar based on the sensor signal, depending on the value of the bar passing through the range. Exit is executed only via Stop Loss. Optimization is performed using a genetic algorithm, which searches for extreme values ​​(i.e. the maximum equilibrium in our case).

To avoid the impact of margin calls on the algorithm, the initial amount should be large, such as $1,000,000.

In the first stage , we need to determine

Enter values ​​for MA: average period and stop loss variables. For this purpose, we select the last two historical intervals, from 6 months ago to today. Set all parameters of the perceptron weights from Start = 0 to Stop = 100 in steps of 10. MA: The average period is from Start=3 to Stop=100, with a step size of 10; the value stop loss is from Start=10 to Stop=75, with a step size of 10. Value passed = 1. Select optimization parameters: x11 , x21 , x31 , x41 , MA: average period and stop loss . All other checkboxes should be disabled. Start optimizing. Then enter the parameter values ​​based on the optimal channel settings.

The second stage . Optimize the first perceptron weight in the second historical data interval. Set the optimization date and time from 6 years ago to 3 months ago. Remove the checkbox MA: Average Period and Stop Loss . Start optimizing. Then enter the parameter values ​​based on the optimal channel settings. This elapsed value remains 1.

The third stage . Optimize the second perceptron weight in the third historical data interval. Set the optimization date and time from 3 months ago to today. Remove the selections x11 , x21 , x31 , x41 from the parameters and select x12 , x22 , x32 and x42 . Other parameters should be disabled. Put passed =2. Start optimizing. Then enter the parameter values ​​based on the optimal channel settings.

The fourth stage . The trading system has been optimized for the past six months of historical data. Save the values ​​of input parameters to the configuration file. Set the passed input variable to 3. Now we need to check the robustness of the system, i.e. the input parameters are not overfitted and the probability that they may show profits during non-optimized time periods. So now, we set a date between 9 and 6 months ago (no optimization is done in this range) and test it.
If the test result is negative (failed) in mode 3, then we most likely find that the coefficients of both perceptrons are overfitted. In this case, we need to optimize again to obtain other values ​​of the sl and p parameters of the first stage - the possible cause of the loss may lie in these parameters. Another reason for failure may be a small number of trades in the first and second optimization phases (the number of trades should not be less than 100) - in this case, the maximum stop loss range of the sl parameter should be reduced.

If the fourth phase is successful, then we can assume that either the first or the second perceptron, or even both of them, can generate profits outside the optimization interval and therefore can be used for trading. Now we need to select the perceptron. To do this, we set the dates from 9 months ago to the current date and run the EA test in the following mode: after 1 and 2.

The model with better results is likely to be the one with less overfitting and is considered suitable for trading. Switch the EA to this mode and save the EA settings to a file. Then run the EA on the chart, set the timeframe to H1 and load the settings from the previously saved file.

Of course, to ensure that this method of testing the robustness of a trading system is indeed effective, all historical data intervals should be moved deep into history in order to obtain an extra interval and test the parameters we set within that interval.

The above method of determining the robustness of a trading system is not simple. But compared to the classic method described in Robert Pardo's book [1], it is much simpler and in most cases more reliable, since it eliminates the almost useless and resource-consuming analysis of trading systems after forward testing.

Reference list

1.Robert Pardo. Design, testing and optimization of trading systems. - Minax, 2002. - 224 pages. ISBN 5-902270-01-4


Attachment download

📎 gold_dust.mq5 (72.74 KB)

Source: MQL5 #23220

Verification code Refresh