Bool to String - page 2

 

anuj71 #: Error : 'booltostring' - function not defined    output.mq4    31    7

For me, it giving values like 0 and 1. 0 For false and 1 for True. 

Both returning values 0 not "FALSE". 

You got a compile error because there is no such function as "booltostring".

You are getting 0 and 1, because you are not using "#property strict". Always use it.

Place it right at the beginning of your code ...

#property strict

Example ...

#property strict

void OnStart() {
   bool   bTakeProfit = true;                 // it is "true" and not "TRUE"
   string sTakeProfit = (string) bTakeProfit; // explicit typecasting to a string
   
   // The following will all output "true" ...
      Print(          bTakeProfit ); // Method 1 ... implicit typecasting 
      Print( (string) bTakeProfit ); // Method 2 ... explicit typecasting to a string
      Print(          sTakeProfit ); // Method 3 ... variable is already a string
};

Output ...

With "strict" ...

2024.02.02 12:15:05.219 TestStrict EURUSD,M1: true
2024.02.02 12:15:05.219 TestStrict EURUSD,M1: true
2024.02.02 12:15:05.219 TestStrict EURUSD,M1: true

Without "strict" ...

2024.02.02 12:14:34.856 TestStrict EURUSD,M1: 1
2024.02.02 12:14:34.856 TestStrict EURUSD,M1: 1
2024.02.02 12:14:34.856 TestStrict EURUSD,M1: 1
Reason: