Converting string to a method

 

Hi there,


I want to receive a value from an API call that will return a string (JSON ... ).

Lets say I'll get something like a = "iMA(Symbol(), 0, 14);"

How can I actually make from a, a string, a, a number that will always return the current value of MA (this will be done in OnInit()).


Regards,

Ciprian

 

Hi please see: https://www.mql5.com/en/docs/convert/stringtointeger

Or if you want to extract key's do a search on JSON libraries by using the search engine.

Documentation on MQL5: Conversion Functions / StringToInteger
Documentation on MQL5: Conversion Functions / StringToInteger
  • www.mql5.com
Conversion Functions / StringToInteger - Reference on algorithmic/automated trading language for MetaTrader 5
 

Unfortunately this will not work: StringToDouble("iMA(Symbol(), 0, 14);")

 

Of course not.

That's why you use key's with datatype specific known values.

Or in your case you only need numbers so you can do a easy solution in base10 only.

 

Sorry for my bad skills on programming but I may need a little more help if you can and time will allow you.

Lets say I have this code in OnInit

res = WebRequest("GET", Website, cookie, NULL, timeout, post, 0, result, headers);

where result will always be equal to: "iMA(Symbol(), 0, 1, 0, MODE_SMA, PRICE_CLOSE, 0);" (a string)

What can I do to make result actually displaying the value that iMA... will give (if called not as a string).

Can I make something on the web response perspective to have the desired value.

I don't want to have on mq4 code the call to iMA as I'd like to hide that part (that's the reason I want to call this method from an API).


Regards,

Ciprian

 
ciprian87:

Sorry for my bad skills on programming but I may need a little more help if you can and time will allow you.

Lets say I have this code in OnInit

What can I do to make result actually displaying the value that iMA... will give (if called not as a string).

Can I make something on the web response perspective to have the desired value.

I don't want to have on mq4 code the call to iMA as I'd like to hide that part (that's the reason I want to call this method from an API).


Regards,

Ciprian

string results[];
if(StringSplit(a,',',results)!=-1)
 {
  int maPeriod=(int)results[2];
 }
Not compiled, not tested.
 

Here are the issues with what you seek to accomplish . 

If you use iMA in the code you are afraid of risking strategy being leaked

so, you want to send it over the web on the fly ,but again when your clients EA (lets call it the receiver) 

receives it as a command ,it will still have to execute iMA and iMA will have to be in the code .

-So if its important to you for your users to have access to indicator inputs and parameters 

combine Marcos and Alains suggestions from this and the other thread . 

You will need an interpreter ,and you will turn responses into calls in your ea by getting the specs as Alain showed.

But then again , if you are worried that someone can see your strategy ,if they actually manage to reach that point of gauging

into your code ,then whats to stop them from plugging a logger and record all the "commands" you send via the WebRequests.

-If on the other hand its not crucial for your clients to fiddle with the strategys parameters , you are better off sending Sell and buy orders

with the same "Api" tech 

 
Lorentzos Roussos:

Here are the issues with what you seek to accomplish . 

If you use iMA in the code you are afraid of risking strategy being leaked

so, you want to send it over the web on the fly ,but again when your clients EA (lets call it the receiver) 

receives it as a command ,it will still have to execute iMA and iMA will have to be in the code .

-So if its important to you for your users to have access to indicator inputs and parameters 

combine Marcos and Alains suggestions from this and the other thread . 

You will need an interpreter ,and you will turn responses into calls in your ea by getting the specs as Alain showed.

But then again , if you are worried that someone can see your strategy ,if they actually manage to reach that point of gauging

into your code ,then whats to stop them from plugging a logger and record all the "commands" you send via the WebRequests.

-If on the other hand its not crucial for your clients to fiddle with the strategys parameters , you are better off sending Sell and buy orders

with the same "Api" tech 

It seems I misunderstood the OP request actually (too fast initial reading).

What he wants seem to execute a command directly from a string, this is just not possible.

 
Alain Verleyen:

It seems I misunderstood the OP request actually (too fast initial reading).

What he wants seem to execute a command directly from a string, this is just not possible.

Yeah , he/she will have to do what you posted at some point though 

 
Lorentzos Roussos:

Yeah , he/she will have to do what you posted at some point though 

Yes parsing the string, but all these complications seem useless for the OP purpose.
 
Alain Verleyen:
Yes parsing the string, but all these complications seem useless for the OP purpose.

Well yeah , but then again if "they" see his code , then "they" can also set up a "net" to record which parts of it is used . So its kind of a unique request to begin with ,unless he is using a sequencer of void diversion commands .But then again , the "DivertionOrNot" function will be exposed if the OP's fears become reality .
He'll be better off with a signal i suppose 

Reason: