Grid Deriv EA
Optimization Guide
Optimization Guide
Grid Deriv is an automatic grid-based system designed to exploit extreme price movements.Â
It uses an initial entry based on Bollinger Bands and a stepped logic of counter entries to capture deep pullbacks, based on a mean reversion approach after volatility expansion.
The goal of the following step-by-step optimization guide is to give the traders the tools to find a set file that suits their own unique profit objectives and risk management specifications, ensuring the best results when using the Grid Deriv EA.
Initial lot size (0 = minimum lot): Volume used for the first trade in the grid (0 uses symbol minimum).
Lot mode: Lot scaling mode for each new trade (Fixed, Linear, or Power of 2).
Distance factor between grid trades: Allows to adjust the number of entries triggered.
Max trades allowed per grid: Maximum number of trades allowed simultaneously within a grid.
Global TP (in $ or % if enabled): Closes all trades when the total profit is reached.
Global SL (in $ or % if enabled): Closes all trades when the loss threshold is reached. This parameter is intended to be set by the user according to their own risk specifications.
Close if price crosses mid Bollinger: If enabled, the grid closes when price crosses the middle band.
Bollinger Bands period: Simple moving average period of the indicator.
Bollinger Bands deviation: Determines the distance between the upper and lower bands and the middle line of the indicator.
Bollinger timeframe: Timeframe used by the indicator.
The parameters related to the Bollinger Bands Settings are intended to be set by the user according to the asset for which the EA is being optimized.
Introduction to Fast Genetic Based Optimization Algorithm
Optimization is an essential process for improving the performance of any Expert Advisor (EA). The Fast Genetic Based Algorithm is an advanced technique that utilizes principles of genetics and evolution to search for the best parameter combinations. This algorithm significantly speeds up the optimization process, allowing for the efficient and effective exploration of a wide range of configurations.
Modeling Selection
It is recommended to use "1 minute OHLC" for a faster optimization process.
Optimization Period
For obtaining a set file for a week, optimize with data from the last 10 weeks.
For a monthly setfile, optimize with data from the last 10 months.
Optimization: Criteria Selection
Funded Accounts or Prop Firms
For users operating with funded accounts or prop firms, it's crucial to maintain strict control over risk and drawdown. Therefore, it is recommended to select one of the following optimization criteria:
Drawdown min: Minimizes drawdown to maintain account stability.
Complex Criterion max: Balances profit-seeking with drawdown control.
Regular Accounts
For users with regular accounts who want to maximize profits, even if it means taking on higher risk, they may consider the following optimization criteria:
Balance Max: This criterion maximizes the account balance, seeking high returns in a short period, with associated risks.
Profit Factor Max: This criterion maximizes the profit factor, which is the ratio between gross profit and gross loss. A high profit factor indicates a more profitable and stable strategy over time.
The Inputs tab in MetaTrader 5's Strategy Tester allows you to configure and optimize the parameters of the Expert Advisor (EA).
In this example, only the parameters within the yellow boxes should be selected and optimized. Below is a description of each of these parameters, showing the range of values used for optimization.
The user also has the option of setting the Global Stop Loss (Global SL) parameter to a specific value according to their risk management strategy, or allowing the parameter to vary between configurable start and stop values with a specific step value. To do this, simply select the Global SL check box in the table below and set the parameter values.
Input Parameters
Lot mode
Current Value: Fixed
Optimization Range: Options: Fixed, Linear, X2.
Max trades allowed per grid
Current Value: 5
Optimization Range: Start: 5
Step: 2
Stop: 20
Distance factor between grid trades
Current Value: 2.0
Optimization Range: Start: 2.0
Step: 2.0
Stop: 10.0
Global TP (in $ or % if enabled)
Current Value: 0.2
Optimization Range: Start: 0.2
Step: 0.2
Stop: 2.0
Input Parameters
Close if price crosses mid Bollinger
Current Value: false
Optimization Range: Options: false, true.
Bollinger Bands period
Current Value: 10
Optimization Range: Start: 10
Step: 5
Stop: 40
Bollinger Bands deviation
Current Value: 1.0
Optimization Range: Start: 1.0
Step: 0.2
Stop: 3.0
Bollinger timeframe
Current Value: 5 minutes
Optimization Range: Start: 5 minutes
Step: -Â
Stop: 4 hours
Initial Setup:
Select the Expert Advisor (Grid Deriv\Grid Deriv.ex5) and the symbol (XAUUSD).
Configure the timeframe (H1) and the date range (Custom period, 2025.01.01 - 2025.09.09), for example.
Select the modeling type ("1 minute OHLC") for a faster optimization.
Set the initial deposit (1000 USD) and leverage (1:100). You can select any initial deposit and higher leverage values.
Optimization Algorithm Setup:
Choose the optimization algorithm ("Fast genetic based algorithm").
Select the appropriate optimization criteria:
For funded accounts: It is not recommended to select Balance Max. Use criteria like Drawdown min or Complex Criterion max.
For regular accounts: Any optimization criterion can be selected, but Complex Criterion max is recommended.
Input Parameters Setup:
Adjust the input parameters using the start, step, and stop values indicated above.
Start the Optimization:
 Click the "Start" button to begin the optimization.
At the end of the optimization process, you will see a results window similar to the one shown below. Understanding this output is crucial for selecting the best set file for your trading strategy.Â
Key Metrics
Pass: The number of optimization iterations completed. Each pass represents a unique combination of input parameters tested during the optimization process.
Result: The overall performance score for each pass. This is often based on the selected optimization criteria, such as balance or drawdown.
Profit: The total profit generated by the EA during the optimization period.
Total trades: The total number of trades executed by the EA in each pass.
Expected payoff: The average profit per trade, calculated as total profit divided by the number of trades.
Drawdown %: The maximum drawdown percentage experienced during the optimization period. This indicates the largest peak-to-trough decline in the account balance.
lotMode: The global Take Profit used in the pass.
maxOrdersPerGrid: The number of trades allowed per grid in the pass.
gridSpacingFactor: The factor to trigger open positions in the pass.
globalTP: The global Take Profit used in the pass.
closeAtMiddleBand: Whether the grid is closed when price crosses the middle band in the pass.
bollingerPeriod: The period used by the Bollinger Bands indicator in the pass.
bollingerDeviation: The distance between the upper and lower bands and the middle band applied by the Bollinger Bands indicator in the pass.
bollingerTimeframe: The timeframe used by the Bollinger Bands indicator in the pass
To select the best set file, follow these steps:
Evaluate the Criteria: Focus on passes with the best balance between high profit and low drawdown. The selected criteria (e.g., balance, drawdown) should guide this evaluation.
Check Stability: Ensure the selected pass shows consistent performance across different metrics. High profit with extremely high drawdown may not be desirable.
Review Trade Frequency: Ensure the total number of trades is reasonable. Too few trades might indicate insufficient data, while too many trades could mean signal over-optimization.
Analyze Expected Payoff: Higher expected payoff indicates more efficient trading. Select passes with a good balance between expected payoff and drawdown.
Consistency of Parameters: Ensure the selected set file has consistent and logical parameter values. Extreme values may suggest overfitting.
Plot the Balance/Equity Curves: In the Settings tab, select "Every tick" as the modelin type for a more realistic analysis, and disable the optimization algorithm by selecting "Disabled". Now, doble-click the desired pass from the Optimization Results tab to plot the Balance/Equity curves. See the results in the Graph tab.
Analyze the Metrics: To observe metrics such the Equity Drawdown Relative Percentage, click on the Backtest tab for a good risk selection criteria.
Export the Setfile: Once you identify the best pass, export the set file for use in live trading or further testing. In MetaTrader 5, click on the Inputs tab and right-click on the inputs of the desired pass, then select "Save" to save it as a set file.
Example
In the provided image the second pass has a profit of 24,563.68 and a drawdown of 50.32%. Both profit and drawdown are quite acceptable, which probably suggests a moderate risk strategy. Compare it with other passes to find a balance that fits your risk tolerance.
By plotting the balance/equity curves, you can get a good overview of the pass's behavior throughout the optimization period, as can be seen in the image below:
Finally, the equity drawdown relative percentage for this pass is 54.84%, which suggests a moderate risk strategy.
By carefully analyzing the optimization results, the plot of the balance/equity curves, and the backtest results, you can identify the most robust and profitable set files for your Grid Deriv EA. This process helps ensure your trading strategy is both effective and sustainable.
Understanding and analyzing the optimization results is crucial for maximizing the performance of your Grid Deriv EA. By following this guide and selecting the best set file, you can enhance your trading strategy and achieve more consistent results. Remember, the key is to balance profitability and risk management.