Getting name of a variable as string

 
Hi, is there any way to get a variable name as string?

For example:
   bool isHigh = false;

I need to get the variable name "isHigh" as string value. 
 
Pourya Ebrahimi: Hi, is there any way to get a variable name as string?

MQL is a compiled language and so you cannot get the variable name at runtime.

However, you can prepare a macro to generate the variable name as a string at compile time, which is called "stringification".

Forum on trading, automated trading systems and testing trading strategies

any way to store expression into a variable or array?

Fernando Carreiro, 2022.08.18 21:03

There is also a way of using macros to "stringify" the expression, so that you don't have to type the expression twice. This will help keep the code consistent when you update the expressions.

However, this is a more power programmer coding skill that needs careful planing of the code logic, but you can research the "#" Stringification functionality of the standard C/C++ preprocessor which also works on MQL.


 
Pourya Ebrahimi:
Hi, is there any way to get a variable name as string?

For example:
   bool isHigh = false;

I need to get the variable name "isHigh" as string value. 
#define TO_STRING(v)  #v  
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
    bool isHigh = false;
    string variableName = TO_STRING(isHigh);
    Print(variableName," = ",isHigh);
    return;
 }

2023.01.18 15:15:30.943    ...    isHigh = false