Tony A Antony: prevent the 4 charts from writing to a particular terminal global variable at the same time.
Use a Mutex for that.
Prevent EA from opening trades at the same time across 2 or more pairs? - MQL4 programming forum - Page%nbsp;2 #11 (2022)
William Roeder #:
Use a Mutex for that.
Prevent EA from opening trades at the same time across 2 or more pairs? - MQL4 programming forum - Page%nbsp;2 #11 (2022)
Thank you for pointing me in the right direction. I have replied on that thread with a query. Please go through it.
Tony A Antony:
code:
int timerinterval; do { timerinterval=MathRand(); } while((timerinterval<1000) || (timerinterval>10000));
is equivalent to code
int timerinterval = 1000 + ((rand()<<15)|rand())%9000;

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I have 4 charts setup with my EA on an MT4 terminal. A portion of the code needs to generate a random number, which will then be used as the interval for a timer. This is done to prevent the 4 charts from writing to a particular terminal global variable at the same time. This is my code to initialise random number generator.
Then I use this to generate a random number between 1,000 and 10,000 and use it as the interval for a millisecond timer.
I call this function once every M15 bar. The problem is throughout the day multiple times I can see two of the four charts getting the same 4 digit number for timerinterval, which defeats the purpose. So my question is whether there is a way to generate truly random numbers across multiple charts running the same EA in a single terminal.