Strange (incorrect?) behaviour of PrintFormat / StringFormat. Need help

Dr Matthias Hammelsbeck  

Hi,

today I stumbled across a very strange (or incorrect?) behaviour of the functions PrintFormat and/or StringFormat. Please see the following script:

void OnStart() {
   double            margin = 63.0;
   ENUM_ORDER_TYPE   otype  = ORDER_TYPE_BUY;
   PrintFormat("wrong   %s %s", StringFormat ("%0.5f", margin), EnumToString(otype));
   PrintFormat("correct %s %s", EnumToString(otype), StringFormat ("%0.5f", margin));
}


I get the following output:

2022.07.17 13:58:07.098 printformat (EURUSD,H1) wrong   63.00000 63.00000
2022.07.17 13:58:07.098 printformat (EURUSD,H1) correct ORDER_TYPE_BUY 63.00000


Of course I expect

2022.07.17 14:05:58.676 printformat (EURUSD,H1) wrong   63.00000 ORDER_TYPE_BUY

in the first output line.

What I'm doing wrong??

An auxiliary solution would be

void OnStart() {
   double            margin = 63.0;
   ENUM_ORDER_TYPE   otype  = ORDER_TYPE_BUY;
   string ms=StringFormat ("%0.5f", margin);
   PrintFormat("wrong   %s %s", ms, EnumToString(otype));
  }

But honestly I want to understand what is wrong here.

I use MT5 version 3360.


Thanks for every answer,

Matthias






Philippe Pauleau  

I've compiled your code using full optimization with build 3337 are here is the result:


2022.07.17 14:23:48.258 test (UsaInd,M1) wrong   63.00000 ORDER_TYPE_BUY

2022.07.17 14:23:48.259 test (UsaInd,M1) correct ORDER_TYPE_BUY 63.00000


void OnStart() {
   double            margin = 63.0;
   ENUM_ORDER_TYPE   otype  = ORDER_TYPE_BUY;
   PrintFormat("wrong   %s %s", StringFormat ("%0.5f", margin), EnumToString(otype));
   PrintFormat("correct %s %s", EnumToString(otype), StringFormat ("%0.5f", margin));
}



You have tried to compile with no optimizations ?

Dr Matthias Hammelsbeck  
Philippe Pauleau #:

I've compiled your code using full optimization with build 3337 are here is the result:


2022.07.17 14:23:48.258 test (UsaInd,M1) wrong   63.00000 ORDER_TYPE_BUY

2022.07.17 14:23:48.259 test (UsaInd,M1) correct ORDER_TYPE_BUY 63.00000




You have tried to compile with no optimizations ?

Thanks for your answer.

I tried both modes: full optimization and no optimization. It does not work correctly in both modes.

Strange, is'nt it?

Philippe Pauleau  
Dr Matthias Hammelsbeck #:

Thanks for your answer.

I tried both modes: full optimization and no optimization. It does not work correctly in both modes.

Strange, is'nt it?


Not strange when you are using a beta version, because last release build is 3337

Dr Matthias Hammelsbeck  
Philippe Pauleau #:


Not strange when you are using a beta version, because last release build is 3337

May be the reason . I will check this in any further version 
Reason: