mutex - win ap i
Info
The mutex - win ap i is a Library for MetaTrader 5 that why this is necessary global variables, disk or memory-mapped files, important operating procedure are not a problem anymore. if you use:calls to the same data from different experts work with other applications from mql in general data your copiers work in various mt4-mt4 / mt4-mt5 / mt5-mt5 terminals (hello, urain :) or you just need to comply with exact operating procedures among different experts of one or different terminals, you shall understand how important is that performed algorithms do not appeal to same data via different processes simultaneously.
Usage
This tool is typically used for enhancing chart analysis and decision making.
Platform
This Library works exclusively on MetaTrader 5 (both build 600+ and newer versions).
Setup
Place the downloaded file in MQL5/Libraries folder via File ? Open Data Folder in MetaTrader 5.
How to Install and Use mutex - win ap i
1. Storage: Place library files in the MQL/Libraries directory to ensure they are accessible to your projects.
2. Implementation: Include the library in your code using the #import directive, ensuring you match the exact function names and parameters.
3. Compilation: Ensure the library is present in the directory before you compile your main EA or script, as the compiler links them during this phase.
4. Management: Keep libraries organized in sub-folders if you manage many custom functions to maintain a clean project structure.
Frequently Asked Questions
Q: What is a library file used for? A: Libraries store reusable code modules, allowing you to centralize common logic used by multiple EAs or indicators.
Q: Is a library executable? A: No, libraries are non-executable files containing functions; they must be imported into an EA, indicator, or script to function.
Q: Can I update a library while the platform is running? A: You should compile your EA or script after updating a library to ensure the latest code changes are integrated.
What this tool does
why this is necessary global variables, disk or memory-mapped files, important operating procedure are not a problem anymore.
Typical Use Case
This Library excels in automated trading and technical analysis on MetaTrader 5.
Compatible Platform & Setup
This Library works on MetaTrader 5. Place the file in the MQL5/Libraries folder and restart the terminal.
Description & Settings
Related: Trading Signals Module Based on GO Indicator - another powerful library for MetaTrader 5 traders.
why this is necessary
global variables, disk or memory-mapped files, important operating procedure are not a problem anymore!
Also recommended: permutations and combinations - similar library with strong performance on MetaTrader 5.
if you use:calls to the same data from
different
experts
work with
other
applications from mql in general data
your copiers work in various mt4-mt4 / mt4-mt5 / mt5-mt5 terminals (hello, urain :)
or you just need to comply with exact operating procedures among different experts of one or
different
terminals,
you shall understand how important is that performed algorithms do not appeal to same data via different processes simultaneously. as it can result in unexpected effects: one process is writing, and the other one is reading and making some decision, and renewing these data at the same time.
in such a case if writing of data by first process hasn't been finished it may lead to incorrect work of the second process, as a result the data may be damaged.
the solution
we use objects of
mut
ual
ex
clusion operating system, in other words
mutex.
how it works
the mutex is very simple. we use a principle similar to the principle described in : locking a resource when an object is created, and deallocation of a resource when an object is removed.
working with mutex is implemented in two classes.
the first class -
cmutexsync
- represents mutex handle resource, which is created and deallocated by this class. an object of this class can be global and the one for the whole application.
the second class -
cmutexlock
- is a locked object which awaits for deallocation and locks mutex handle when created, and deallocates it when removed.
due to the locking principle of mutex makes the code nice and readable. it frees the code from winapi functions
example
in this example we will synchronize operation of cycles of two scripts in two charts.
the first script performs some operations for too long (2 seconds in the example). the second script performs its operations in a rapid manner (0.2 second).
our task is
not to allow new iteration of the rapid script until the first script completes its current iteration
.
result
mutex (eurusd,m1) eurusd mutexsync created ok! sleep=2000mutex (eurusd,m1) eurusd lock scopemutex (eurusd,m1) eurusd lock scopemutex (audcad,h1) audcad mutexsync created ok! sleep=200mutex (audcad,h1) audcad lock scopemutex (eurusd,m1) eurusd lock scopemutex (audcad,h1) audcad lock scopemutex (eurusd,m1) eurusd lock scopemutex (audcad,h1) audcad lock scopemutex (eurusd,m1) eurusd lock scopemutex (audcad,h1) audcad lock scopemutex (eurusd,m1) eurusd lock scopemutex (audcad,h1) audcad lock scopemutex (eurusd,m1) eurusd lock scopemutex (audcad,h1) audcad lock scopemutex (eurusd,m1) eurusd lock scopemutex (audcad,h1) audcad lock scopemutex (eurusd,m1) eurusd lock scopemutex (audcad,h1) audcad lock scopemutex (eurusd,m1) eurusd lock scopemutex (audcad,h1) audcad lock scope
32/64 ready
the library works taking into account 32/64 bit count in a similar way to .
i wish you good luck and big profits!
You may also like: smooth algorithms - corrected/modified - excellent alternative for library users on MetaTrader 5.
Source Code
#property copyright "robotfx"
#property link "https://robotfx.org"
#property version "1.00"
#include <mqh\lib\mutex.mqh>
#property script_show_inputs
input int sleep=200;
void onstart()
{
sleep(5000); // ,
cmutexsync sync; //
.......
⚠ Limitations & Risk Warning
- This tool is provided for educational and testing purposes only.
- Past performance does not guarantee future results.
- Trading involves substantial risk of loss. Use on a demo account first.
- Results may vary depending on market conditions, broker, and settings.
- We recommend thorough backtesting and forward testing before using with real funds.