check passing parameters ny reference:
int res1 func(int& res2, other parameters...)
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
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
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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?