nested ifdef not recognized by the MQL5 compiler?

nested ifdef not recognized by the MQL5 compiler?

Manage alerts

Loading saved threads...

Sean Champ · External communityPost link
External question — Stack Overflow Stack Exchange Author: Sean Champ Original post: https://stackoverflow.com/questions/77054652 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Since beginning to read about the technical analysis methods published by John F. Ehlers ( MESA Software ), I've been working on developing a sort of filters API for MQL4. Albeit, not in all ways like an analog audio filter, of course these FX filters would all operate on data in series. While developing this API, I've implemented one indicator that provides a number of options for different filters in the indicator's filter chain. The approach I've used with MQL4 is simply to provide a number of nested #ifdef declarations for configuring the exact filter chain to be used in the indicator build. This would be contrasted to an implementation producing any further number of distinct indicator definitions, with each one differing only in some aspects of the linked filter chain. Trying to port this to MQL5, I've produced what seems to be an ifdef declaration that the MQL5 compiler may be unable to process. The following should produce an error. #define CORRA_NRFILTERS_CORRA 2 #ifdef CORRA_HPLP #ifdef CORRA_ROC #property indicator_buffers -1 THUNK9 #else #ifdef CORRA_FILTER_IFISHER #property indicator_buffers 5 THUNK8 #else #property indicator_buffers 4 THUNK7 #endif #endif THUNK6 #else // !CORRA_HPLP #ifdef CORRA_ROC #property indicator_buffers 4 THUNK5 #else #ifdef CORRA_FILTER_IFISHER #property indicator_buffers 4 THUNK4 #else #ifdef CORRA_WMA #property indicator_buffers 3 THUNK3 #endif #else // a secondary `else` clause, probably the cause here // #property indicator_buffers 2 THUNK // curiously not in fact reached #property thunk #property indicator_buffers CORRA_NRFILTERS_CORRA #endif #endif #endif This code is designed to produce at least one error, and the MQL5 compiler has not reached any branch in those clauses. It parses the file without error. Subsequently, the indicator winds up without an appropriate number of data buffers defined for its MQL5 implementation. Given the absence of any sort of else clause for these preprocessor declarations in MQL, and while this bit of code may be a bit tough to parse visually, an approach quite like this has worked out well enough for purpose of prototyping in MQL4. Presently, I'm trying to port the whole codebase to MQL5, it's not proving to be an altogether straightforward process however. I was trying to test a different approach to implementing the indicator_buffers property for MQL5, when I noticed that the code I was using - illustrated above - wasn't even being reached by the compiler. In the original MQL4 implementation, this part was managed with the IndicatorBuffers() function. This seems to have been removed from the API. The MQL4 indicator_buffers property might now be represented by the indicator_plots property, while the MQL5 indicator_buffers property takes on the functionality of the earlier IndicatorBuffers() function. It also removes the property from any scope in which the property could be set at runtime, using these static preprocessor directives now instead. Does it stop parsing at any certain depth of ifdef? On further testing, it doesn't seem that it could be related to the depth of the ifdef declaration. I'll try testing this section in a separate file.
Quote
Report
Sean Champ · External communityPost link
External answer — Stack Overflow Stack Exchange Author: Sean Champ Original post: https://stackoverflow.com/a/77054833 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. After simply indenting the nested ifdef clauses, the issue seems to have been with a misplaced else clause, now annotated in the example above An updated example, with indentation for the ifdef clauses #define CORRA_NRFILTERS_CORRA 2 // other constants to be tested in some later revision #define CORRA_NRFILTERS_HPLP 2 #define CORRA_NRFILTERS_IFISHER 1 #define CORRA_NRFILTERS_WNA 1 #define CORRA_NRFILTERS_ROC 1 #ifdef CORRA_HPLP #ifdef CORRA_ROC #property indicator_buffers THUNK9 #else #ifdef CORRA_FILTER_IFISHER #property indicator_buffers 5 THUNK8 #else #property indicator_buffers 4 THUNK7 #endif #endif THUNK6 #else // !CORRA_HPLP #ifdef CORRA_ROC #property indicator_buffers 4 THUNK5 #else #ifdef CORRA_FILTER_IFISHER #property indicator_buffers 4 THUNK4 #else #ifdef CORRA_WMA #property indicator_buffers 3 THUNK3 #endif #property indicator_buffers CORRA_NRFILTERS_CORRA #endif #endif #endif In an alternate approach, it seems that the MQL5 compiler may support some mathematical operations within property declarations. It will at least parse the source code .... #ifdef CORRA_HPLP // high-pass/low-pass filter #define CORRA_NRFILTERS_HPLP 2 #else #define CORRA_NRFILTERS_HPLP 0 #endif #ifdef CORRA_IFISHER // inverse fisher transform #define CORRA_NRFILTERS_IFISHER 1 #else #define CORRA_NRFILTERS_IFISHER 0 #endif #ifdef CORRA_WMA // weighted moving average #define CORRA_NRFILTERS_WMA 1 #else #define CORRA_NRFILTERS_WMA 0 #endif #ifdef CORRA_ROC // rate of change filter #define CORRA_NRFILTERS_ROC 1 #else #define CORRA_NRFILTERS_ROC 0 #endif // price source and correlation filter #define CORRA_NRFILTERS_CORRA 2 #define CORRA_NRFILTERS CORRA_NRFILTERS_CORRA + CORRA_NRFILTERS_ROC + CORRA_NRFILTERS_WMA + CORRA_NRFILTERS_IFISHER + CORRA_NRFILTERS_HPLP #property indicator_buffers CORRA_NRFILTERS #property indicator_plots 1 This updated example would not use so many nested ifdef clauses. It parses, at least, in MQL5.
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: Sean Champ Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/questions/77054652 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Since beginning to read about the technical analysis methods published by John F. Ehlers ( MESA Software ), I've been working on developing a sort of filters API for MQL4. Albeit, not in all ways like an analog audio filter, of course these FX filters would all operate on data in series. While developing this API, I've implemented one indicator that provides a number of options for different filters in the indicator's filter chain. The approach I've used with MQL4 is simply to provide a number of nested #ifdef declarations for configuring the exact filter chain to be used in the indicator build. This would be contrasted to an implementation producing any further number of distinct indicator definitions, with each one differing only in some aspects of the linked filter chain. Trying to port this to MQL5, I've produced what seems to be an ifdef declaration that the MQL5 compiler may be unable to process. The following should produce an error. #define CORRA_NRFILTERS_CORRA 2 #ifdef CORRA_HPLP #ifdef CORRA_ROC #property indicator_buffers -1 THUNK9 #else #ifdef CORRA_FILTER_IFISHER #property indicator_buffers 5 THUNK8 #else #property indicator_buffers 4 THUNK7 #endif #endif THUNK6 #else // !CORRA_HPLP #ifdef CORRA_ROC #property indicator_buffers 4 THUNK5 #else #ifdef CORRA_FILTER_IFISHER #property indicator_buffers 4 THUNK4 #else #ifdef CORRA_WMA #property indicator_buffers 3 THUNK3 #endif #else // a secondary `else` clause, probably the cause here // #property indicator_buffers 2 THUNK // curiously not in fact reached #property thunk #property indicator_buffers CORRA_NRFILTERS_CORRA #endif #endif #endif This code is designed to produce at least one error, and the MQL5 compiler has not reached any branch in those clauses. It parses the file without error. Subsequently, the indicator winds up without an appropriate number of data buffers defined for its MQL5 implementation. Given the absence of any sort of else clause for these preprocessor declarations in MQL, and while this bit of code may be a bit tough to parse visually, an approach quite like this has worked out well enough for purpose of prototyping in MQL4. Presently, I'm trying to port the whole codebase to MQL5, it's not proving to be an altogether straightforward process however. I was trying to test a different approach to implementing the indicator_buffers property for MQL5, when I noticed that the code I was using - illustrated above - wasn't even being reached by the compiler. In the original MQL4 implementation, this part was managed with the IndicatorBuffers() function. This seems to have been removed from the API. The MQL4 indicator_buffers property might now be represented by the indicator_plots property, while the MQL5 indicator_buffers property takes on the functionality of the earlier IndicatorBuffers() function. It also removes the property from any scope in which the property could be set at runtime, using these static preprocessor directives now instead. Does it stop parsing at any certain depth of ifdef? On further testing, it doesn't seem that it could be related to the depth of the ifdef declaration. I'll try testing this section in a separate file.

Cancel quote

Checking account access…