Features of the mql5 language, subtleties and tricks - page 317

 
Vitaly Murlenko #:
Then you need to ask your question differently. I would ask: "Who knows if there are functions in the language that affect the Expert Advisor journal?".

For example, fxsaber has the TerminalJournalClear function in the MTTester.mqh file.

https://www.mql5.com/en/code/26132

 
Andrei Iakovlev #:

For example, fxsaber has the TerminalJournalClear function in the MTTester.mqh file.

https://www.mql5.com/en/code/26132

Here is the code of this subroutine:

static bool TerminalJournalClear( void )
  {
    return(!::IsStopped() && user32::SendMessageW(MTTESTER::GetTerminalHandle(), WM_COMMAND, 0 X8135, 0));
  }

What do we see in it? Stopping, sending a message, receiving a terminal handle. How does it affect the log?

I don't think it will be of much use to you.

P.S..

I checked the word Journal in the MQL5 Help. This term is used 1 time and only in LeastSquaresSolutionWY. See Matrix and Vector Methods. But I think this is not your topic.

It would be logical to name log functions in such a way that the word log is present in them. I may be wrong, but in my opinion it is highly probable that the influences you need on the journal of advisors simply do not exist in the language. Frankly speaking, for almost 2 decades of interaction with the MQL language, this is the first time I have encountered the need for someone to influence this journal programmatically. This brings us back to the original question: what is the need for this? Is it just a desire (which can be done without), or is it a need?

 

Forum on trading, automated trading systems and testing trading strategies

Peculiarities of mql5 language, subtleties and techniques of work

Vitaly Murlenko, 2025.11.02 11:28 AM

    return(!::IsStopped() && user32::SendMessageW(MTTESTER::GetTerminalHandle(), WM_COMMAND, 0 X8133, 0));  

This code.

 
fxsaber #:

This kind of code.

Thanks, it works.

Vitaly Murlenko #:
How does it affect the log?

It affects the log so that the log is cleared.

 
fxsaber #:

This kind of code.

Is there any way to know the current state ofautoscrolling, whether it is on or not?
 
Andrei Iakovlev #:
Is there any way to know the current state ofautoscrolling, whether it is on or not?
I don't know.
 
Can you please tell me where I make a fundamental error in working with macros?
struct STRUCT
{
  int Value;
  
  void Func( int ) {}
};

#define  MACROS(A) Struct##A

void OnStart()
{
  STRUCT Struct;

  MACROS(.Value) = 0; // The first entry is OK.
  MACROS(.Func(0));   // The second entry is OK.

  MACROS(.Func(MACROS(.Value))); // First and second entry together - undeclared identifier.
}

This will not work in other languages either? What is the right way?


I understand that in MQL5 an external macro is opened first, and then only the internal macro is opened. What construct should I use to make it possible to do it the other way round?


I have to guess, as it is not implemented.

Forum on trading, automated trading systems and testing trading strategies

New version of MetaTrader 5 build 5320: services in the Code Library and convenient work with inputs in MQL5

fxsaber, 2025.09.25 16:14

Please supplement this error message in ME with the name of an undefined identifier.
#define  MACROS(A) A = 5;

void OnStart()
{
  MACROS(Tmp); // undeclared identifier Tmp
}

In complex macros it would help a lot to identify the causes of the error. Thanks.

 
fxsaber #:
Can you please tell me where I make a fundamental error in working with macros?

This will not work in other languages either? What is the right way?

struct STRUCT
{
  int Value;

  void Func( int ) {}
};

#define  MACROS(A) Struct##A
#define  MACROS2(A) MACROS(A)

void OnStart()
{
  STRUCT Struct;

  MACROS(.Value) = 0; // The first entry is OK.
  MACROS(.Func(0));   // The second entry is OK.

  MACROS2(.Func(MACROS2(.Value))); // First and second entry together - undeclared identifier.
}

Solution: use a 2nd level macro (for indirection).

This was discussed before here and here.

 
amrali #:

Solution: use a second level macro (for redirection).

This has already been discussed here and here.

Thank you very much!
 
Another situation where "double expansion" of macros (__LINE__) is necessary:
#define ST2(x) #x
#define STR(x) ST2(x)
#define LOCATION __FILE__ " : " STR(__LINE__)

//#define LOCATION __FILE__ " : " __LINE__

void OnStart()
{
  Print("Error in ", LOCATION);
}
or directly as:
#define LOCATION __FILE__ + " : " + (string)__LINE__

Using the string() function at runtime (but not evaluated at compile-time as in the first example).