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 should be, but it's not. What part of “sometime it returns an error (4030),” and “it's some type of race condition, highly variable,” was unclear?
Did you try the format I provided? Doing this will not create a race condition.
I see you are checking the event Timer in the condition statement. As I mentioned I do not understand your issue clearly . You are doing something weird in the condition statement.
What does your If statement do? ..... Lets consider this statement.
IF( !EventSetTimer(1))
This statement is setting the event timer to 1 second and checking to make sure it is not true. But the function EventSetTimer only sets the timer period. You are not actually checking to see if the timer went off. What your if statement is doing is not setting the event timer to 1 second. So, Of course a error will result.
Again, consider using the two built in functions OnInit() and OnTimer().
OnInit() is run once. Here you set the EvenSetTimer to 1 second. so that you have the period of the event timer defined.
To do something every second use the OnTimer() which is called every second....because the EventSetTimer has set the period to 1 second.
Does this make sense?
Good luck,
Chris
The issue occurs because MetaTrader does not seem to handle setting the timer very well. If more that one program is trying to set the timer concurrently, it only serves the first one and rejects the others. It does not queue the requests and only the first one gets handled.
In order to get around this, the program needs to keep retrying until the requests can be satisfied.
The format you used causes the program to immediately terminate if it fails setting the timer and that is not ideal. Imaging starting MetaTrader from a previous session with several programs attached to charts being terminated, and then you have to manually restart them all again. Not ideal! Not practical.
And if the EvenSetTimer fails, you do not recover and your code fails! Does this make sense?