How to return multiple values from a function?

 

Hi

Newbie here... I'm trying to write an EA that returns two values from a function. Can't seem to get it working... Any help will be much appreciated. Thanks.

 
how about if I use arrays? Can I use arrays to return more than one values?
 

I have a question to you. I can not figure out what is the benefit of formulating two postings and then waiting until somebody posts an answer instead of just typing the words function return multiple values into the search box and having an immediate and complete result within a few seconds. I would really like to know what is going on in other people's minds in regard to this phenomenon, so please tell me: what exactly was it that made you chose the complicated way over the easy and quick one?

 
void function(int inarg, double &outArg1, double &outArg2)
 

I posted two postings because after I posted the first one.. I got a reply that says it can't be done.... That's why I replied by asking if I can use arrays... but seems like whoever replied deleted his post immediately after that....

Anyway, searching for function return multiple values (both using google and the search function on this forum) didn't exactly give me 'an immediate and complete result'... you may want to try it out yourself first...

WHRoeder, thanks for being helpful....

I did try to use pointers... I came from a C background... but have not being programming for some time... How do I call the function from Start()? Do I need to use * to declare a pointer variable? Thanks

 
Read the section "Functions that Return Several Values" here -> https://www.mql5.com/en/articles/1496. There are no pointers in MQL4.
 
https://forum.mql4.com/search/function%20return%20multiple%20values
 
sorry.... I did search through.... but probably din search through hard enough... my bad... thanks anyway...
 
Wynne Chan:

Hi

Newbie here... I'm trying to write an EA that returns two values from a function. Can't seem to get it working... Any help will be much appreciated. Thanks.

Arrays can't be returned, but structures can ;-)

 
or pass two variables by reference, and set the caller's.
Reason: