Finding Performance Bottlenecks in EAs

 

My question is when developing an EA in MQL4, what are the best ways to finding the things in your code that are slowing backtesting the most? For example, can I see which lines are causing the CPU the most problem (I know something so literal might not exist, but what about a workaround)?  

 
TraderTogami:

My question is when developing an EA in MQL4, what are the best ways to finding the things in your code that are slowing backtesting the most? For example, can I see which lines are causing the CPU the most problem (I know something so literal might not exist, but what about a workaround)?  

To check runtimes of your code, you should look into GetMicrosecondcount ().

Wrapping code fragments with such will give you the time that fragment needs for execution.

 
TraderTogami: My question is when developing an EA in MQL4, what are the best ways to finding the things in your code that are slowing backtesting the most? For example, can I see which lines are causing the CPU the most problem (I know something so literal might not exist, but what about a workaround)?  

You can analyse your code using the "Profiler" in MetaEditor. Please refer to help reference in MetaEditor application.

On MT4, MetaEditor is actually a MT5 Editor, so refer to the MT5 online documentation — Code profiling - Developing programs - MetaEditor Help

Code profiling - Developing programs - MetaEditor Help
  • www.metatrader5.com
Profiling means collecting program parameters during its execution. During a profiling, the execution time and the number of calls of individual...
 

From encountering the same issues in the past, speeding up the backtesting can be done in numerous ways. The one that helped me the most going through some research was to use:

datetime lastBarTime = 0;

if (Time[0] != lastBarTime)
lastBarTime = Time[0];

Having multiple strategies that run on tick data, there may be some discrepancies with tick versus calling this into your code depending on the timeframe you are back testing. The higher the timeframe the more discrepancies you will see in comparison to the tick version of your EA. 

 
Fernando Carreiro #:

You can analyse your code using the "Profiler" in MetaEditor. Please refer to help reference in MetaEditor application.

On MT4, MetaEditor is actually a MT5 Editor, so refer to the MT5 online documentation — Code profiling - Developing programs - MetaEditor Help

Thanks, I never knew this existed. I think this was what I was looking for


Edit: Do you know why profiling on historical data would be blocked? 

Dominik Egert #:
To check runtimes of your code, you should look into GetMicrosecondcount ().

Wrapping code fragments with such will give you the time that fragment needs for execution.

Thanks, this should work as well


Adj007 #:

From encountering the same issues in the past, speeding up the backtesting can be done in numerous ways. The one that helped me the most going through some research was to use:

Having multiple strategies that run on tick data, there may be some discrepancies with tick versus calling this into your code depending on the timeframe you are back testing. The higher the timeframe the more discrepancies you will see in comparison to the tick version of your EA. 


I actively do this already, but this is helpful people who don't know 

 
@TraderTogami #: Do you know why profiling on historical data would be blocked? 

That functionality is only available on MT5. MT4 does not support historical tick data.

 
Fernando Carreiro #:

That functionality is only available on MT5. MT4 does not support historical tick data.

Ahh I see, thanks