Is "while(!IsStopped())" expected to work on Indicators? - page 2

 

_StopFlag issue is already reported to MetaQuotes.

In all cases it's a bad practice to use such loop in an indicator.

 
Alain Verleyen #:

_StopFlag issue is already reported to MetaQuotes.

In all cases it's a bad practice to use such loop in an indicator.


Agree, its only really valid in services. Thank you for reporting.


 
Dominik Egert #:
Stop screwing this user. _StopFlag isnt working. Its a bug. I have reported this. Never got fixed.

Using Sleep() is not a solution. - Sleep() could be using a "noop" but who knows, right?

Documentation is clear on this. API is not behaving as documented -> Bug.
Fixed. Available in next build after 5836.
 
Alain Verleyen #:
Fixed. Available in next build after 5836.
Halleluiah! 🥳
 
Alain Verleyen #:
Fixed. Available in next build after 5836.
Nice. Thanks for the follow up.
 

here's a way to structure this that sidesteps the problem entirely. Indicators support OnTimer, so instead of blocking OnCalculate with a while or do-while loop, history can load in small batches on a timer while OnCalculate stays fast every time it's called.

Set a millisecond timer in OnInit with EventSetMillisecondTimer(50) or similar. In OnTimer, request one batch of ticks with CopyTicks or CopyTicksRange, process that batch, update LAST_TICK_TIME, and return immediately rather than looping until everything is copied. The next OnTimer call picks up where the last one left off.