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.
- https://users.informatik.haw-hamburg.de/~krabat/FH-Labor/gnupro/2_GNUPro_Compiler_Tools/The_C_Preprocessor/cppStringification.html
- https://renenyffenegger.ch/notes/development/languages/C-C-plus-plus/preprocessor/macros/stringify
- https://docs.microsoft.com/en-us/cpp/preprocessor/stringizing-operator-hash?view=msvc-170
Hi, is there any way to get a variable name as string?
#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

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use