MQL5 - Empty EA run slower than EA generated using wizard.

 

I'm facing one weird problem. I notice the EA i wrote is way slower than EA generated using EA generator wizard.

I'm trying to troubleshoot and eventually removed all codes and it is still slower than EA generated using the generator.
does anyone have the same problem? the "Empty EA" literally does nothing.

All other area remain constant during testing. e.g. using OLTP, using the same 6 months duration, same symbol etc.


Empty EA:

//+------------------------------------------------------------------+
//|                                                        empty.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   return;
  }
//+------------------------------------------------------------------+


 
EA generated using generator:- this code generated using wizard without any modification

//+------------------------------------------------------------------+
//|                                                    generator.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Include                                                          |
//+------------------------------------------------------------------+
#include <Expert\Expert.mqh>
//--- available signals
#include <Expert\Signal\SignalAMA.mqh>
#include <Expert\Signal\SignalEnvelopes.mqh>
//--- available trailing
#include <Expert\Trailing\TrailingParabolicSAR.mqh>
//--- available money management
#include <Expert\Money\MoneyFixedLot.mqh>
//+------------------------------------------------------------------+
//| Inputs                                                           |
//+------------------------------------------------------------------+
//--- inputs for expert
input string             Expert_Title                 ="test";      // Document name
ulong                    Expert_MagicNumber           =15052;       //
bool                     Expert_EveryTick             =false;       //
//--- inputs for main signal
input int                Signal_ThresholdOpen         =10;          // Signal threshold value to open [0...100]
input int                Signal_ThresholdClose        =10;          // Signal threshold value to close [0...100]
input double             Signal_PriceLevel            =0.0;         // Price level to execute a deal
input double             Signal_StopLevel             =50.0;        // Stop Loss level (in points)
input double             Signal_TakeLevel             =50.0;        // Take Profit level (in points)
input int                Signal_Expiration            =4;           // Expiration of pending orders (in bars)
input int                Signal_AMA_PeriodMA          =10;          // Adaptive Moving Average(10,...) Period of averaging
input int                Signal_AMA_PeriodFast        =2;           // Adaptive Moving Average(10,...) Period of fast EMA
input int                Signal_AMA_PeriodSlow        =30;          // Adaptive Moving Average(10,...) Period of slow EMA
input int                Signal_AMA_Shift             =0;           // Adaptive Moving Average(10,...) Time shift
input ENUM_APPLIED_PRICE Signal_AMA_Applied           =PRICE_CLOSE; // Adaptive Moving Average(10,...) Prices series
input double             Signal_AMA_Weight            =1.0;         // Adaptive Moving Average(10,...) Weight [0...1.0]
input int                Signal_Envelopes_PeriodMA    =45;          // Envelopes(45,0,MODE_SMA,...) Period of averaging
input int                Signal_Envelopes_Shift       =0;           // Envelopes(45,0,MODE_SMA,...) Time shift
input ENUM_MA_METHOD     Signal_Envelopes_Method      =MODE_SMA;    // Envelopes(45,0,MODE_SMA,...) Method of averaging
input ENUM_APPLIED_PRICE Signal_Envelopes_Applied     =PRICE_CLOSE; // Envelopes(45,0,MODE_SMA,...) Prices series
input double             Signal_Envelopes_Deviation   =0.15;        // Envelopes(45,0,MODE_SMA,...) Deviation
input double             Signal_Envelopes_Weight      =1.0;         // Envelopes(45,0,MODE_SMA,...) Weight [0...1.0]
//--- inputs for trailing
input double             Trailing_ParabolicSAR_Step   =0.02;        // Speed increment
input double             Trailing_ParabolicSAR_Maximum=0.2;         // Maximum rate
//--- inputs for money
input double             Money_FixLot_Percent         =10.0;        // Percent
input double             Money_FixLot_Lots            =0.1;         // Fixed volume
//+------------------------------------------------------------------+
//| Global expert object                                             |
//+------------------------------------------------------------------+
CExpert ExtExpert;
//+------------------------------------------------------------------+
//| Initialization function of the expert                            |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- Initializing expert
   if(!ExtExpert.Init(Symbol(),Period(),Expert_EveryTick,Expert_MagicNumber))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing expert");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Creating signal
   CExpertSignal *signal=new CExpertSignal;
   if(signal==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating signal");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//---
   ExtExpert.InitSignal(signal);
   signal.ThresholdOpen(Signal_ThresholdOpen);
   signal.ThresholdClose(Signal_ThresholdClose);
   signal.PriceLevel(Signal_PriceLevel);
   signal.StopLevel(Signal_StopLevel);
   signal.TakeLevel(Signal_TakeLevel);
   signal.Expiration(Signal_Expiration);
//--- Creating filter CSignalAMA
   CSignalAMA *filter0=new CSignalAMA;
   if(filter0==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating filter0");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
   signal.AddFilter(filter0);
//--- Set filter parameters
   filter0.PeriodMA(Signal_AMA_PeriodMA);
   filter0.PeriodFast(Signal_AMA_PeriodFast);
   filter0.PeriodSlow(Signal_AMA_PeriodSlow);
   filter0.Shift(Signal_AMA_Shift);
   filter0.Applied(Signal_AMA_Applied);
   filter0.Weight(Signal_AMA_Weight);
//--- Creating filter CSignalEnvelopes
   CSignalEnvelopes *filter1=new CSignalEnvelopes;
   if(filter1==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating filter1");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
   signal.AddFilter(filter1);
//--- Set filter parameters
   filter1.PeriodMA(Signal_Envelopes_PeriodMA);
   filter1.Shift(Signal_Envelopes_Shift);
   filter1.Method(Signal_Envelopes_Method);
   filter1.Applied(Signal_Envelopes_Applied);
   filter1.Deviation(Signal_Envelopes_Deviation);
   filter1.Weight(Signal_Envelopes_Weight);
//--- Creation of trailing object
   CTrailingPSAR *trailing=new CTrailingPSAR;
   if(trailing==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating trailing");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Add trailing to expert (will be deleted automatically))
   if(!ExtExpert.InitTrailing(trailing))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing trailing");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Set trailing parameters
   trailing.Step(Trailing_ParabolicSAR_Step);
   trailing.Maximum(Trailing_ParabolicSAR_Maximum);
//--- Creation of money object
   CMoneyFixedLot *money=new CMoneyFixedLot;
   if(money==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating money");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Add money to expert (will be deleted automatically))
   if(!ExtExpert.InitMoney(money))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing money");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Set money parameters
   money.Percent(Money_FixLot_Percent);
   money.Lots(Money_FixLot_Lots);
//--- Check all trading objects parameters
   if(!ExtExpert.ValidationSettings())
     {
      //--- failed
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Tuning of all necessary indicators
   if(!ExtExpert.InitIndicators())
     {
      //--- failed
      printf(__FUNCTION__+": error initializing indicators");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- ok
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Deinitialization function of the expert                          |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ExtExpert.Deinit();
  }
//+------------------------------------------------------------------+
//| "Tick" event handler function                                    |
//+------------------------------------------------------------------+
void OnTick()
  {
   ExtExpert.OnTick();
  }
//+------------------------------------------------------------------+
//| "Trade" event handler function                                   |
//+------------------------------------------------------------------+
void OnTrade()
  {
   ExtExpert.OnTrade();
  }
//+------------------------------------------------------------------+
//| "Timer" event handler function                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
   ExtExpert.OnTimer();
  }
//+------------------------------------------------------------------+
 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
dreamsky2007:

I'm facing one weird problem. I notice the EA i wrote is way slower than EA generated using EA generator wizard.

I'm trying to troubleshoot and eventually removed all codes and it is still slower than EA generated using the generator.
does anyone have the same problem? the "Empty EA" literally does nothing.

All other area remain constant during testing. e.g. using OLTP, using the same 6 months duration, same symbol etc.

How can an empty EA be "slower"? How do you even know when it's "done"?

Other than that, I'm thinking the most likely culprit is where you're putting your enries and exits. Are you doing it in OnTick()? Or are you somehow checking for a new candle and only processing indicator updates and entries/exits on new candles?

That was one of the biggest things I learned early on writing EAs -- unless you're doing something really weird, you probably don't need to do much on every tick, but only on new candles. That'll make a huge difference in EA speed.

 

@dreamsky2007

Your comment is unclear; are you saying that the Empty ea is slower than the "generated" ea?

 
Revo Trades #:

@dreamsky2007

Your comment is unclear; are you saying that the Empty ea is slower than the "generated" ea?

yes. i'm saying the EA without any logic in OnTick() running slower in tester compare to "generated" EA.

it also shown over profiler where a complex "generated" EA seems to have same CPU time with EA that laterally does nothing. (check the code in 1st post).

 
Scott Allen #:

How can an empty EA be "slower"? How do you even know when it's "done"?

Other than that, I'm thinking the most likely culprit is where you're putting your enries and exits. Are you doing it in OnTick()? Or are you somehow checking for a new candle and only processing indicator updates and entries/exits on new candles?

That was one of the biggest things I learned early on writing EAs -- unless you're doing something really weird, you probably don't need to do much on every tick, but only on new candles. That'll make a huge difference in EA speed.

for my own EA, i'm processing indicator updates only on new candles.


in this specific post, i'm referring to the EA that does nothing in OnTick() run slower than generated EA where it complete almost within 1 seconds, where the empty EA run for about 8-10 seconds over tester.
it also show almost the same cpu utilization over the profiler

 

dreamsky2007 #:

yes. i'm saying the EA without any logic in OnTick() running slower in tester compare to "generated" EA.

it also shown over profiler where a complex "generated" EA seems to have same CPU time with EA that laterally does nothing. (check the code in 1st post).

for my own EA, i'm processing indicator updates only on new candles.

in this specific post, i'm referring to the EA that does nothing in OnTick() run slower than generated EA where it complete almost within 1 seconds, where the empty EA run for about 8-10 seconds over tester.
it also show almost the same cpu utilization over the profiler

I am unable to reproduce your claims. I also tested the empty code without a return in OnTick() ...

2023.11.17 03:21:16.425 Terminal        MetaTrader 5 x64 build 4040 started for MetaQuotes Software Corp.
2023.11.17 03:21:16.425 Terminal        Windows 10 build 19045, 8 x Intel Core i7-4790T  @ 2.70GHz, AVX2, 7 / 15 Gb memory, 150 / 893 Gb disk, touchable, UAC, GMT+0

2023.11.17 03:25:07.172 Core 1  EURGBP,M1: testing of Experts\(Test)\empty with return.ex5 from 2022.01.02 00:00 to 2022.12.31 00:00 started
2023.11.17 03:25:08.758 Core 1  EURGBP,M1: total time from login to stop testing 0:00:07.972 (including 0:00:00.262 for history data synchronization)

2023.11.17 03:26:08.340 Core 1  EURGBP,M1: testing of Experts\(Test)\empty no return.ex5 from 2022.01.02 00:00 to 2022.12.31 00:00 started
2023.11.17 03:26:09.955 Core 1  EURGBP,M1: total time from login to stop testing 0:00:07.834 (including 0:00:00.113 for history data synchronization)

2023.11.17 03:26:58.267 Core 1  EURGBP,M1: testing of Experts\(Test)\generator.ex5 from 2022.01.02 00:00 to 2022.12.31 00:00 started with inputs:
2023.11.17 03:27:25.085 Core 1  EURGBP,M1: total time from login to stop testing 0:00:32.901 (including 0:00:00.105 for history data synchronization)

The "empty" run for 7-8 seconds, while the "generator" ran for 32-33 seconds, for 1 year of testing period on M1.

All code examples were compiled with "X64 Regular (Maximum Optimisation)" in non debug mode, and tested with real ticks.


Please provide information on how the code is being compiled on your end and what test settings you are using.

Also provide log output of the testing with the time stats as I have done. Include also details on build and operating system, ram, etc.

Reason: