Evaluating math formula from string
You cannot evaluate strings in MQL. In other languages it's called eval(string) where the string may contain math or even commands. Unless you want to write a parser, which is a lot of work, you are limited to simple number conversions like StringToDouble().
If you want to write a parser, I suggest to use a set of simple commands similar to assembler. A command set could look like this: "c1=1; c2=3; c3=0.7482; c4=0.5; set c1; sum c2; mul c3; pow c4" where all operations are done with an internal accumulator, "set" assigns to it, and ci is any constant. Should be easy to parse. Or even simpler, "set 1; sum 3; mul 0.7482; pow 0.5". Just an idea. :D
Of course.
- You have to parse the string into tokens.
- Identify and priority the tokens.
- Convert numeric tokens to numbers.
- Execute the tokens correctly and get the result.
My question is very simple.
Imagine we have the following string:
Is it possible to calculate that formula which will be provided during run time as a string?
The result should be:
Thanks!
My question is very simple.
Imagine we have the following string:
Is it possible to calculate that formula which will be provided during run time as a string?
The result should be:
1.7299710980244727Thanks!