![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
I am curious, has anyone a suggestion on how to solve following task.
The main idea is to trace MQL API function calls in such way, that it is possible to print to the journal following informations:
File and line where the call to a function has taken place, and if provided, the return value and the current error code state.
For this, I defined a macro for each function name by the list of functions from the MQL documentation.
Now I would want to substitute the function name with some code, so I can inject these details. - For this I have created an object.
now this would change a function call
into this:
The Object dbg_mql_api_retval would now handle the output accordingly by using the overloaded operator= as a function call being called after the ChartGetDouble-call is performed. - So far so good, but I have issues with when this is inside an if-statements condition, like this:
ChartGetDouble() is not the best example here, but the problem is the evaluation of the result, as it could be also the other way around, first DBL_MIN, then the function call.
The relevan code is included in lib_debug.mqh already, and can be found at lines 984 to 986 and1084 to 1119 as well as 2287 to 2882. - I had begun to change the function macros, please ignore the second parameter for now, the string constant of the return type)
My issue is with the evaluation of the return values within conditional evaluation blocks, like if-statements.
I had to solve it this way, because only at that point are the informations available, I want to print. - So even rewriting all functions with a wrapper would not solve the problem. - I need the values from the complier macros __FILE__, __FUNCTION__ and __LINE__.
Any ideas??
EDIT (updated):
I am curious, has anyone a suggestion on how to solve following task.
The main idea is to trace MQL API function calls in such way, that it is possible to print to the journal following informations:
File and line where the call to a function has taken place, and if provided, the return value and the current error code state.
For this, I defined a macro for each function name by the list of functions from the MQL documentation.
Now I would want to substitute the function name with some code, so I can inject these details. - For this I have created an object.
now this would change a function call
into this:
The Object dbg_mql_api_retval would now handle the output accordingly by using the overloaded operator= as a function call being called after the ChartGetDouble-call is performed. - So far so good, but I have issues with when this is inside an if-statements condition, like this:
ChartGetDouble() is not the best example here, but the problem is the evaluation of the result, as it could be also the other way around, first DBL_MIN, then the function call.
The relevan code is included in lib_debug.mqh already, and can be found at lines 984 to 986 and1084 to 1119 as well as 2287 to 2882. - I had begun to change the function macros, please ignore the second parameter for now, the string constant of the return type)
My issue is with the evaluation of the return values within conditional evaluation blocks, like if-statements.
I had to solve it this way, because only at that point are the informations available, I want to print. - So even rewriting all functions with a wrapper would not solve the problem. - I need the values from the complier macros __FILE__, __FUNCTION__ and __LINE__.
Any ideas??
I would like to help but I don't have time to dive into your code. So I would suggest you to ask small well targeted question if possible.
Thank you for the offer.... Let me try.
As far as I can see, my problem is the sequence of operators.
Let me try to show:
Inside of an evaluation block, for example within an if()-statement, following happens:
And here is what I need to happen ( Pos 1 and 2 can be swapped):
1. Member function "msg" gets called
2. ArraySize gets called
3. return value of ArraySize calls operator=()-function from object.
4. returned value from operator=() gets compared by "==" to the right side. (5)
I know by doing following, it can be done easily:
But I cannot insert these brackets by macro...
So what I need to find is some way to influence the execution order without editing/substituting anithing after the MQL-API-Function-Name, since this is the only thing I can replace with a macro.
The solution to be used ineeds to be able to handle the other way around as well, like this:
How could this be solved?
Addendum, the main issue is getting the "debug-infos" from where the function call takes place... - I am open to any approach on solving this, as it would enhance the lib_debug.mql library greatly. (And finally bring it to version 5.0...)
Thank you for the offer.... Let me try.
As far as I can see, my problem is the sequence of operators.
Let me try to show:
Inside of an evaluation block, for example within an if()-statement, following happens:
And here is what I need to happen ( Pos 1 and 2 can be swapped):
1. Member function "msg" gets called
2. ArraySize gets called
3. return value of ArraySize calls operator=()-function from object.
4. returned value from operator=() gets compared by "==" to the right side. (5)
I know by doing following, it can be done easily:
But I cannot insert these brackets by macro...
So what I need to find is some way to influence the execution order without editing/substituting anithing after the MQL-API-Function-Name, since this is the only thing I can replace with a macro.
The solution to be used ineeds to be able to handle the other way around as well, like this:
How could this be solved?
Addendum, the main issue is getting the "debug-infos" from where the function call takes place... - I am open to any approach on solving this, as it would enhance the lib_debug.mql library greatly. (And finally bring it to version 5.0...)
Very clear, thank you. I will think about it.
Great.
I am waiting for the release of the "API tracer".
Great.
I am waiting for the release of the "API tracer".
If you would like to test the current version, here is how to activate MQL-API-Tracing.
Please note, it is considered "alpha" stage at the moment as I am strugling with another issue at the moment. - See post here: https://www.mql5.com/en/forum/446559
I would appreciate testing and helping to make the code more stable in the process.
To test the functionality:
Since this code is alpha/early beta, it is only available via cloud storage and part of the "MQL plus" project.
EDIT:
Do not use MQL-API-Calls with other macros from the library, this is currently broken when MQL-API-TRACING is enabled. Example:
DBG_MSG_VAR(TimeCurrent());
This will make the program crash with an "access violation" error.
If you would like to test the current version, here is how to activate MQL-API-Tracing.
Please note, it is considered "alpha" stage at the moment as I am strugling with another issue at the moment. - See post here: https://www.mql5.com/en/forum/446559
What do you think of implementing the API tracer like this:
It handles all operators, nicely. https://www.mql5.com/en/docs/basis/operations/rules
What do you think of implementing the API tracer like this:
It handles all operators, nicely. https://www.mql5.com/en/docs/basis/operations/rules