I Need Advice on Optimizing MQL5 Code for Better Performance

 
Hello everyone,

I am currently working on an Expert Advisor (EA) for MetaTrader 4 and I've noticed that its performance is not quite as expected. I’ve implemented several strategies and optimizations, but I'm still seeing inconsistent results.

Could anyone share some tips or best practices for enhancing the performance of an EA? Specifically, I’m interested in advice on optimizing code, improving execution speed, and effectively handling different market conditions.

I also check this: Is the linear deceleration a programming error or a feature gcp ;But I have not found any solution. Could anyone provide me the best solution for this. and suggest any insights or suggestions would be greatly appreciated!

Thanks in advance!
MT5 Optimization how to speed up runtime
MT5 Optimization how to speed up runtime
  • 2022.06.25
  • KjLNi
  • www.mql5.com
Hello, I am using a server for running MT5. When I do optimisations, I can split it on up to 8 CPU's. Still it is running not extremely fast...
 

Why do you use MT4 instead of MT5 and ask for a better performance:


 
valak90: I’m interested in advice on optimizing code, improving execution speed, and effectively handling different market conditions.
  1. The first two is optimizing the code.

    1. EAs : Don't do per tick what you can do per bar, or on open.
      If you are waiting for a level, don't reevaluate, wait until price reaches it (or a new bar starts, and you recalculate.)
      If you are waiting for an order to close, only look when OrdersTotal has changed. (In MT5 capture the deal out)
                How to get backtesting faster ? - MT4 - MQL4 programming forum (2017)

    2. Indicators: Code it properly so it only recomputes bar zero (after the initial run).
                How to do your lookbacks correctly. (2016)
                3 Methods of Indicators Acceleration by the Example of the Linear Regression - MQL5 Articles. (2011)
      Or, reduce Tools → Options (control+O) → Charts → Max bars in chart to something reasonable (like 1K.)

  2. The last one is optimizing your strategy. Without the strategy and your implementation of it, no answer is possible.