Query: DLL Usage and Synchronization in Multi-threaded Backtesting

 

Hello MQL5 Community,

I have some questions regarding the use of DLLs during multi-threaded backtesting in MetaTrader 5, based on the documentation I found:

  1. Multiple Instances: From the documentation, it seems that if a DLL is already loaded (even by another Expert Advisor or client terminal), it will be shared rather than creating multiple instances. Can someone confirm if this understanding is correct? How does this affect thread safety, especially when the same DLL functions are called from multiple threads?

  2. Synchronization: Since DLL functions are executed in the thread of the calling module, and synchronization is not managed by the MetaTrader backtesting engine, what are the best practices for handling synchronization within the DLL? Specifically, how can I ensure that shared resources are accessed safely and efficiently in a multi-threaded environment?

Any insights, experiences, or best practices on managing DLL usage and ensuring thread safety during backtesting would be greatly appreciated.

Thank you!

Best regards,
Ramzi

Testing trading strategies on real ticks
Testing trading strategies on real ticks
  • www.mql5.com
The article provides the results of testing a simple trading strategy in three modes: "1 minute OHLC", "Every tick" and "Every tick based on real ticks" using actual historical data.