Function that returns 2 results?

 

I need to return 2 results from one function. I can seperate them and creat one function for each result I need, but it's a lot more code and makes other things more complicated. Is this possible with MT4?

 

check passing parameters ny reference:

int res1 func(int& res2, other parameters...)

 

Do you mean basically running the function twice, passing a spceial parameter to get a different result each time? I suppose that could work...

Wish I could just do this though:

return(a,b);
 

no,

int x;

int y=func(x, other parameters);

after call x=5 and y=2;

int res1 func(int& res2, other parameters...)

{

res2=5

return(3);

}

 

I mean y=3

 

Wow, thank you for trying to help but I dont understand what you're doing here. Do you have a function fully coded out that does this that you could just copy and paste here?

 

It still looks like its only returning one result--"3"

return(3);

?

 

just find passing paramters by reference in mql4 help:

Generally passing by rederence means you pass an actual variable into function from outside (using &) and you can change it's value inside the function and that vaule will be still there when you copme back from the call.

thus int x set value to 0.

inside function you set x=5

when you come back from function x=5 as set by function so you gave your second result from function without returning 2 results.

functions never return 2 results only one.

 

OK, thanks, irusoh1

 

What's missing from irusoh1 explanation is the variable need to be Array(s). And rather the return not play a role in filling/modifying the arrays but instead modify it directly as needed.  

int Xarray[]; int Yarray[];

void Fun2result(int& Array[], int& Brray[], int pos)
{    Array[pos] = 2 + pos;
     Brray[pos] = 5 + pos;
} 
int start()
{  
    for(i=Bars-1; i>=0; i--)
       Fun2result(Xarray, Yarray, i); 
}

Good luck. 

 

doesn't need to be an array