Closing unprofitable positions by identifying and closing profitable ones. The Expert Advisor (EA) is designed to close unprofitable positions by identifying…
Partial Close and Trailing. Partial closing of positions on rollbacks
Close Minus by Plus, Closing unprofitable positions by searching and closing profitable positions
Table of Contents (click to show)
List
- Description
- Start Step Stop
- Preparing for Optimization of the Expert Advisor
- Customizable Parameters for Optimization
- Block 1: Trade Signals and Filters
- Block 2: Signal Options
- Block 3: Opening Filter Options
- Block 4: Close Options
- Block 5: Pending Orders Options
- Block 6: Trading Options
- Block 7: Stops Options
- Block 8: Lots Options
- Block 9: Averager Options
- Block 10: Additional Opening
- Block 11: BreakEven Without Loss Options
- Block 12: Standard Trailing Options
- Block 13: Trailing Stop by SAR
- Block 14: Time Trade Options
- Block 15: CloseALL When Profit or Loss Options
- Options for Calling OnTester_Custom_max:
- Conclusions
- Questions?
Description
The X and The xCustomEA are two standout Expert Advisors (EAs) in the Forex trading community, gaining widespread popularity over the past five years. These tools are designed to cater to traders who want to customize their trading strategies and focus on testing and optimization to enhance performance and adapt to varying market conditions.
Key Features:
- The X: This EA is a comprehensive strategy builder that allows users to create trading strategies using standard MetaTrader indicators. It includes over 20 signal options and a variety of filters, making it an adaptable tool for any trading style.
- The xCustomEA: Taking customization a step further, this EA enables traders to develop strategies based on iCustom indicators (iCustom), providing even more flexibility in trading strategies. This means you can incorporate any custom indicator into your automated trading.
Why Choose The X and The xCustomEA?
- Versatile and Adaptive: Both advisors can be used across multiple currency pairs, timeframes, and market conditions, offering traders endless possibilities for strategy development.
- No Coding Required: While the tools are highly customizable, they are designed for easy use, even by those with no programming background. Simply select your indicators and parameters, and let the EAs do the rest.
- Advanced Functions: Both Expert Advisors come with advanced features like dynamic lot sizing, trailing stops, break-even levels, and more. Whether you are a beginner or a seasoned trader, these functions allow for precise risk management and trade execution.
Flexibility
With The X, you can craft a strategy from the standard MetaTrader indicators, while The xCustomEA allows you to integrate your custom indicators, giving you the power to truly personalize your trading strategy.
These EAs offer the complete package for anyone looking to automate their trading strategies, maximize potential, and make informed decisions based on sophisticated technical analysis.
We will not talk about how to test or optimize the Expert Advisors (EAs) in the terminals MT4 and MT5! We already discussed this in our article: Testing and Optimizing Expert Advisors.
In this article, I will show you some ways to optimize the Expert Advisor and the right functions to work with an Expert Advisor.
We have created several sets of optimization settings for you so that you can start optimizing on your computer.
Starting with version 18.008, we assigned the same names to all variables in both the MT4 and MT5 versions. This is done so that you can transfer configuration files from one terminal to another!
We will show examples of trading strategies based on THE X.
Remember: The X or The xCustomEA is a designer for trading strategies. By grouping and applying different combinations of functions, you can achieve different results.
You must understand that miracles do not happen. Our Expert Advisors (EAs) are just instruments for trading on Forex. Forex trading involves 100% risk!
EA The xCustomEA Universal Trading Expert Advisor (EA) on iCustom indicators.
The X – Universal Expert Advisor (EA) for Forex on standard indicators.
The functional features of the Expert Advisors and the description of the settings were already covered in our article The X – Universal Advisor for Forex MT4 MT5 Full Instruction.
In this article, we will discuss how to optimize the parameters of the Expert Advisor and achieve the desired results.
We will cover testing methods, the selection of optimization strategies, and the inclusion of various functions for Forex trading.
Start Step Stop
The set of settings depends on your deposit and the drawdown limit, currency pair and contract specifications, and whether you are engaging in long-term trades or pipsing!
Here and below I will use these values:
0-10-100 = means that the parameters for optimization are:
- Start optimization value = 0
- Parameter optimization step = 10
- Stop parameter value for optimization = 100
All parameters that are measured in Points (Pips) (Stop Loss, Take Profit, Distance, etc.) are based on 4-digit quotes.
- For example, EURUSD = 1.2001 means that the broker has 4-digit quotes. And 1 = 1 point!
- If I write 10, it means that I have 10 Points (Pips) in mind.
- If your broker has 5-digit quotes, then you need to multiply my recommendations by 10!
- For example, EURUSD = 1.20015 means that the broker has 5-digit quotes. And 1 = 1 point!
- If I write 10, it means that I have 10 Points (Pips) in mind. But you must set the values to 100.
Remember the answer to the question!
What are the values in the parameters in points or pips?
In points! The value is derived from the Point variable.
- If you have a 5 or 3-digit broker, then 1 point = 0.00001 or 0.001
- If you have a 4 or 2-digit broker, then 1 point = 0.0001 or 0.01
Preparing for Optimization of the Expert Advisor
Our Expert Advisors (EAs) share the same signal and function algorithms.
However, because of the differences between the terminals MT5 and MT4, there may be performance discrepancies.
The strategy tester in the MT5 terminal is currently the most technologically advanced and accurate.
The most important feature of the MetaTrader 5 terminal and Strategy Tester is the ability to test on real ticks. The spread and stop levels in MetaTrader 5 are floating, which means that testing in the MT5 strategy tester is as close as possible to live trading.
We will not explain testing and optimization in the MetaTrader 4 terminal! You already know how to test it. The optimization process is similar to the MT5 process (Settings and Startup).
But the main feature of the strategy tester in MT5 is, of course, the ability to optimize in the cloud MQL5 Cloud Network.
The cloud allows optimizing the Expert Advisor (EA) using thousands of other computers at a minimal cost. It’s very affordable and fast. Therefore, I highly recommend using MQL5 Cloud.
In the archive with the Expert Advisor, you will find several files with optimization settings. These are just examples, but they will show you how to configure optimization.
Remember: Each currency pair and broker have their own trading conditions (Spread, swap, commission, settlement method, execution, account type), so the optimization results may differ!
To make the results more consistent, you need to turn off Random Delay. It is not required for optimization!
Setting up the Strategy Tester:
- Select an Expert Advisor from the list.
- Set the currency pair for which you will conduct the test.
- TF: It is better to choose M1. (The TimeFrame will be set by the Expert Advisor from its settings)
- Optimization date: You can select the current year! Remember, past results cannot guarantee a profit in the future! Optimizing every half-year is the most practical range!
- Forward can be set to 1 month, but we advise obtaining clean results first. Then, we will carry out the Forward Test.
- Deposit: It is better to set the deposit you will start trading with. Do not set too small a balance, and not too large either!
- Leverage: Set the leverage you will be trading with.
- Optimize the Slow Complete algorithm.
- And be sure: “Every tick, based on real ticks”!
Configuring Expert Advisor Settings:
- Click the Inputs tab and load our Set file.
- Check or uncheck the options you want to optimize. (By default, I set up the file so that you can optimize all important parameters)
- Value—This is the fixed value of the parameter. The Expert Advisor will use this value if this parameter is not optimized or during testing!
- Start – The initial value of the parameter for optimization.
- Step – The step by which the parameter changes each time the optimizer runs.
- Stop – The final value of the parameter for optimization.
- Remember! The more parameters and steps for optimization, the more time is needed to complete the testing and optimization!
Enable Cloud Optimization
I highly recommend enabling cloud optimization!
In this case, I disable the use of my processor, so my computer does not slow down during optimization. Additionally, the cost of one pass in the cloud is less than 0.01 cents!
Press the START button and continue with your tasks!
Customizable Parameters for Optimization
You can download our files for optimization for The X.
Block 1: Trade Signals and Filters
In our Expert Advisors (EAs), more than 20 trading strategies are based on the standard indicators of the MetaTrader terminal.
Why Do We Use Standard Indicators?
All user indicators almost entirely replicate the standard indicators that are already in the terminal.
By changing the parameters within the code, you create a custom indicator. Logically, the custom indicator is composed of 90% standard indicators!
We have written more than 5,000 Expert Advisors (EAs) using custom indicators, and we can confidently say that it does not make sense.
Working with standard indicators is predictable and, in 90% of cases, more profitable.
Therefore, we use standard indicators for trading. Read examples of opening positions based on standard indicators, as well as a description of signals, in the article: Examples of Signal Operation!
Indicators and signals are the main elements to consider when starting our optimization and testing!
At the time of this writing, we have 20 signals:
- NoSignal = 0, // No Signal
- Ma = 1, // Moving Average
- MACD = 2, // Moving Average Convergence Divergence (MACD)
- STOCH = 3, // Stochastic Oscillator
- RSI = 4, // Relative Strength Index (RSI)
- CCI = 5, // Commodity Channel Index (CCI)
- WPR = 6, // Williams Percent Range (WPR)
- BB = 7, // Bollinger Bands
- Envelopes = 8, // Envelopes
- Alligator = 9, // Alligator
- OsMA = 10, // Moving Average of Oscillator (OsMA)
- AO = 11, // Awesome Oscillator (AO)
- ISH = 12, // Ichimoku
- AC = 13, // AC
- BAR = 14, // BAR BEAR \ BULL
- ADX = 15, // Average Directional Index (ADX)
- ADXWilder = 19, // ADX Wilder
- ZigZag = 17, // ZigZag
- MFI = 20, // Money Flow Index (MFI)
- Fractals = 21, // Fractals
Each signal and strategy is the standard strategy for using the indicator. Such strategies were developed by the creators of these indicators. We will not explain the entire purpose of each strategy.
These are standard trading strategies!
You will have 100,000,000 options for using the standard indicator, but you also understand that we cannot add them to the Expert Advisor!
If you wish to write your strategy or Expert Advisor (EA) on your indicator, then you need open-source code:
- Open source The X for MetaTrader5 (Currently unavailable)
- Open source The X for MetaTrader4 (Currently unavailable)
- Programming the Expert Advisor: 10 Steps to Success!
In our Expert Advisor, you can combine one signal and up to five filters.
Signal and Filter Difference:
Signal
- Signal — occurs when all conditions for the signal are met, for example, the intersection of MA lines or the appearance of a new ZigZag point.
- For example, the intersection of level 70 for the RSI indicator is a signal. If the RSI is above the level of 70, then this is already a filter.
- The signal is what appears when the quotes are received, fixed on the bar. The Expert Advisor (EA) accepts the signal.
- For example, the light turned on. This is a signal because the light has just turned on. When you turn on the light, the person wakes up. It’s a signal.
- Opening positions occur after the signal is confirmed. The lines intersect, and then the position opens. If the lines were crossed earlier, this is not a signal; the signal has already passed.
Filter:
- Filter – This is the current position of the indicator, for example, the current position of the MA lines relative to each other or the current last vertex of ZIGZAG.
- The filter is what the indicator shows at the moment. This is not a signal. This is the current position of the indicator.
- For example, the light was on. This is a filter because the light has already been turned on and is currently on. When the light is on, the person no longer sleeps. This is a filter.
- Signals are filtered based on the current value of the indicator. If the Fast MA is above the Slow MA, then only BUY positions should open with this filter.
Tips for Optimizing Signal Parameters:
string Signal1s = "========= OWN Signal options ========="; typesignals IndSigToTrade = 1; ENUM_TIMEFRAMES TF_IndSigToTrade1 = PERIOD_CURRENT; bool Signal_Reverse = false; bool ClosePositionifChangeOWNSignal = false; int OWNSIGNAL_shift = 1; string Signal2s = "========= Filter 1 options ========="; typesignals2 FILTER_IndSigToTrade1 = 0; ENUM_TIMEFRAMES FILTER_TF_IndSigToTrade1 = PERIOD_CURRENT; bool Filter1_Reverse = false; int FILTERSIGNAL1_shift = 1;
We advise you not to use more than two filters for the signal, so we have hidden the other three filters at the bottom of the settings table.
This is because each filter reduces the number of signals. If you use more than two filters, the signals will become very rare.
Why did we create five filters?
During the programming and creation stage of the Expert Advisor (EA), our initial users provided us with a “wishlist” of features and requests. We fulfilled these requests and created five filters.
Variants of Signal Block Optimization
IndSigToTrade parameter can be optimized! There will be 20 options for this parameter. It’s not many, but you can choose the best result for this or that strategy.
Optimization of values: 1 – 20 or Moving Average – Fractals
Parameter TF_IndSigToTrade1 can also be optimized. However, we advise you to set the TimeFrame to the one you usually trade on.
- Remember: The higher the TimeFrame, the fewer signals will appear. The higher the TimeFrame, the longer the strategy will be.
The Signal_Reverse parameter is used to invert strategies! Sometimes, a trade becomes more profitable when we reverse a strategy.
It makes no sense to optimize.
- However, to include this parameter, I recommend only long-term trades and the use of large Stop Loss and Take Profit.
- If you use lossless and trailing stops and incur a loss within the spread, you will not be able to trade profitably by enabling this parameter!
- For example, if your strategy includes Stop Loss = 2000 Points (Pips) and Take Profit = 500 Points (Pips), you will have 100 losses and 1 profit.
- When you invert the strategy, you get 100 wins and 1 loss.
- But it’s all relative. Every theory needs to be tested! Miracles do not happen!
Parameter ClosePositionifChangeOWNSignal allows the closing of open positions when the primary signal changes.
It makes no sense to optimize.
- This option can be used to immediately cut off false signals.
- For example, suppose you do not use averaging (displaying a series of trades in the total profit) and accept that some signals will be false, resulting in an instant loss when closing on a signal. In that case, you can enable this function.
The OWNSIGNAL_shift parameter is very important! It regulates the reception of a signal from a closed or current bar.
It makes no sense to optimize.
- I recommend leaving it at the default setting.
- 1 – Receiving signals from an already closed and fully formed bar.
- 0 – Receiving a signal from the current bar, which is still being generated.
- A detailed article on how to use the SHIFT signal.
Parameters Filter N options have the same logical explanations as signals. Therefore, we will not repeat them, but we state the following:
- You can use filters of other indicators that are different from the signals.
- You can use the same indicator as in the signal but set the TimeFrame higher than the TimeFrame of the signal. For example, TF signal = M15, and TF filter = H1.
- The filter reduces the number of signals and open positions.
- One filter may not work with another signal. It all depends on the strategies you set up. Some filters and signals can conflict with each other.
- For example, the Moving Average shows a BUY signal, while the RSI Filter shows only SELL at that moment. Such conflicts have been encountered.
- If you do not open a position using a filter, turn off the filter and investigate this issue. Perhaps two indicators are conflicting.
Block 2: Signal Options
In this block, we added parameters that can help in fine-tuning the block of signals.
These parameters are auxiliary, and I do not recommend optimizing them.
bool Show_alert_without_opening_positions = false; bool OpenBarControlOnly = false; bool ControlNewBarforSIGNAL = true; bool ReverseSignal = false;
Parameter Show_alert_without_opening_positions allows turning off the actual opening of positions. Instead, the Expert Advisor (EA) displays information on the screen when a signal arrives.
It makes no sense to optimize.
- The Expert Advisor (EA) does not open the position.
- Information about the signal with calculated parameters is displayed.
- You can turn the opening of positions for this signal on or off.
The parameter OpenBarControlOnly is used only for the testing model in the form of Open Prices Only.
It makes no sense to optimize.
- This allows the Expert Advisor (EA) to operate on open bars on the real chart.
- When this parameter is enabled, the Expert Advisor‘s entire algorithm is executed only once when a new bar is opened.
- The results when you enable this option are similar to the results of testing in the Open Prices Only mode.
Parameter ControlNewBarforSIGNAL – Parameter that includes signal processing only once on a new bar.
It makes no sense to optimize.
- It allows you to significantly reduce the load on your computer while optimizing the Expert Advisor (EA).
- Increases testing speed in the strategy tester.
- Used only for SHIFT > 0.
Parameter ReverseSignal – inverts the general signal for opening positions.
Optimization of values: True – False
- Unlike Signal_Reverse, you can reverse the main signal for opening, including signals and filters.
Block 3: Opening Filter Options
This block contains parameters that allow you to filter the opening of positions based on technical limitations.
string oo_121 = "========= Opening Filter options ========="; TypeTrade TypeTradeBUYSELL = 0; int MinuteToOpenNextPosition = 0; bool OpenOppositePositionAfterStoploss = false; bool OnlyOnePosbySignal = true; bool OnePosPerDirection = true; bool OnlyOnePositionPerMagic = false; bool OnlyAlternateSignals = false; int MAX_BUY_POSITION = 0; int MAX_SELL_POSITION = 0; int MaxSpreadToNotTrade = 0; int MinSpreadToNotTrade = 0;
Parameter TypeTradeBUYSELL – includes the ability to trade only in one direction.
It makes no sense to optimize.
- It is useful when you manage the Expert Advisor (EA) manually, for example, when analyzing the news.
- Or when you use additional means to determine the signals, for example, trend lines.
- I recommend this feature only when you are sure that the trend has direction.
Parameter MinuteToOpenNextPosition – prohibits the opening of an additional position on the signal.
It makes no sense to optimize.
- It allows you to fine-tune the trading settings on signals when the trader is confident in the strength of the signal.
- Used with OnlyOnePosbySignal = false.
- Limits the opening of positions on the same signal.
Parameter OpenOppositePositionAfterStoploss – opens the opposite position if the previous position was closed by stop loss (in loss).
It makes no sense to optimize.
- This is an experimental option and can only be used by a trader who understands the essence of their work.
Parameter OnlyOnePosbySignal – allows the Expert Advisor (EA) to open only one position for the selected currency pair and magic number.
You can set this parameter to True or False when using OnePosPerDirection = true.
- Turning off this function allows you to “dial” positions on the same signal in the same direction.
- I do not recommend changing this parameter.
Parameter OnePosPerDirection – allows the Expert Advisor (EA) to open positions in only one direction or includes the possibility of trading in two directions at once.
It makes no sense to optimize.
- Works only when OnlyOnePosbySignal = false.
- I do not recommend changing this parameter.
The OnlyOnePositionPerMagic parameter allows you to control the open positions of all Expert Advisors (EA) that have the same MAGIC.
It makes no sense to optimize.
- Works only when OnlyOnePosbySignal = false.
- I do not recommend changing this parameter.
The parameter OnlyAlternateSignals – allows you to open positions only in the opposite direction from the last closed position.
It makes no sense to optimize.
- It significantly reduces the number of signals.
- I do not recommend changing this parameter.
Parameters MAX_BUY_POSITION and MAX_SELL_POSITION – allow you to limit the number of simultaneously open deals (positions).
It makes no sense to optimize.
- Works only when OnlyOnePosbySignal = false.
- I do not recommend changing this parameter.
- This parameter is created for trading in different directions without limiting the number of signals.
- It allows you to limit the simultaneous opening of positions on one signal or find open positions in the market.
Parameters MaxSpreadToNotTrade and MinSpreadToNotTrade allow you to limit the opening of positions on a signal when the broker frequently changes the spread.
It makes no sense to optimize.
- I do not recommend changing this parameter.
- These parameters should be set only on a real chart.
- They allow you to limit the signals during important news releases and sharp jumps in the spread, where the Expert Advisor (EA) can set large stops.
Block 4: Close Options
This block contains parameters that allow you to close positions in certain situations.
input string oo_123 = "========= Close options ========="; input bool ClosePosIfChange = true; input bool CloseChangeOnlyInProfit = true; input int ClosePosition_After_X_Minutes = 0;
Parameter ClosePosIfChange – closes the opposite position when changing the signal to open.
Optimization of values: True – False
- It is useful when you want to change the current signal if it turns out to be false or when a new signal appears.
- It allows you to fix a profit or loss when changing the signal from the indicator.
Parameter CloseChangeOnlyInProfit – allows you to close only profitable positions.
If a signal is received to open the opposite position, it will be closed only when the current position is in profit.
Optimization of values: True – False
- It allows you to lock in profits when changing the signal from the indicator.
- Works only with ClosePosIfChange = true.
Parameter ClosePosition_After_X_Minutes – closes the position after a certain time.
Optimization of values: It is recommended to set the numbers that are multiples of your TimeFrame (TF).
For example, when using the Expert Advisor (EA) on TimeFrame M15, set the values: start 0, step 15, stop 75.
- To tightly fix the time when the Expert Advisor (EA) is allowed to trade.
- It allows you to close positions that were opened by the signal. For example, 15 minutes after the opening.
- Depends and works on the CloseChangeOnlyInProfit parameter:
- If CloseChangeOnlyInProfit = true, then the positions are closed if they have a profit.
Block 5: Pending Orders Options
In this block, the parameters for managing pending orders are described.
input StopOrderType StopOrderUSE = 0; input int StopOrderDeltaIfUSE = 0; input int StopOrderDayToExpiration = 0; input int StopOrderBarToExpiration = 0; input bool ReInstallStopOrdersNewSignalAppears = true;
Parameter StopOrderUSE – allows you to open pending or limit orders instead of positions.
Optimization of values: False – Use Stop Orders.
- It allows you to filter the signals by the operating distance additionally.
- Use Stop Orders: If the Expert Advisor (EA) receives a signal and we open a pending order at a distance of 100 points (pips), if the price has passed 100 points (pips) in our direction and triggered the pending order, then the signal is considered confirmed.
- Use Limit Orders: If the Expert Advisor (EA) receives a signal and we open a limit order at a distance of 100 points (pips), if the price has passed 100 points (pips) in the opposite direction and triggered a limit order, then the signal is considered a rebound. It is best to ensure that there will be a rebound.
- I do not recommend optimizing for Use Limit Orders.
- The value of Use Stop Orders makes sense only for long-term trading.
Parameter StopOrderDeltaIfUSE is the distance to the pending stop or limit order.
Optimization of values: It is recommended to set the parameters individually for each pair.
- For example, if this is the EURUSD currency pair and you trade on the M30 timeframe. The average price movement in the period, for example, 50 bars = 7500 points (pips), then set this parameter for optimization as start 0, step 100, and stop 1000.
- For example: If this is the XAUUSD currency pair and you trade on the M1 timeframe and the average price movement in the period, for example, 50 bars = 100 points (pips), then set this parameter for optimization as: start 0, step 10, stop 100.
- For example, you need confirmation of the opening signal and the average price movement in the period. For example, 100 bars = 1000 points (pips), then start 0, step 50, and stop 500.
Parameter StopOrderDayToExpiration – deletes the pending order if it does not execute within the set number of days.
It makes no sense to optimize.
Parameter StopOrderBarToExpiration deletes the pending order if it does not execute within the set number of bars (it depends on your timeframe).
Optimization options: start 0, step 1, stop 10
- Allows you to delete a pending order if the price does not break the Pending order (StopOrder) setting level.
Parameter ReInstallStopOrdersNewSignalAppears – resets the pending order when the signal is updated.
It makes no sense to optimize.
- It allows you to set a pending order every time a new signal appears.
- I do not recommend changing this setting.
Block 6: Trading Options
In this block, the parameters that are set at the time of executing positions are collected.
It makes no sense to optimize.
Block 7: Stops Options
Block for working with stop loss and take profit.
input string oo5 = "========= Stops options ========="; input bool VirtualStops = false; input bool ForcedModifySLTP = false; input minlevel SetMinStops = 0; input int StopLoss = 2000; input int TakeProfit = 0; input bool Include_Commission_Swap = true;
Parameters ForcedModifySLTP, SetMinStops, Include_Commission_Swap – I do not recommend changing. It makes no sense to optimize.
The parameter VirtualStops – includes the ability to install virtual stop loss and take profit without actual modification of positions (stop loss and take profit in the position will be = 0).
Optimization of values: True – False
- All levels of StopLoss and TakeProfit are stored in global variables and on the chart.
- There is a virtual execution of StopLoss and TakeProfit.
- It makes sense to apply only when you need to install very small (less than the minimum possible level on the server) stop levels.
- It allows you to hide your stop levels from the broker, thereby making it difficult to understand the logic of your strategy.
Parameter StopLoss – stop loss for the position.
Optimization of values: It is recommended to set the parameters individually for each pair.
- For example, if this is the EURUSD currency pair and you trade on the M30 timeframe. The average price movement in the period, for example, 50 bars = 7500 points (pips), then set this parameter for optimization as start 0, step 100, and stop 1000.
- For example: If this is the XAUUSD currency pair and you trade on the M1 timeframe and the average price movement in the period, for example, 50 bars = 100 points (pips), then set this parameter for optimization as: start 0, step 10, stop 100.
- It depends on your limits for each position.
- The more StopLoss, the longer the holding time of the position, and the more opportunity there is to hope that the price will return to the open position.
- The smaller the StopLoss, the faster the false signals will be closed.
- It makes no sense to use a small StopLoss, which is less than the DistanceAdditionalOpening.
Parameter TakeProfit – take profit for the position.
Optimization of values: It is recommended to set the parameters individually for each pair.
- For example: If this is the EURUSD currency pair and you trade on the M30 timeframe and the average price movement in the period, for example, 50 bars = 7500 points (pips), then set this parameter for optimization as: start 0, step 25, stop 500.
- For example: If this is the XAUUSD currency pair and you trade on the M1 timeframe and the average price movement in the period, for example, 50 bars = 100 points (pips), then set this parameter for optimization as: start 0, step 5, stop 100.
- You can set a take profit in the calculation of StopLoss / 2 or StopLoss / 3.
- The larger the TakeProfit, the longer the holding time of the position. You can miss the profit position if it does not achieve the goal of the TakeProfit.
- The smaller the TakeProfit, the sooner the profitable signals will be closed.
- It makes no sense to use a small TakeProfit, which is less than the DistanceAdditionalOpening.
Block 8: Lots Options
Block for working with fixed lot and auto lot.
input string oo4 = "========= Lots options ========="; input double Lots = 0.01; input bool DynamicLot = false; input double LotBalancePercent = 0.01; input double RiskRate = 0; input double MaxLot = 999; input double Martingale = 1;
I do not recommend changing the parameters MaxLot and RiskRate. It makes no sense to optimize.
Lots parameter – adjusts the volume of the position.
Optimization of values: It depends on your deposit. For example: For a step lot of 0.01 and a deposit of $1000: start 0.01, step 0.01, stop 0.1
- This parameter is better optimized after the optimization of the remaining parameters of the strategy.
- When you increase the lot, you increase the profit obtained from one position.
- With an increase in the lot, you can drain the deposit.
- It does not make sense to optimize with DynamicLot = true.
- Calculate the lot so that when you open a position with this lot, you only use 1-2% of the Balance. For example:
- To open one position with a lot of 0.01, you need $10 of free margin.
- If you use 100 stop points (pips) (where the price is 1 point = $0.1), you will receive a loss of $10. This is 1% of $1000.
Parameters DynamicLot and LotBalancePercent – adjust the auto calculation of the lot position.
Value optimization: DynamicLot = true and LotBalancePercent with parameters: start 0.1, step 0.1, stop 1
- This parameter is better optimized after the optimization of the remaining parameters of the strategy.
- It allows you to increase the lot when making a profit in a geometric progression.
- It can affect the final profit.
- I do not recommend using values higher than 1%.
Martingale parameter – includes Martingale when closing on stop loss.
Optimization of values: start 0.1, step 0.2, stop 2
- It makes sense to use only the value StopLoss > 0.
- If Martingale is less than 1, then each next position and its lot will be less than the previous one.
- If the value is less than 1, it makes sense to use it only when the lot positions are higher than the minimum lot on the server.
- If Martingale is greater than 1, then each next position and its lot will be larger than the previous one.
- The higher the value of Martingale, the more dangerous the trade Expert Advisor (EA).
- Martingale is a very simple and dangerous strategy.
- I recommend checking and reading about our Martingale trading strategy: Two Sides.
Block 9: Averager Options
Block for working with opening against the trend. Averaging positions.
input string oo2 = "========= Averager options ========="; input bool AverageUSE = true; input bool OnlyModify = false; input int TakeProfitALL = 200; input int Distance = 500; input double DistanceMartingale = 1; input double LotsMartingale = 1; input int MaxOrdersOpen = 5;
Parameter OnlyModify – I do not recommend changing. It makes no sense to optimize.
Parameter AverageUSE enables the averaging functions. Only with AverageUSE set to true can other parameters be optimized!
Optimizing values: True – False
- Averaging positions can load your account with additional positions.
- The averaging strategy requires a balance that is at least three times greater than the standard deposit (without averaging).
- Averaging positions are attempts to maintain a losing position in profit.
- If you use the recommended deposit, you can increase the number of profitable trades to 70-90%.
- When using averaging, the Expert Advisor (EA) will try to bring a false signal into profit. Other signals will be ignored until the averaging series closes.
Parameter TakeProfitALL modifies the take profit of all positions by one level.
Optimization of values: 10-50-1000 (start = 10, step = 50, stop = 1000)
- It serves as additional protection for positions if you have disabled averaging.
- It is useful if you do not use the AdditionalOpening parameter set to false.
The parameter Distance specifies the distance at which additional positions are opened against the trend.
Optimization of values: It is recommended to set the parameters individually for each currency pair.
- For example, if this is the EURUSD currency pair and you trade on the M30 timeframe with an average price movement of 50 bars = 7500 points (pips), set this parameter for optimization as follows: start = 0, step = 25, stop = 500.
- For example, if this is the XAUUSD currency pair and you trade on the M1 timeframe with an average price movement of 50 bars = 100 points (pips), set this parameter for optimization as follows: start = 0, step = 5, stop = 100.
- Another way to optimize this parameter is to use the average spread for the selected currency pair. We use this method in our TickSniper Expert Advisor (EA).
- For example, if the average spread for a currency pair is 3 points (pips), then the averaging Distance = 50 * 3 = 150 points (pips). In this case, the optimization can be set as follows: 100-25-250.
- Read more about the recommendations regarding the averaging Distance: Averager for MT4 and MT5
- The higher the distance values, the longer the Expert Advisor (EA) takes to bring the series of positions into total profit.
- The smaller the value of the averaging Distance, the greater the load on your account balance. More open positions mean you can achieve profit faster, but your trading account will be heavily loaded!
Parameter DistanceMartingale increases the distance in each additional position.
Optimization of values: Only in extreme cases, 1-0.1-2
- This parameter should be optimized if you need to increase the Distance for each new position in the series.
- If the Distance is too small, then DistanceMartingale allows you to increase the step of the averaging grid.
- If DistanceMartingale is less than 1, the step of the averaging grid and Distance will decrease with each additional averaging position opened!
- If DistanceMartingale is greater than 1, the step of the averaging grid and Distance will increase with each additional averaging position opened!
Parameter LotsMartingale increases the lot size for each additional position!
Optimization of values: Only in extreme cases, 1-0.1-2
- It allows you to reduce the time for a series of positions to move into profit.
- It can increase the load on your trading account and balance.
- It is recommended to use only with a sufficient balance!
- If LotsMartingale is less than 1, the lot size of the next additional position will decrease with each additional averaging position opened.
- If LotsMartingale is greater than 1, the lot size of the next additional position will increase with each additional averaging position opened.
Parameter MaxOrdersOpen limits the number of additional averaging positions against the trend!
Optimization of values: Only in extreme cases, 0 – 1 – 10
- Allows you to limit the load on the account by restricting the number of new additional positions.
- I use the value of 5. However, you can optimize this value for better results.
Block 10: Additional Opening
This block deals with the opening positions in the trend direction. Additional analysis.
input string oo10 = "========= Additional opening ================================== ======= "; input bool AdditionalOpening = false; input bool OnlyModifyAdditionalOpening = false; input int StopLossALL = 0; input int DistanceAdditionalOpening = 100; input double LotsMartinAdditionalOpening = 1; input int MaxOrdersOpenAdditionalOpening = 0;
The OnlyModifyAdditionalOpening parameter is not recommended to change! It makes no sense to optimize.
The AdditionalOpening parameter enables the function of additional opening based on the trend. Only when AdditionalOpening is set to true can other parameters be optimized!
Optimizing values: True – False
- Additional openings of positions allow you to achieve more profit if the signal is highly profitable.
- An additional position can incur a loss and reduce profits from the original series.
- Allows you to build a grid of positions in the direction of profit.
- It makes sense to use it together with the Absolute Stop or Trailing Stop.
The StopLossALL parameter modifies the StopLoss of all positions by one level.
Optimization values: 10-50-1000 (start = 10, step = 50, stop = 1000)
- It serves as an additional opening of positions if you have disabled it.
- It makes sense if you do not use Averaging: AverageUSE = false.
The DistanceAdditionalOpening parameter specifies the distance at which additional positions are opened in the trend.
Optimization values: It is recommended to set the parameters individually for each currency pair.
- For example, if this is the EURUSD currency pair and you trade on the M30 timeframe with an average price movement of 50 bars = 7500 points (pips), set this parameter for optimization as follows: start = 0, step = 25, stop = 500.
- For example, if this is the XAUUSD currency pair and you trade on the M1 timeframe with an average price movement of 50 bars = 100 points (pips), set this parameter for optimization as follows: start = 0, step = 5, stop = 100.
- Another way to optimize this parameter is to use the average spread for the selected currency pair.
- For example, if the average SPREAD for a currency pair is 3 points (pips), then the averaging distance = 50 * 3 = 150 points (pips). In this case, the optimization can be set as follows: 100-25-250.
The LotsMartinAdditionalOpening parameter increases the lot size for each additional position.
Optimization values: Only in extreme cases, 1-0.1-2
- It can affect your trading account and balance.
- It is recommended to use only with a sufficient balance.
- If LotsMartinAdditionalOpening is less than 1, the lot size of the next additional position will decrease with each additional position opened.
- If LotsMartinAdditionalOpening is greater than 1, the lot size of the next additional position will increase with each additional position opened.
The MaxOrdersOpenAdditionalOpening parameter restricts the number of additional positions in the trend.
Optimization values: Only in extreme cases, 0 – 1 – 10
Block 11: BreakEven Without Loss Options
BreakEven block.
input string MovingInWLUSE_ = "========= BreakEven Without LOSS options ========="; input bool MovingInWLUSE = false; input int LevelWLoss = 0; input int LevelProfit = 0;
The MovingInWLUSE parameter enables the installation of a Stop-Loss at the break-even point. Only when MovingInWLUSE is set to true can other parameters be optimized!
Optimizing values: True – False
The LevelWLoss parameter sets the level for adjusting the stop loss into profit. The LevelProfit parameter defines the profit value in points (pips) when the break-even starts to work.
Optimization values: 0-5-50
- The LevelProfit parameter must always be greater than LevelWLoss.
- You can set LevelProfit optimization to 25-5-100 and LevelWLoss to 0-5-50.
- The higher the value of LevelProfit, the more the position needs to move into profit for the Expert Advisor (EA) to set a break-even point. This protects against small losses, but you might miss out on profits.
- The greater the difference between LevelProfit and LevelWLoss, the less sensitive the break-even threshold becomes.
Block 12: Standard Trailing Options
The unit for standard trailing stops.
input string Trailing_ = "========= Standard Trailing options ========="; input bool TrailingStopUSE = true; input bool IfProfTrail = true; input int TrailingStop = 100; input int TrailingStep = 1; input bool SaveTPafterTrailingStop = false;
IfProfTrail, TrailingStep, and SaveTPafterTrailingStop parameters are not recommended to change! It makes no sense to optimize.
The TrailingStopUSE parameter enables the support and modification of Stop-Loss to profit. Only when TrailingStopUSE is set to true can other parameters be optimized!
Optimizing values: True – False
- The difference between TrailingStop and BreakEven is that the trailing stop sets the BreakEven point and then adjusts the stop loss into profit if market conditions allow.
- You can use different parameter values for TrailingStop and BreakEven. It does not make sense to use the same parameters for both.
The TrailingStop parameter defines the distance of the stop loss from the current price. In this case, the position should accumulate TrailingStop profit pips.
Optimization values: 0-10-100 (With an average currency pair movement of 200-300 points (pips) per day)
- The higher the value of TrailingStop, the more the position needs to move into profit for the Expert Advisor (EA) to establish a break-even point and continue trailing the position. This protects against small losses, but you might miss out on larger profits.
Block 13: Trailing Stop by SAR
Trailing stop unit based on the SAR indicator.
input period periods6 = "========= TrailingStop by SAR ================================= ==== "; input bool TrailingStopSAR = false; input ENUM_TIMEFRAMES TrailingStopSAR_TimeFrame = PERIOD_CURRENT; input double step = 0.02; input double maximum = 0.2;
The TrailingStopSAR_TimeFrame, step, and maximum parameters are not recommended to change! It makes no sense to optimize.
The TrailingStopSAR parameter enables the support and modification of Stop-Loss into profit based on the points (pips) of the Parabolic SAR indicator. Only when TrailingStopSAR is set to true can other parameters be optimized!
Optimizing values: True – False
- It allows you to set Stop-Loss based on the extremes of the indicator.
- Always maintain the distance from the current price to the extremum by calculating the distance automatically.
- It does not make sense to use it with TrailingStopUSE set to true.
Block 14: Time Trade Options
The time management unit of the Expert Advisor (EA).
input string oo6 = "========= Time Trade options ================================= ======= "; input bool TradeStartStopbyTime = false; input string SeveralTimeWork = ""; input string of_times41 = "=== Time Trade Start / Stop Time ============================"; input int OpenHour = 0; input int OpenMinute = 0; input int ClosePeriod_Minute = 0; input int CloseHour = 23; input int CloseMinute = 59; input typeofclosebyouttime CloseAllTradesByOutOfTime = NotUse; input string period43 = "=== Time Trade Days ============================"; input bool TradeByDays = false; input string Days = "1,2,3,4,5,6,0"; input int DayForOptimization = 0; input string period42 = "=== Time Trade Monday ============================"; input bool TradeStartbyTimeMonday = false; input int OpenHourMonday = 0; input int OpenMinuteMonday = 0; input string of_periods44 = "=== Time Trade Friday ============================"; input bool TradeStartStopbyTimeFriday = false; input int OpenHourFriday = 0; input int OpenMinuteFriday = 0; input int CloseHourFriday = 23; input int CloseMinuteFriday = 59; input bool CloseFriday = false;
This block contains numerous parameters, making it time-consuming to optimize all of them.
You can optimize the time settings after optimizing all the other blocks to improve the test results.
Only when TradeStartStopbyTime is set to true does it make sense to optimize the remaining parameters!
I recommend optimizing only these parameters:
- OpenHour = 0-1-23
- CloseHour = 0-1-23
- TradeByDays = True-False
- DayForOptimization = 0-1-6
Block 15: CloseALL When Profit or Loss Options
Block for closing based on total profit.
input string CloseProfitLoss = "========= CloseALL when Profit or LOSS options ========="; input typeprofloss TypeofClose = 1; input bool CloseProfit = false; input double prifitessss = 10; input bool CloseLoss = false; input double lossss = -10; input double TrailOptions = 0; input double TrailOptionsStep = 0; input double BalanceStart = 0; input bool ForcedClose = true; input bool MailSend; input bool Orderdelete = true; input bool OFFAfterClosePROF = false; input bool OFFAfterCloseLOSS = false; input bool CloseTerminalAfterClosePROF = false; input bool CloseTerminalAfterCloseLOSS = false;
Individual block. You can optimize parameters only when it is necessary for your strategy.
For example, when you open multiple positions or engage in chaotic position openings.
It makes sense to optimize the following parameters when TypeofClose is set to PercentBalance:
- CloseProfit = True-False;
- prifitessss = 0.1-0.1-1
- CloseLoss = True-False;
- lossss = (-0.1) – (-0.1) – (-1)
Options for Calling OnTester_Custom_max:
The first parameter is the general formula for obtaining the optimizer run result!
By default: (Profit * Number of Trades) / Percentage of Drawdown of Available Funds
OnTester_Custom_max | Your own criterion for genetic optimization. More information about the test results: Statistics Recorded in the form of a formula. For example: OnTester_Custom_max = “STAT_PROFIT * STAT_TRADES / STAT_EQUITY_DD” Be sure to specify the names of variables as in the reference! |
Options for Calling OnTester_****:
OnTester_Min_Trades | Min Deals for Optimization | Minimum Balance (in the deposit currency) at the end of testing for a successful optimization result. For example, 1000 (Same as the initial deposit) = If the Balance in this optimizer run is less than the initial deposit, then this result will be equal to 0. |
OnTester_Min_Profit | Min Profit for Optimization | Minimum Free Funds (in the deposit currency) at the end of testing for a successful optimization result. For example, 500 = If Equity in this optimizer run is less than 500 (in the deposit currency), then this result will be equal to 0. |
OnTester_Min_ProfitFactor | Min ProfitFactor for Optimization | Minimum Profit Factor required for a successful optimization result. For example, 1.5 = If the Profit Factor in this optimizer run is less than 1.5, then this result will be equal to 0. |
OnTester_Min_Balance | Min Balance for Optimization | Minimum Balance (in the deposit currency) at the end of testing for a successful optimization result. For example, 1000 (Same as the initial deposit) = If the Balance in this optimizer run is less than the initial deposit, then this result will be equal to 0. |
OnTester_Min_Equity | Min Equity for Optimization | The minimum number of trades opened by the Expert Advisor (EA) for a successful optimization result. For example, 50 = If the number of trades in this optimizer run is less than 50, then this result will be 0. |
OnTester_Max_Balance_DD | Max Balance Drawdown % for Optimization | Maximum allowed Drawdown on Balance (in the deposit currency) for a successful optimization result. For example, 20% = If the Balance Drawdown in this optimizer run exceeds 20%, then this result will be equal to 0. |
OnTester_Max_Equity_DD | Max Equity Drawdown % for Optimization | Maximum allowed Drawdown on Equity (in the deposit currency) for a successful optimization result. For example, 15% = If the Equity Drawdown in this optimizer run exceeds 15%, then this result will be equal to 0. |
Conclusions
Optimization and testing of Expert Advisors (EA) is a continuous endeavor.
You may think that optimization is complicated and expensive. But are you planning to earn millions of dollars?
You must understand that Forex is not easy. Every EA is just an algorithm built into the code.
We have been working for more than 10 years and understand what trade experts require.
With confidence, we can say that optimizing and configuring one EA is much easier than searching for and optimizing thousands of other robots.
- Test and find the trading options that suit you best!
- Optimize every six months!
- Monitor the Expert Advisor (EA), study the logs, and stay attentive to the EA!
- Adjust the parameters of the Expert Advisors (EA) based on the news.
Learn the materials on Forex trading.
Questions?
If you have any questions, please ask them. We do not sell the pig in a poke.
Each of our products can be checked before purchase.
We appreciate your feedback and wishes for our products and strive to maintain high-quality standards.
Thank you for being with us!
Do you have a question?
Related Posts
VirtualTradePad (VTP) Trading Panel. Trade Pad for One Click Traiding
VirtualTradePad or VTP – control panel for trade in 1 click in MetaTrader 4 and 5. Trade in 1 click from…
The X – Universal Expert Advisor (EA) for Forex Using
Universal Expert Advisor (EA) for MetaTrader with Extensive Functionality The Expert Advisor The X is a versatile trading tool for MetaTrader,…
Tick Hamster Automatic trading robot. Nothing extra!
Tick Hamster – Expert Advisor with Automatic Optimization for Any Trading Symbol in MetaTrader Tick Hamster is a fully automated Expert…
Extra Report Pad – Trader’s Diary. Professionally analyzes your trading
Extra Report Pad – professional solution for analyzing your trading account Today, it is essential to trade at once for several…
Swing strategy (Pendulum). Automatic opening of 2 opposite pending orders,
The Pendulum or Swing strategy involves the sequential opening of pending orders with an increased lot size. The core principle…
InfoPad, Online Information Panel for MetaTrader
InfoPad is a highly useful information panel designed to provide crucial information on the specific currency pair selected in the…
Duplicator – Duplication of deals/positions on the MetaTrader terminals
The Exp-Duplicator is an automatic Expert Advisor designed to duplicate trades and positions a preset number of times on your…
EA The xCustomEA: Universal Trading Advisor for iCustom Indicators. Custom
Universal trading adviser on custom indicators for MetaTrader . Exp – The xCustomEA Universal trading advisor on custom indicators. The xCustomEA works on…
CLP CloseIfProfitorLoss with Trailing. Control of the total profit or
The Expert Advisor (EA) offers advanced features for managing and closing positions in MetaTrader, specifically upon reaching a predetermined level…
Templates MQL Open Source. Template for Creating Expert Advisor
Brief Creating Expert Advisors (EAs) to test your strategy using any indicator can indeed be simplified using templates and open-source resources….
SafetyLOCK PRO Protect your positions by locking using the opening
SAFETYLOCK: Secure Your Trades Against Sharp Market Reversals Trading on financial markets involves high risks, particularly during sharp market reversals. SAFETYLOCK…
Tester Pad is a Forex trading simulator for strategy tester.
One-click trading on the Strategy Tester chart. The utility allows you to manually test your strategies in the strategy tester….
EAPadPRO – Information panel for our experts. Dashboard for Expert
Information panel for all our advisors and utilities for the MetaTrader terminal. Detailed instructions on the basics of managing and using…
Averager. Averaging trading positions. Opening deals against the trend and
Averaging positions. Opening of additional positions on the trend and against the trend with the function of the general trailing…
Related Posts
Swing strategy (Pendulum). Automatic opening of 2 opposite pending orders,
The Pendulum or Swing strategy involves the sequential opening of pending orders with an increased lot size. The core principle…
EAPadPRO – Information panel for our experts. Dashboard for Expert
Information panel for all our advisors and utilities for the MetaTrader terminal. Detailed instructions on the basics of managing and using…
Tick Hamster Automatic trading robot. Nothing extra!
Tick Hamster – Expert Advisor with Automatic Optimization for Any Trading Symbol in MetaTrader Tick Hamster is a fully automated Expert…
Tester Pad is a Forex trading simulator for strategy tester.
One-click trading on the Strategy Tester chart. The utility allows you to manually test your strategies in the strategy tester….
Extra Report Pad – Trader’s Diary. Professionally analyzes your trading
Extra Report Pad – professional solution for analyzing your trading account Today, it is essential to trade at once for several…
SafetyLOCK PRO Protect your positions by locking using the opening
SAFETYLOCK: Secure Your Trades Against Sharp Market Reversals Trading on financial markets involves high risks, particularly during sharp market reversals. SAFETYLOCK…
Market Time Pad. Indicator for MetaTrader with trading sessions
The Time Indicator displays the current time across the major world markets and highlights the active trading session. It is easy…
VirtualTradePad (VTP) Trading Panel. Trade Pad for One Click Traiding
VirtualTradePad or VTP – control panel for trade in 1 click in MetaTrader 4 and 5. Trade in 1 click from…
TickSniper Automatic Expert Advisor for Metatrader. Tick scalper
Exp-TickSniper is a fast tick scalper that automatically selects parameters for each currency pair separately. The EA has been developed based on…
Averager. Averaging trading positions. Opening deals against the trend and
Averaging positions. Opening of additional positions on the trend and against the trend with the function of the general trailing…
Trade Report of TickSniper and the best advisors from Expforex
Description We have summed the summary and detailed trading results of our experts TickSniper, Good Santa, Tick Hamster, The X, on our real trading accounts. Trade…
Assistant – the best free trading panel to support positions
Auto Setting stop loss, take profit, trailing stop, breakeven levels, enabling virtual stops. Exp Assistant will help you organize maintenance of your…
EAPADPRO LIBRARY – Adding our panel to your EA
EAPADPRO LIBRARY – Enhancing Your Expert Advisor (EA) with Our Information Panel EAPADPRO LIBRARY offers a robust solution for traders looking…
Close Minus by Plus, Closing unprofitable positions by searching and
Closing unprofitable positions by identifying and closing profitable ones. The Expert Advisor (EA) is designed to close unprofitable positions by identifying…
Partial Close and Trailing. Partial closing of positions on rollbacks
Partial Close and Trailing is an EA assistant that closes a portion of a position (i.e., part of the lot)…
This post is also available in: English Українська Portuguese Español Deutsch Chinese Русский Français Italiano Türkçe 日本語 한국어
Leave a Reply