![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Bodolino #:
it is now finally possible to create variables dynamically in MQL5 like this:
Oh no: I'm wrong, dynamic varibale creation has been possible all along!
What I really wanted to ask is:
1. Please explain __isNew_inner in detail
2. With your new macro string capabilities, is it now somehow possible to do away with my above isChanged1() -helper function and make isNew() a more or less self-contained macro, e.g. by doing something like this (just so it compiles & works):
You know, my point is to not always reuse thes same last-comparison variable because it would be shared across macro calls and mix up results.working version of code
Your main misunderstand: macro is not a function, it is the part of the text processor:
In this case lexeme '__COUNTER__' passed to macro ISNEW will be replaced by parser to actual number
See expanding stepsworking version of code
Hi Ilyas,
thank you very much for your answer. I have read everything here and also the docs on MQL5 macros in detail, but I still don't exactly understand e.g. this:
Why is __COUNTER__ still __COUNTER__ after the first expansion, but a number (0 in our case) after the second expansion?
I also don't understand what exactly changed with macros with build 3950...
Also, your above code...
...throws the compilation error 'return' - 'void' function returns a value . So I refactored it into:
Does that look good to you?
To test the above code snippet in action with actual, random values over time, I wove it into the following code (an indicator which each second creates new, random values of different types within a small range and prints whether they have changed or not):
However, if you compile that code as it is, you'll get a whole bunch of macro-related errors like:
May I kindly ask you to explain it so that I can fix my code or — if you are especially kind — explain it by fixing my code with comments what you changed and why?
I'm really sorry to bother you, but the docs are a bit thin on macros and so are the articles, too. And you seem to be te only person around who has a deep understanding of this matter.
Of course you have errors, you can't declare variable inside a print statement.
Macros processing will now work as C++. You can eventually read about C++ preprocessor to see how it works.
Of course you have errors, you can't declare variable inside a print statement.
Macros processing will now work as C++. You can eventually read about C++ preprocessor to see how it works.
Yes, true, but my intention to use that isNew-macro inside e.g. if-statements was clear from the start. I already had resolved this with my helper-functions, but it's an unelegant approach, so please let my question stand for Ilyas, the macro-expert right at the source and maker of the MQL5 preprocessor, to respond. Maybe he knows a way around it. And judging from your posts, you were adversely affected by the recent macro-changes in MQL5, too, so why hit at me now.
Anyway, if you know a good C++ tutorial on that matter (although it's not exactly the same as MQL5 and MQL5 is obviously in the process of changing their preprocessor), I'd be grateful for your link.
so why hit at me now.
Hit at you ?!? Don't take things so personally please. I tried to help explaining you what is happening.
Hit at you ?!? Don't take things so personally please. I tried to help explaining you what is happening.
Ok, sorry, I took that the wrong way. You much rather deserve our big thanks for being so helpful over all the years with all your many competent and friendly posts, Alain! :-)
But I'm also seeing my questions still unanswered in important points, and since MQL5 macro documentation is a bit thin, since MQL5 macros are undergoing changes and since we are having their developer here (Ilyas), I would like to once more kindly ask Ilyas to answer as many of them as possible, please, as soon as he's got time. Not many people are macro-experts and even fewer develop the corresponding preprocessor, so I don't want to let go of this seldom chance, please :-)