This is a mid-term Expert Advisor based on defining two extreme points formed by indicators and comparing them to the price extreme values.
- Start_lot – the initial lot size. If the dynamic lot is disabled (risk=0), the lot size of orders is constant.
- risk – enable the dynamic lot with the specified risk level.
- MaxOrders_InOneSet - the maximum number of orders in one set. 0 - no control. Allows you to flexibly limit the total number of orders, while allowing all sets to open orders (at least one at a time).
- MaxOrders_InSymbol - the maximum number of orders for the current symbol (the sum of all sets). 0 - no control.
PartialCloseIfProfit_ATRs - partial closure. Close profitable orders if more than 3 orders within one set are open in the same direction and the price exceeded > PartialCloseIfProfit_ATRs.
These settings are sufficient for trading.
Expert Advisor Optimization
To improve trading, you can develop custom settings using optimization for a certain pair and write them to a plain text file:
"MetaTrader...\tester\files\DoubleExt.txt" - for testing, then copy to "MetaTrader...\MQL4\Files\DoubleExt.txt" - for trading.
The EA searches for the specified settings file and takes the basic ones from the code if none are found.
The following parameters allow configuring the EA.
- 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.
- Set_number – default is 0 (all sets). It is used to analyze a specific set, one of those written to the file.
- Indicator – analyzed indicator for defining extreme values: AO, RSI, CCI, Stochastic, MACD, RVI, WPR and Momentum.
- Ind_per – analyzed indicator period (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.
- TPSL_coef – take profit/stop loss ratio. Recommended values are from 1 to 10.
- 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.
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.
- 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.
After optimization and analysis, select the most suitable test results and copy paste them to the text file. Enter a currency pair name, at which a certain result has been achieved, at the start of each line in the file (for example, "eurusd") and press TAB (mandatory). These will be the sets, each of them working according to its own parameters. After optimization, save the file.
Set OptimizationMode=false, and the EA is ready to trade according to your settings. The video is attached below.
Find the additional description here (in Russian).
2) Added the MinDist_ATRs variable, which allows setting the minimum distance between orders in the same direction;
3) Added the BreakEven_ShiftPoints variable, which allows setting a breakeven equal to the opening price +/- [BreakEven_ShiftPoints] points.
4) The MagicNumber parameter is now available for editing.
5) Added the ECN variable (for certain account types, not necessarily for all ECN). Enabling the ECN mode allows opening orders without predefined TP and SL, and to modify them after the order is placed;
6) Expanded the customization of the information panel color scheme, set a transparent background;
7) Moved additional data to the information panel:
- Information on the number of trades;
- Information of the lot calculation;
- Information on MaxOrders settings;
- Information on MinDist and ClosePart.
8) Now, the information on the number of opened orders is displayed next to each set in the list. IF a set is only working for closing, «(Х)» is displayed.
9) If the minimum lot size allowed by the broker is more than twice the manual or calculated dynamic lot, orders will not be opened.
2. The following parameters have been added:
The maximum number of orders in one set. The default is 0 (no control). Allows you to flexibly limit the total number of orders, while allowing all sets to open orders (at least one at a time). Thus, the balance of all strategies is ensured (diversification effect).
The maximum number of orders for the current symbol (the sum of all sets). The default is 0 (no control).
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. In the earlier versions, this parameter had been hardcoded to 0.95.
Partial closure function. Close profitable orders if more than 3 orders within one set are open in the same direction. In earlier versions, the parameter was hidden. The closure of the most profitable order is triggered if the conditions are met:
- PartialCloseIfProfit_ATRs >0;
- the number of orders of one set opened simultaneously and in the same direction is greater than three;
- the distance of the most profitable order exceeds ATR*PartialCloseIfProfit_ATRs.
2. The names of the configuration files are supported: DoubleExt.txt (as in the description), Double Extremum.txt (the file name in the Market).