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

 
Anatoli Kazharski #:

Try this:

Result:
And to keep the Internal sources untouched?
 
amrali #:
Also division by / 1000 may be slow. Try a faster (3x) multiplication * 0.001 if it makes a difference.

It does, indeed, make a difference! Thanks.

Forum on trading, automated trading systems and testing trading strategies

Libraries: TicksShort

fxsaber, 2025.11.18 12:57 pm.

Absolutely free compression performance has been raised by almost 40%!


If real division is executed millions of times, it is reasonable to replace it with multiplication.


Where similar code can be executed millions of times.

  • Expert Advisor/Indicator in Tester.
  • Your own tester.
  • Canvas.
  • And other work with large data arrays (compression/coding, etc.).
 

Who knows JSON, please share a ready solution with the functionality of these two buttons.

bool SymbolExport( const string Symb, const string FileName ); // Export symbol's json-data.
bool SymbolImport( const string Symb, const string FileName ); // Import symbol's json-data.

Should create and read exactly the same json as MT5 does through the labelled buttons on the screenshot.


Need for a public torrent with backtest data. Thanks.

 

Question about macros. I want to set a variable x5 to the value 5 through a macro, compiling the name of this variable.

This code does not compile:

char x3 = 0, x4 = 0, x5 = 0, o = 0;
#define num o
#define mcr(z) x##z = 5;
#define macro(z) o = z == 3 ? 5 : 3; mcr(num)
macro(3)
Print("x3 = ",x3,", x4 = ",x4,", x5 = ",x5);

As I think the problem is that the value of variable o is not passed to mcr. Is there any way to solve this problem?

 
Andrei Iakovlev #:

Question about macros. I want to set a variable x5 to the value 5 through a macro, compiling the name of this variable.

This code does not compile:

As I think the problem is that the value of variable o is not passed to mcr. Is there any way to solve this problem?

The compiler cannot resolve a (future) runtime value to expand the macro mcr(num) at compile-time.

The mcr(z) is using the concat operator (##), thus it must be resolved (expanded) at compile-time only.

 
amrali #:

The compiler cannot determine the (future) runtime value for the mcr(num) macro extension at compile time.

The mcr(z) macro uses the concat operator (##), so it should only be allowed (expanded) at compile time.

Understood.

Is there any other way to solve this task? Is it possible to set variable names through conditions?

 
The condition must be resolved at compile time. This can be done using #ifdef and #ifndef.
 
amrali #:
The condition must be resolved at compile time. This can be done using #ifdef and #ifndef.

Such code will not compile either.

char x3 = 0, x4 = 0, x5 = 0, o = 5;
#define  num o
#define  mcr(z) x##z = 5;
mcr(num)
Print("x3 = ",x3,", x4 = ",x4,", x5 = ",x5);

o is already equal to 5 and the x5 variable is defined. Where is the error?

 
Andrei Iakovlev #:

Such code will not compile either.

o is already equal to 5 and the x5 variable is defined. Where is the error?

The preprocessor knows nothing about the value of 'o' or any variable.

What are you REALLY trying to achieve ?

 
Andrei Iakovlev #:

Such code will not compile either.

o is already equal to 5 and the variable x5 is defined. Where is the error?

If you want to get "computable" variable names, use arrays.