There is no possible generic solution to this issue in MQL currently. 5 years ago, I was facing similar issue (maybe not obvious it's similar but it is related to variant type)
What you would need is a variant "type", which is hard to implement in MQL.
If you can provide an example a bit less simplified, maybe the community can help, as the best solution depends on what you are really trying to achieve.
thanks a lot i went through your post and it was definitely way more complicated and high level than my problem. i am definitely not experienced enough to completely follow that in first glance😅. but something picked my attention that you say it is hard to implement. so this is possible somehow. i'm pretty sure it would be complicated and i may not have the knowledge to do it now, but if i wanted to make it happen. where should i start?
I was trying to use iCustom to dynamically load multiple indicators with varying parameters, aiming for a flexible and reusable setup. I thought maybe if I could make the idea more abstract my answer would not be as straightforward as this post. I know the reason now. However, the lack of a true variant type in MQL5 makes handling different outputs very challenging. It seems this limitation is inherent to the language.
thanks a lot i went through your post and it was definitely way more complicated and high level than my problem. i am definitely not experienced enough to completely follow that in first glance😅. but something picked my attention that you say it is hard to implement. so this is possible somehow. i'm pretty sure it would be complicated and i may not have the knowledge to do it now, but if i wanted to make it happen. where should i start?
You should start to provide real code if you need coding help.
For the rest continue to study and acquire experience, it's what I did.
The solution is to step out of the pure MQL5 and implementing an expression evaluator (also in MQL5 though).
The other way you could take requires a small explanation. All parameters of indicators can be divided into 2 main groups: strings and non-strings. This is because any numbers/dates/etc are implicitly typecasted to each other, thereas the string is completely different thing - an object. Hence you can theoretically generate a lot of predefined function prototypes with different combinations of string and non-string parameters (for example, func(N,N,S,N,S), func(N,S,N,N,N), etc., where N is a number, S is a string), and then compiler will match corresponding template. The problem here is that the number of possible combinations grow very fast. Many years ago I tried to do this for a 20-30 parameters, and compiler crashes. If, say, 5-10 parameters are sufficient for you, then you can do this.
PS. Probably, most simple approach (which just came to my mind) would be to use the AutoIndicator from the book. In this approach you'll need to StringFormat() parameters of your arbitrary indicator and pass to the AutoIndicator, which will do the rest of work for you, that is parse the string and create required indicator via MqlParams.
This is a module for MQL5 Wizard and Standard Library, which allows you to generate expert adviser based on arbitrary set of indicators and conditions.
The solution is to step out of the pure MQL5 and implementing an expression evaluator (also in MQL5 though).
The other way you could take requires a small explanation. All parameters of indicators can be divided into 2 main groups: strings and non-strings. This is because any numbers/dates/etc are implicitly typecasted to each other, thereas the string is completely different thing - an object. Hence you can theoretically generate a lot of predefined function prototypes with different combinations of string and non-string parameters (for example, func(N,N,S,N,S), func(N,S,N,N,N), etc., where N is a number, S is a string), and then compiler will match corresponding template. The problem here is that the number of possible combinations grow very fast. Many years ago I tried to do this for a 20-30 parameters, and compiler crashes. If, say, 5-10 parameters are sufficient for you, then you can do this.
PS. Probably, most simple approach (which just came to my mind) would be to use the AutoIndicator from the book. In this approach you'll need to StringFormat() parameters of your arbitrary indicator and pass to the AutoIndicator, which will do the rest of work for you, that is parse the string and create required indicator via MqlParams.
Very Interesting, i will check out the library. thank you.
The solution is to step out of the pure MQL5 and implementing an expression evaluator (also in MQL5 though).
The other way you could take requires a small explanation. All parameters of indicators can be divided into 2 main groups: strings and non-strings. This is because any numbers/dates/etc are implicitly typecasted to each other, thereas the string is completely different thing - an object. Hence you can theoretically generate a lot of predefined function prototypes with different combinations of string and non-string parameters (for example, func(N,N,S,N,S), func(N,S,N,N,N), etc., where N is a number, S is a string), and then compiler will match corresponding template. The problem here is that the number of possible combinations grow very fast. Many years ago I tried to do this for a 20-30 parameters, and compiler crashes. If, say, 5-10 parameters are sufficient for you, then you can do this.
PS. Probably, most simple approach (which just came to my mind) would be to use the AutoIndicator from the book. In this approach you'll need to StringFormat() parameters of your arbitrary indicator and pass to the AutoIndicator, which will do the rest of work for you, that is parse the string and create required indicator via MqlParams.
May I suggest as another inspirational input to take a look at how I solved similar challenge here:
Yasingh: Hello Everyone is there in any way possible to create something that could make this possible? to have a function or method? a structure, class, some data type or anything that could solve this problem?
this is super simplified and of course does not work for many reasons but exactly what i need. Thank You in advance 🙏🙏🙏
Is this even possible?
I thought about this. The root issue here seems to be something else.
At some point, the type definition of the value to be returned, must be defined, somewhere inside the function get_value, or before.
This type needs to be "forwarded" to the return type of the function itself.
So maybe, if thought through, depending on the actual code, it would be possible to forward this type through some template definitions.
Since templates only get expanded by the actual type requirements, it might be possible to build a code, that compiles correctly.
This is a module for MQL5 Wizard and Standard Library, which allows you to generate expert adviser based on arbitrary set of indicators and conditions.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
There is no possible generic solution to this issue in MQL currently. 5 years ago, I was facing similar issue (maybe not obvious it's similar but it is related to variant type)
What you would need is a variant "type", which is hard to implement in MQL.
If you can provide an example a bit less simplified, maybe the community can help, as the best solution depends on what you are really trying to achieve.
thanks a lot
i went through your post and it was definitely way more complicated and high level than my problem. i am definitely not experienced enough to completely follow that in first glance😅.
but something picked my attention that you say it is hard to implement. so this is possible somehow.
i'm pretty sure it would be complicated and i may not have the knowledge to do it now, but if i wanted to make it happen. where should i start?
Thank you, everyone, for your responses!
I was trying to use iCustom to dynamically load multiple indicators with varying parameters, aiming for a flexible and reusable setup. I thought maybe if I could make the idea more abstract my answer would not be as straightforward as this post. I know the reason now. However, the lack of a true variant type in MQL5 makes handling different outputs very challenging. It seems this limitation is inherent to the language.
I appreciate all the help 🙏🙏🙏
thanks a lot
i went through your post and it was definitely way more complicated and high level than my problem. i am definitely not experienced enough to completely follow that in first glance😅.
but something picked my attention that you say it is hard to implement. so this is possible somehow.
i'm pretty sure it would be complicated and i may not have the knowledge to do it now, but if i wanted to make it happen. where should i start?
You should start to provide real code if you need coding help.
For the rest continue to study and acquire experience, it's what I did.
You should start to provide real code if you need coding help.
For the rest continue to study and acquire experience, it's what I did.
I read the mqlparam document, it is good for built in indicators. Still for new ones I need ICustom.
Here is an example of execution of arbitrary indicators - https://www.mql5.com/en/code/32107
The solution is to step out of the pure MQL5 and implementing an expression evaluator (also in MQL5 though).
The other way you could take requires a small explanation. All parameters of indicators can be divided into 2 main groups: strings and non-strings. This is because any numbers/dates/etc are implicitly typecasted to each other, thereas the string is completely different thing - an object. Hence you can theoretically generate a lot of predefined function prototypes with different combinations of string and non-string parameters (for example, func(N,N,S,N,S), func(N,S,N,N,N), etc., where N is a number, S is a string), and then compiler will match corresponding template. The problem here is that the number of possible combinations grow very fast. Many years ago I tried to do this for a 20-30 parameters, and compiler crashes. If, say, 5-10 parameters are sufficient for you, then you can do this.
PS. Probably, most simple approach (which just came to my mind) would be to use the AutoIndicator from the book. In this approach you'll need to StringFormat() parameters of your arbitrary indicator and pass to the AutoIndicator, which will do the rest of work for you, that is parse the string and create required indicator via MqlParams.
Here is an example of execution of arbitrary indicators - https://www.mql5.com/en/code/32107
The solution is to step out of the pure MQL5 and implementing an expression evaluator (also in MQL5 though).
The other way you could take requires a small explanation. All parameters of indicators can be divided into 2 main groups: strings and non-strings. This is because any numbers/dates/etc are implicitly typecasted to each other, thereas the string is completely different thing - an object. Hence you can theoretically generate a lot of predefined function prototypes with different combinations of string and non-string parameters (for example, func(N,N,S,N,S), func(N,S,N,N,N), etc., where N is a number, S is a string), and then compiler will match corresponding template. The problem here is that the number of possible combinations grow very fast. Many years ago I tried to do this for a 20-30 parameters, and compiler crashes. If, say, 5-10 parameters are sufficient for you, then you can do this.
PS. Probably, most simple approach (which just came to my mind) would be to use the AutoIndicator from the book. In this approach you'll need to StringFormat() parameters of your arbitrary indicator and pass to the AutoIndicator, which will do the rest of work for you, that is parse the string and create required indicator via MqlParams.
Very Interesting, i will check out the library.
thank you.
Here is an example of execution of arbitrary indicators - https://www.mql5.com/en/code/32107
The solution is to step out of the pure MQL5 and implementing an expression evaluator (also in MQL5 though).
The other way you could take requires a small explanation. All parameters of indicators can be divided into 2 main groups: strings and non-strings. This is because any numbers/dates/etc are implicitly typecasted to each other, thereas the string is completely different thing - an object. Hence you can theoretically generate a lot of predefined function prototypes with different combinations of string and non-string parameters (for example, func(N,N,S,N,S), func(N,S,N,N,N), etc., where N is a number, S is a string), and then compiler will match corresponding template. The problem here is that the number of possible combinations grow very fast. Many years ago I tried to do this for a 20-30 parameters, and compiler crashes. If, say, 5-10 parameters are sufficient for you, then you can do this.
PS. Probably, most simple approach (which just came to my mind) would be to use the AutoIndicator from the book. In this approach you'll need to StringFormat() parameters of your arbitrary indicator and pass to the AutoIndicator, which will do the rest of work for you, that is parse the string and create required indicator via MqlParams.
Thank you sir.
Today I have accuired a lot of reading material, thanks to you and Stanislav Korotky.
Thanks a lot 🙏🏻🙏🏻🙏🏻
Hello Everyone
is there in any way possible to create something that could make this possible?
to have a function or method? a structure, class, some data type or anything that could solve this problem?
Thank You in advance 🙏🙏🙏