Double Extremum 2.8 - automatic medium-term advisor.

The expert's work is based on the definition of two extremums formed by indicators, and comparing them with price extremes. The algorithm for determining the extrema themselves is based on nested loops within which the division into zones occurs. For analysis, the last 40 bars are taken, this block is divided into two parts, each of which in turn is divided into 3 parts. The extremums found are numbered, the numbering is shifted by n bars, and then compared with the price. Comparison reveals divergence or consistency.

1.

To save the spread, as well as to optimize the number of orders, there is a function of checking and closing opposite orders. Its work is simple: when a signal to sell within the limits of a specific set appears, in the presence of purchase orders, the adviser instead of opening a position for sale closes one position for the purchase, choosing for closing the order with the higgest profit.

On the following bars, with the appearance of new sell signals, the buy orders will be close until they are exhausted, and only then will sell orders be opened.

2.

With multiple triggering of a signal and opening positions in one direction, orders accumulate more than usual at certain levels. On the one hand, a signal that has been repeatedly triggered is a high probability of making a profit; on the other hand, many orders are a risk. For such situations, there is a function of partial unloading, which works as follows (consider for example a buying).

On the current bar, the following conditions are checked:

Opened more than 3 buy orders within the one set.
For checking, is selected order, that have the highest profit.
If from the opening level the price has passed the distance greater than ATR * PartialCloseIfProfit _ ATRs, the order is closed.

At the next bar, the test is repeated.

Thus, the risk is reduced, while some profit is fixed.

3.

The situation described in point 2 occurs when there are a lot of sets (more than six). For limiting the number of orders used the function MaxOrders_InOneSet (the maximum number of orders in one set) and MaxOrders_InSymbol (the maximum number of orders for the symbol). The first option is preferable, since it allows the sets to open at least one order, which ensures a greater flattening of the equity growth line.

4.

Also, to achieve the most smoothened growth line of Equity, we use a combination of several systems, or instruments that are weakly correlated with each other. So that when a system or tool are in a state of drawdown, others can compensate for it.

This effect is achieved by introducing several different sets in one symbol. Sets are those most advantageous combinations of parameter values ​​that we see in the optimization results.

If you want to improve trading, you can create your own settings by optimizing for a particular pair (select up to 20 best results for each pair, preferably in them periods of downs and downs do not correlate with each other).

It's like a recruiting. The command usually requires: one with a certain property, second with a different property, the third with a third property that is not inherent in the first and second. In practice, the selection of sets, this means the selection of minimally correlated with each other, but at the same time profitable strategies. Drawdown of one set in a single period is compensated by a good growth of another set, and vice versa. Even if the instrument as a whole has a drawdown (you will not believe, but it happens :), then other tools will give good results, and the overall equity (for all instruments) will be quite stable.

Having found such sets, it is enough to write them in a plain text file:

- "MetaTrader ... \ tester \ files \ DoubleExt.txt" - for testing, then copy to

- "MetaTrader ... \ MQL4 \ Files \ DoubleExt.txt" - for trade .

After pasting in front of each line, write down the name of the instrument (without prefixes and endings, ie 6 characters) and press TAB (required).

The Expert Advisor searches for the specified configuration file, then searches the file for lines beginning with the name of the tool on which it is currently running, extracts the values, and writes them to the array.

If the EA does not find the file, or in the file does not find a single set on the tool, it takes the base values ​​from the code.

Therefore, as an option, you can comment out individual lines in the file by setting any character before the line (eg "-", it will be "-eurusd ") if you do not want to use them in the trade.

In order not to delete the file, you can rename it in the same way as above, and then all the sets will be taken solely from the code. Remove "-" before the name - and the trade will be done again with the sets from the file.

At trade or at visual testing the comment on which it is possible to define, whence he takes sets is deduced:

"Advisor in working mode. The settings for trading are taken from the CODE (or "FILE").

Now we proceed to describe the parameters of the advisor.

• Start_lot -initial lot. If the dynamic lot is switched off (risk = 0), the adviser will issue orders with a constant lot, determined by this parameter. When dynamic lot is enabled (risk > 0), Start_lot determines the initial lot size, from which its value will grow.
• risk - the inclusion of a dynamic lot with a given level of risk. To have an idea of ​​profit and drawdown, the risk value is better to pick up experimentally in the tester. Recommended 3. The lot size does not decrease when several losing trades are closed, enabling the following profitable trades to restore the balance with the same chance. The last lot size is stored in the global variable (Lots_581978359). When withdrawing money, this variable must be manually reset.
• MaxOrders_InOneSet - Maximum number of trades in one set. The default is 0 (no control). Allows you to flexibly limit the total number of orders, while allowing you to open trades (at least one at a time) to all sets. Thus, the balance of all strategies is ensured (the effect of diversification).
• MaxOrders_In Symbol - The maximum number of trades for the current symbol (the sum of all the sets). The default is 0 (no control).
• MinDist_ATRs - Distance between two transactions of one direction in ATRs, not less than (0 - disabled). Upon receipt of a signal to open a trade, the function checks whether there are transactions of the same direction at a distance of MaxDist_ATRs from the current price. If such transactions are exist, the signal for opening a new transaction is ignored. Thus, there will not be excessive accumulation of orders at the same level. This function, like the two previous ones, reduces the number of transactions.
• PartialCloseIfProfit _ ATRs - Function of partial closure. Closing of profitable orders, if more than 3 are opened in one direction by a whole symbol. Closing the most profitable order is triggered if the following conditions are met:
• PartialCloseIfProfit _ ATRs > 0 ;
• At the same time, there are more than three open orders in one direction;
• the price of the most profitable order went to a distance greater than ATR * PartialCloseIfProfit _ ATRs.

These settings are sufficient for trading.

Parameters for the Advisor 's optimization

• OptimizationMode - enable/disable optimization mode. If OptimizationMode is enabled, the ForPeriod, Indicator, Ind_per, i3, i4, SL_ATRs, TPSL_koef, BreakEven_ATRs, TrailDist_ATRs, CoefExpr parameters are optimized. The best test results are placed in the specified text file (by means of a copy-paste), and from there, when the OptimizationMode is off, the EA takes the parameters when trading.
• ForPeriod - chart period (timeframe), for which the optimization is performed.

When trading, when the test results are placed in a file, it is necessary that the adviser be placed on the chart with the least timeframe from the prescribed ones.

• Set_number - default 0 (all sets). Used to analyze a specific set, one of those recorded in a file. Up to 20 sets can be written for one currency pair, for different timeframes, which will work each according to their parameters, but it is enough to install an adviser on one chart (with the smallest timeframe).
• Indicator - Analyzed indicator for the determination of extremes: AO, RSI, CCI, Stochastic, MACD, RVI, WPR, Momentum.
• Ind_per - the period of the indicator being analyzed (not relevant for AO).
• i3 - method of defining a double decreasing top. It varies from 0 to 3 (see the image below).
• i4 - method of defining a double increasing top. It varies from 0 to 3 (see the image below).

• SL_ATRs - initial stop loss level in the number of averaged candles. Here and further below, the size of an average candle for the tested timeframe is defined by ATR(200) indicator. Recommended values are from 5 to 10. You can try other values (10-20).
• TPSL_coef - take profit/stop loss ratio. Recommended values are from 1 to 10. You can try other values (0.5-2 or 10-20).
• BreakEven_ATRs - breakeven level in ATRs. Recommended values are from 1 to 10.
• TrailDist_ATRs - trailing distance in ATRs. Recommended values are from 1 to 10.
• BreakEven_ShiftPoints - setting a breakeven equal to the opening price +/- [BreakEven_ShiftPoints] points.
• Coef_expr - expressiveness of the double extremum - the ratio of the lowest High to Low, to start the pattern validation. The smaller the coefficient, the more expressed the pattern and the less likely it is to be found. Recommended optimization range: from 0.55 to 0.95. Default is 0.95.

• ShowProfitInfo - show/hide data on the EA's current trading results.

If BreakEven exceeds TrailDist, trailing does not start till the price breaks the BreakEven level. In other words, BreakEven restrains trailing.

If BreakEven is less than TrailDist, an order is moved to breakeven when the price reaches the BreakEven level. This level remains unchanged till the price breaks the TrailDist level. After that, the trailing starts.

At once it is necessary to note that the advisor is working on closing the candle, and the test results for each tick practically do not differ from the test results at the opening prices. A few screenshots:

What can I do from five hundred in EURUSD:

Risk 0

Risk 7

Other pairs (from \$ 500, risk 0):

The result of overlaying the test results of the first six currency pairs:

As you can see, the periods of drawdown by one pair are compensated by the growth of others.

Combine test results for 13 currency pairs in the ReportManager:

Risk 0:

Risk 3:

The advisor is not demanding on the spread and the speed of execution of transactions, and the test results practically coincide with the results in real trading.

It is also important, that the "adapting to result" effect is minimized. Try forward testing, and see for yourself. If a particular instrument is not suitable for trading an expert advisor, then the optimization results will be weak, and vice versa.

The ascetic information panel:

It should be noted that the optimization procedure is not required at all (by the end of 2018).

Enough to load the Expert Advisor, open the charts on the timeframe M30 for EURUSD, GBPUSD, USDJPY, USDCHF, USDCAD, AUDUSD, NZDUSD, EURGBP, EURJPY, GBPJPY, GBPCHF, EURCAD, EURAUD, drag-n-drop an adviser on them, and establish the level of risk.

Yes, and do not forget about the three rules of successful trading:

Version 2.7 is available in the Market from 29 Jan 2018. The attached file is the settings that the Expert Advisor is trading. With or without file, the EA trades in the same way, because the settings in the code match the settings in the file. But if you upload and modify this file (adding or deleting / commenting out some of the sets), you will change the trading as you see fit.

Files:
Share it with friends: