Update the Self Optimising EA

 

I have checked the EA, but results are some correct. Please review the EA and fix the self-optimization logic.

You can update the EA as needed.

Please see attached the Self-Optimizing EA file

 
could you please explain what it is and how to use it ?
 
Jean Francois Le Bas #:
could you please explain what it is and how to use it ?

This is a Walk Forward Optimisation (Self Optimising EA).

A normal EA uses fixed settings, for example :-

Fast MA = 20
Slow MA = 50
MACD = 12, 26, 9
Stop Loss = 4000
Take Profit = 4000

A Self-Optimizing EA can automatically change its settings after optimization and forward testing based on historical market data. It tries to find better settings for the current market conditions.

The basic process is :

Historical Data -> 3 Month Optimization -> 1 Month Forward Test  -> Check Quality filters (Net Profit / Profit Factor / DrawDown ) -> Find Best Settings(Parameters) -> Trade -> Re-optimize -> Repeat.

This process is called Walk-Forward Optimization EA.

Information about Input Parameter :-

Type of TakeProfit & StopLoss :-

input group "Type of TakeProfit & StopLoss :-"
sinput string string_TP_SL = "TakeProfit & StopLoss (True / False) :-";
sinput bool TakeProfit_StopLoss_T_F = false; //TakeProfit & StopLoss (True / False)
input double TakeProfit = 4000; //TakeProfit
input double StopLoss = 4000; //Stoploss
sinput string string_RR = "Risk in Reward (True / False) :-";
sinput bool RiskInReward_T_F = false; //Risk in Reward (True / False)
input double RR = 3; //Risk in Reward (StopLoss x Multiplier)
input double RR_StopLoss = 4000; // Stoploss
sinput string string_ATR = "ATR (True / False) :-";
sinput bool ATR_SL_TP = false; //ATR (True / False)
input int ATR_Period = 14; // ATR Period
input double ATR_TP = 4; // ATR TakeProfit Multiplier
input double ATR_SL = 2; // ATR StopLoss Multiplier

There are 3 options for choosing the Take Profit (TP) and Stop Loss (SL) method:

  • Take Profit & Stop Loss
  • Risk in Reward
  • ATR

Each option has a True / False setting.

Select True for the one method you want to use.
Select False for the methods you do not want to use.
Do not select True for all 3 options at the same time.


Optimization Target :-

enum ENUM_OPTIMISATION_TARGET
  {
   OPT_BALANCE_MAX,  // Balance Max (Net Profit)
   OPT_PROFIT_FACTOR_MAX, // Profit Factor Max
   OPT_EQUITY_DRAWDOWN,  // Equity DrawDown
   OPT_RECOVERY_FACTOR,   // Recovery Factor
   OPT_NUM_OF_MIN, // Number of Trade (Minimize Trades)
   OPT_ALL // All (Balance Max, Profit Factor Min 1.6, Equity DrawDown Min 1% to Max 50%, Recovery Factor Min 2, Number of Trade Min 10 )
  };

It has 6 choices. If you want to select the best result, you can choose the appropriate option.

Balance Max => The EA finds the result with the highest Net Profit.
Profit Factor Max => The EA finds the result with the highest Profit Factor.
Equity Drawdown => The EA selects a result based on the Equity Drawdown range.
Recovery Factor => The EA finds the result with the highest Recovery Factor.
Number of Trades (Min) => The EA tries to find the result with the minimum number of trades.
All => The EA finds the best result after applying all quality filters. (All filter must pass : NetProfit > 0, PF > 1.6, DrawDown > 1% & < 50%, Recovery Factor > 2, Number of Trade > 10)


Re-optimization Mode :-

input ENUM_REOPTIMIZATION_MODE Reoptimization_Mode = REOPT_DAILY; // Re-optimization Mode

This mean the EA can re-optimize Every Day. The Default is Daily.

For Example :-

if you select "Daily" in the Re Optimisation Mode, the EA will re-optimize Every Day.

Daily : Optimize -> Forward -> Next Day -> Optimize again.

Weekly/Monthly : Optimize -> Forward -> Next Weekly/Monthly -> Optimize again.

Number of Re-Optimisation (Every N Day/Wee/Month) :-

input int Number_of_Reoptimization = 1; // Number of Re-optimization (Every N Day/Week/Month)

This mean the EA will Re-Optimise every N Day/Week/Month. The default value is 1.

For example :

1 Day → re-optimize every 1 day
2 Days → re-optimize every 2 days
1 Week → re-optimize every 1 week
1 Month → re-optimize every 1 month

No. of Date Mode (Day/Week/Month/Year) :-

input ENUM_OPT_FORW_MODE opt_forw_mode = MONTH; // No. of Date Mode (Day/Week/Month/Year)
input int Date_Optimization = 3; // Number of Date Optimization
input int Date_Forward = 1; // Number of Date Forward

This mean if you select "Month", the EA will use Months as the Period unit. For Example, 

Date_Optimization = 3; // Number of Date Optimization

it mean 3 Months.

Date_Forward = 1; // Number of Date Forward

it mean 1 Month.

Forward Mode :-

input ENUM_FORWARD_MODE forw_mode = CURRENT_DATE; // Forward Mode (Current Date / Previous Date)

This mean

if you select "Current Date", the EA uses the Current Forward Period. For Example , Now Aug 24 to Sep 23, 2026.

if you select "Previous Date", the EA uses a previous completed Period. For Example , July 24 to Now Aug 23 2026.


Max Parameter Combinations per Cycle :-

input int Max_Param_Combinations = 500; // Max Parameter Combinations per Cycle

It means the EA limits how many parameter combinations it evaluates during an optimization cycle. For Example, 500 is much easier for the computer than trying thousands or millions of combinations.


Optimization Forward WalkForward Mode :-

input ENUM_OPT_FORW_WF_MODE opt_forw_wf_mode = Fast_Genetic_Algorithms; // Optimization Forward WalkForward Mode

It means there are 2 options such as Random Sampling, Fast Genetic Algorithms.

Fast Genetic Algorithms - The EA tries to find good parameter combinations without testing every possible combination.


Close Positions at Segment End :-

input bool Close_Positions_Segment_End = false; // Close Positions at Segment End

It means if you select "True", the EA automatically close all positions when a walk-forward segment ends.


TRADING COSTS (WALK-FORWARD SIMULATION) :-

input group "Trading Costs (Walk-Forward Simulation) :-"
input bool   Sim_Costs_Enabled        = false;  // Trading Costs Enabled (True / False) [Optimization & Forward Simulation]

This mean if you select "True", Include simulated trading costs. Trading costs can include : Spread, Commission, Swap.

input bool   Spread_Current           = true;  // Current Spread (True) / Fixed Spread (False)
input int    Spread_Points_Fixed      = 0;     // Fixed Spread in Points (if Current Spread = False)
input bool   Commission_Detect        = true;  // Detect Commission per Lot (True) / Fixed Commission (False)
input double Commission_Per_Lot_Fixed = 0.0;   // Fixed Commission per Lot per Side (if Detect Commission = False)
input bool   Swap_Detect              = true;  // Detect Swap (True) / Fixed Swap (False)
input double Swap_Per_Lot_Day_Fixed   = 0.0;   // Fixed Swap per Lot per Day (if Detect Swap = False, negative = cost)

This means,  Spread :- if you select "true" = Use current spread, "false" = Use fixed spread.

......


Coordinate Ascent / One-Factor-at-a-Time (OFAT) Mode :-

//+-------------------------------------------------------------------------------+
//|  Coordinate Ascent / One-Factor-at-a-Time (OFAT) Mode            |
//+-------------------------------------------------------------------------------+
input group "Coordinate Ascent / One-Factor-at-a-Time (OFAT) :-"
input bool OFAT_Mode = false; // Coordinate Ascent / OFAT (Optimize N Parameters at a Time) (True / False)
input int OFAT_Param_Count = 2; // Number of Parameters to Optimize at a Time (1 to 5, Default 2)

This mean, OFAT mean One Factor at a time . It means the EA does not optimize all input parameters at the same time. Instead, it optimizes a small group of parameters, then moves to another group.

if you select "true" & 2 Number of parameter, the EA can optimize 2 parameters at a time

For Example, Optimize 2 parameters -> Keep other parameters fixed -> Optimize another 2 parameters -> Keep the others fixed -> Continue


Optimisation Range :-

Each parameter has 4 inputs. 

sinput bool MA_Opt = false; // MA Optimisation (True / False)

"...Optimisation (True / False)" - if you select "true", the EA will optimize this parameter. if you select "false", the parameter will keep its fixed setting.

(Note : You do not need to select “True” for all parameters. It is better to optimize only the parameters you want to change and keep the other parameters fixed)

input int FastMAPeriod_Start = 10; // Fast MA Period Start
input int FastMAPeriod_Step = 10; // Fast MA Period Step
input int FastMAPeriod_Stop = 50; // Fast MA Period Stop

This mean,

"...Start" - First value tested

"...Step" - Increment between values

"...Stop" - Last value tested


Warning - Don't use this EA for live trading. It does not guarantee future profits.

There may be some errors in my EA code, so please check it carefully