I see that it is most often used in cycles in the latest indicators. Shoveling the branches that were raised on this occasion. Someone writes that this function is not needed at all. Someone writes the type needed. As for me, there is no reason to check whether the program is closed, because if it is closed, then it will close and why check it?
Because for me, as I see now, this function has no use, but still I use it, the question arose why do they use it at all?
My thoughts are:
For example, there is a function that opens orders in the standard library. At the beginning, IsStopped () is checked. What for? After all, if, for example, when the program is running and the queue has reached the point where this check takes place, the check:
bool CTrade::OrderOpen(const string symbol,const ENUM_ORDER_TYPE order_type,const double volume,const double limit_price,
const double price,const double sl,const double tp,
ENUM_ORDER_TYPE_TIME type_time,const datetime expiration,const string comment)
{
//--- check stopped
if(IsStopped(__FUNCTION__))
return(false);
the program execution will end and the order will not be sent. Then why do we need this 2 (3) extra lines of code? After all, whatever you say, the program will not continue to run because it is already closing.. (if it closes).
rickd2
It is probably a common approach to add a check for IsStopped at the beginning of most CTrade functions. Some functions may internally expect something in a loop, so in order not to bother and keep the behavior of each function in memory, it is easier to add IsStopped everywhere.
scriptong
Without IsStopped (), the program, if it performs some complex calculations, will crash, which is not very good. This is especially true for programs that display data using graphical objects. An emergency shutdown will leave all readings of such a program intact. First, it’s garbage on the chart. Secondly, the user gets the impression that the program is frozen, and not disabled.
Before opening an order, IsStopped() is checked for the same reason. If the user decides to remove the program from the chart, then it is not necessary to perform a trading operation, which takes quite a long time. As a result, the risk of an emergency program termination increases.
For indicators, due to their use of cycles, this is generally an indispensable thing. After all, the execution of an infinite loop in the indicator suspends the chart (MT5)or the entire terminal (MT4).