
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
To return more than 1 value you need to pass them to the function inputs by reference (adding & after the type)
Here's an example:
Functions that Return Several Values
Are there such functions?? Of course, you can write it yourself. Let us see what you can.
The simplest function returning one value:
And what if we need several values of different types to be returned simultaneously? Look here:
Now let us try to call this "amazing" function:
The result is the following:
This function has one common difference from simple functions: when we declare it, after the argument we put the ampersand character (&). If you do this with an argument, you can change its value inside the function, and after calling it the result will remain. Such operation with arguments is called parameter passing by reference. Thus you can return as many variables of different types as you wish. Try to omit the ampersand characters in the above code and see the result:
You don't know how this helped me a lot. Thank you very much.
Functions that Return Several Values
Are there such functions?? Of course, you can write it yourself. Let us see what you can.
The simplest function returning one value:
And what if we need several values of different types to be returned simultaneously? Look here:
Now let us try to call this "amazing" function:
The result is the following:
This function has one common difference from simple functions: when we declare it, after the argument we put the ampersand character (&). If you do this with an argument, you can change its value inside the function, and after calling it the result will remain. Such operation with arguments is called parameter passing by reference. Thus you can return as many variables of different types as you wish. Try to omit the ampersand characters in the above code and see the result:
Functions that Return Several Values
Are there such functions?? Of course, you can write it yourself. Let us see what you can.
The simplest function returning one value:
And what if we need several values of different types to be returned simultaneously? Look here:
Now let us try to call this "amazing" function:
The result is the following:
This function has one common difference from simple functions: when we declare it, after the argument we put the ampersand character (&). If you do this with an argument, you can change its value inside the function, and after calling it the result will remain. Such operation with arguments is called parameter passing by reference. Thus you can return as many variables of different types as you wish. Try to omit the ampersand characters in the above code and see the result:
Dear Friends,
To return more values from a function is :
Example : You can return as many values as you want from a function. What you do is assign to a string with a seperator, eg : , (coma) . So once the string is return to your main program you can break down
the string and assign to needed variables. Below is an example :
string Info_2_Return = IntegerToString(Send_A_Sign_ToProceed) + "," + DoubleToString(val_index_Highest) + "," + DoubleToString(val_index_Lowest);
return(Info_2_Return);
Dear Friends,
To return more values from a function is :
Example : You can return as many values as you want from a function. What you do is assign to a string with a seperator, eg : , (coma) . So once the string is return to your main program you can break down
the string and assign to needed variables. Below is an example :
string Info_2_Return = IntegerToString(Send_A_Sign_ToProceed) + "," + DoubleToString(val_index_Highest) + "," + DoubleToString(val_index_Lowest);
return(Info_2_Return);
You've made life more difficult than necessary with that, LOL
Arrays can't be returned, but structures can ;-)
For that, just create an include file and in the class make the variables you want to return as public. You can always pick them up when needed. This is because you cannot use pointers in MQL5 and 4. But with this method, they be like global variables whose values update and can be accessed any time.