MT5/mql5 reported and confirmed bugs. - page 11

 

The documentation states () that :

The call of ChartSetSymbolPeriod with the same symbol and timeframe can be used to update the chart (similar to the terminal's Refresh command). In its turn, the chart update triggers re-calculation of the indicators attached to it. Thus, you are able to calculate an indicator on the chart even if there are no ticks (e.g., on weekends).

So we are talking about this statement :

ChartSetSymbolPeriod(0,NULL,0);

When used within an indicator launched with iCustom() on a different symbol as the chart symbol, it changes the CHART symbol !

 

Wrong datatype for _StopFlag.

Documentation: https://www.mql5.com/en/docs/predefined/_stopflag

It says _StopFlag is boolean type, compiler says, it is not.

const bool get_StopFlag()
{
    return(_StopFlag);
}



int OnInit()
{
    printf("StopFlag status: %s", (get_StopFlag()) ? "TRUE" : "FALSE");
    return(INIT_FAILED);
};

void OnDeinit(const int reason)
{
    printf("deinit reason: %i", reason);
};

Result:



Terminal and compiler build: 4232

Documentation on MQL5: Predefined Variables / _StopFlag
Documentation on MQL5: Predefined Variables / _StopFlag
  • www.mql5.com
_StopFlag - Predefined Variables - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Print(typename(_StopFlag));
 
amrali #:

This bug is still not fixed. Why?

 

Bug in MQLInfoString(MQL_PROGRAM_NAME)

When adding multiple copies of a service, the naming of these services is broken.


Procedure to reproduce the bug:

Add two or more of the services, close the terminal and start the terminal again. - All services will receive the same name, the numbering is dropped.

Also, another failure in naming, if you add 2 or more instances of the same service, and remove the one without a name, now add another copy of the service it will receive the same name as the last already added name.


Code to reproduce:


//+------------------------------------------------------------------+
//|                                               ProgramNameBug.mq5 |
//|             Copyright 2024, Freie Netze UG (haftungsbeschraenkt) |
//|                                       https://www.freie-netze.de |
//+------------------------------------------------------------------+
#property service


const bool func_call(const string prg_name)
{
    printf("Start: %s", prg_name);

    return(true);
};



bool at_startup = func_call(MQLInfoString(MQL_PROGRAM_NAME));


//+------------------------------------------------------------------+
//| Service program start function                                   |
//+------------------------------------------------------------------+
void OnStart()
{
    const ulong start = GetMicrosecondCount();
    string program_name = NULL;
    string get_value = NULL;

    while(!_StopFlag)
    {
        get_value = MQLInfoString(MQL_PROGRAM_NAME);
        if(program_name != get_value)
        { printf("%llu: %s", GetMicrosecondCount() - start, get_value); }        
        program_name = get_value;
    }

}
//+------------------------------------------------------------------+


Result at terminal start:


Result when adding another service after removing the one without number:


Please fix, as it is impossible to identify an instance.

 
Dominik Egert #:

This bug is still not fixed. Why?

This bug has been fixed, the documentation was updated such, that the type of _StopFlag now is not bool, but int.



EDIT:

A patch, such that _StopFlag is actually bool again:

#define _StopFlag   !!_StopFlag


Here how to use example:

//+------------------------------------------------------------------+
//|                                               ProgramNameBug.mq5 |
//|             Copyright 2024, Freie Netze UG (haftungsbeschraenkt) |
//|                                       https://www.freie-netze.de |
//+------------------------------------------------------------------+
#property service


#define _StopFlag   !!_StopFlag

const bool stopflag()
{ return(_StopFlag); };


//+------------------------------------------------------------------+
//| Service program start function                                   |
//+------------------------------------------------------------------+
void OnStart()
{
    const ulong start = GetMicrosecondCount();
    string program_name = NULL;
    string get_value = NULL;

    while(!stopflag())
    {
        get_value = MQLInfoString(MQL_PROGRAM_NAME);
        if(program_name != get_value)
        { printf("%llu: %s", GetMicrosecondCount() - start, get_value); }        
        program_name = get_value;
    }

}
//+------------------------------------------------------------------+

Documentation on MQL5: Predefined Variables / _StopFlag
Documentation on MQL5: Predefined Variables / _StopFlag
  • www.mql5.com
The _StopFlag variable contains the mql5 program stop flag equal to 0 during normal operation. When the client terminal tries to stop the program...
 
Dominik Egert #:
This bug has been fixed, the documentation was updated such, that the type of _StopFlag now is not bool, but int.



EDIT:

A patch, such that _StopFlag is actually bool again:


Here how to use example:

IsStopped() is not suitable for you ?
 
Alain Verleyen #:
IsStopped() is not suitable for you ?
I was thinking about that actually. My thought process is somewhat around these lines:

Accessing a variable is faster than calling a function.

Will IsStopped() be optimized by the compiler to inline and actually be a variable check in the end? - I don't know.

Is making an int behave like a bool by using double negation on compiler level and then being optimized to a variable check? More probable than a function inline optimization.

It might be negligent, but that's the reasoning I applied.

EDIT:

What bothers me is the solution to the bug MQ has offered. After all, it's been bool for a very long time (as far as I know) and simply silently changing the docs seems to me to violate "never Break user-space". After all, it's called _StopFlag, and therefore it suggests to be a bool in the first place. Turning it into an int doesn't seem to be the appropriate approach to me.

EDIT2:

Maybe this patch is better:

#define _StopFlag   (bool(_StopFlag))
 
Dominik Egert #:

Bug in MQLInfoString(MQL_PROGRAM_NAME)

When adding multiple copies of a service, the naming of these services is broken.

Please fix, as it is impossible to identify an instance.

Fixed. Thank you

 
Alexey Petrov #:

Fixed. Thank you

First bug fixed, but not the second one.

Build 4392.