Hello,
I am using an infinite loop with a "Sleep" on my "OnStart" because I want to keep track of my positions at all time.
The program works great so far, however, once I stop it, the "Sleep(5000)" (which is 5s sleep) seem to brake, and my infinite loop is getting called thousands of times in a few milliseconds, until eventually the program crashes.
Do you have any idea of what could cause this "Sleep" issue ?
Thank you for your help :)
you need to post your code otherwise it's just guess work....
but why don't you use a timer event instead, probably a neater solution.
void OnStart() { while (1) { OpenNewPositions(); CloseOldPositions(); Print("Infinite Loop"); Sleep(5000); } }
In here, I'm doing open/close position thing, it seem to work as intended. But as soon as I stop my program, my Print "Infinite Loop" get
triggers a huge amount of times in a few millisecond, until the program crashes.
My guess is that there is an issue with MQL5 when a program
gets stopped. Or maybe I should add something else in my infinite loop, I don't really know. What's sure is that it happens the second after I
stop the program.
After a few research, I thought people were using the same solution as me (using an infinite loop). But if there is a more clean solution, I'm all ears.
In here, I'm doing open/close position thing, it seem to work as intended. But as soon as I stop my program, my Print "Infinite Loop" get
triggers a huge amount of times in a few millisecond, until the program crashes.
My guess is that there is an issue with MQL5 when a
program gets stopped. Or maybe I should add something else in my infinite loop, I don't really know. What's sure is that it happens the
second after I stop the program.
After a few research, I thought people were using the same solution as me (using an infinite loop). But if there is a more clean solution, I'm all ears.
like I said use a timer event instead, much cleaner way to achieve what you want which is to do something every X seconds.
https://www.mql5.com/en/docs/eventfunctions/eventsettimer
set the timer up once in OnInit and then create an OnTimer() function to include what you want done

- www.mql5.com
Don't do that. Get a tick. See if something needs to be done and do it. Return and wait for a new tick.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I am using an infinite loop with a "Sleep" on my "OnStart" because I want to keep track of my positions at all time.
The program works great so far, however, once I stop it, the "Sleep(5000)" (which is 5s sleep) seem to brake, and my infinite loop is getting called thousands of times in a few milliseconds, until eventually the program crashes.
Do you have any idea of what could cause this "Sleep" issue ?
Thank you for your help :)