Hey, I have an EA that gets the Stack Overflow error if I don't put a Sleep of something like 1 second. I do have a loop that calls itself (something like an infinite loop) but I need to find a way to do this and not get the Stack Overflow error.
The infine loop is something like this:
Based upon what you've written, I would suggest that you pull the loop logic out of the search logic.
Have your Search() function return a boolean:
true = found; false = not found.
Then, have a loop that calls your Search() function.
You might even rename your function to something logical to enhance readability, e.g.
bool IsGoodStock() { // returns true if good stock found; false otherwise }
Then you might do something like:
while ( true ) { if ( IsGoodStock() ) { // do something } }
So, you get the benefit of the infinite loop without loading up the stack.
You'll probably want some logic to get you out of the infinite loop.
Based upon what you've written, I would suggest that you pull the loop logic out of the search logic.
Have your Search() function return a boolean:
true = found; false = not found.
Then, have a loop that calls your Search() function.
You might even rename your function to something logical to enhance readability, e.g.
Then you might do something like:
So, you get the benefit of the infinite loop without loading up the stack.
You'll probably want some logic to get you out of the infinite loop.
Thanks, I got it working this way...
Thanks again
void Search(){ if(IsGood){ //Do anything }else{ Search(); } }
- When you post code please use the CODE button (Alt-S)!
(For large amounts of code,
attach it.)
Please edit
your post.
General rules and best pratices of the Forum. - General - MQL5 programming forum
Messages Editor - Sleep is irrelevant. You have recursive loop. Search is calling Search. Search should loop through your items and find what you want.

- net-informations.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey, I have an EA that gets the Stack Overflow error if I don't put a Sleep of something like 1 second. I do have a loop that calls itself (something like an infinite loop) but I need to find a way to do this and not get the Stack Overflow error.
The infine loop is something like this:
My EA searches for a good stock, if it doesn't find any, start all over again (calling the same function where this code is inside).
Ex:
void Search()
{
if(IsGood)
{
//Do anything
}else{
Search();
}
}
Thanks