pass arguments by reference:
void func(double& a, int& b, string& c, double& x[], int& y[][])
And btw why do you write "more than two", did you mean "more than one"?
Just to expand on what 7bit is referring to, as this was a point of much confusion to myself years ago when I was at a similar point on the learning curve, what he means is that you pass parameters to the called function and you have the function change the values of the passed parameters directly.
So basically you are using the passed parameters as your was of capturing the returned results.
For example, let's say your function currently only has two parameters that are passed to it (and you don't want them overwritten or changed) so your code might look like:
int MyFunction(int InputA, double InputB);And you might be using the returned output as follows:
int MyResults,CurrentInputA; double CurrentInputB; CurrentInputA=MathFloor(iRSI(NULL,0,14,PRICE_CLOSE,0); // Convert the double-output of the RSI indicator into the floor value CurrentInputB=MathMax(iATR(NULL,0,12,0),iATR(NULL,0,12,1)); // Take the largest value of the ATR, either yesterday's or today's MyResults=MyFunction(CurrentInputA, CurrentInputB); // capture the output of MyFunction in the value of MyResults if(MyResults>10) ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-25*Point,Ask+25*Point,"My order #2",16384,0,Green); else return(0);Now one way to accomplish the same effect is to pass the the variable "MyResults" to the call function directly:
void MyFunction(int& MyResults, int InputA, double InputB); int MyResults,CurrentInputA; double CurrentInputB; CurrentInputA=MathFloor(iRSI(NULL,0,14,PRICE_CLOSE,0); // Convert the double-output of the RSI indicator into the floor value CurrentInputB=MathMax(iATR(NULL,0,12,0),iATR(NULL,0,12,1)); // Take the largest value of the ATR, either yesterday's or today's MyFunction(MyResults, CurrentInputA, CurrentInputB); // MyFunction would be coded to change MyResults directly if(MyResults>10) ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-25*Point,Ask+25*Point,"My order #2",16384,0,Green); else return(0);In this example I made MyFunction a "void" function, but in practice I make my functions be "bool" or "int" functions and the returned value is used to assess whether or not an error occurred during processing of the function itself.
At this point it is a simple matter to expand the function to include two parameters that will store the output results:
bool MyFunction(int& MyIntResult, double& MyDoubleResult, int InputA, double InputB); // MyFunction returns "true" if processing occurred without error, otherwise it returns "false" int MyIntResult,CurrentInputA; double MyDoubleResult,CurrentInputB; bool ProcessedWithoutError; CurrentInputA=MathFloor(iRSI(NULL,0,14,PRICE_CLOSE,0); // Convert the double-output of the RSI indicator into the floor value CurrentInputB=MathMax(iATR(NULL,0,12,0),iATR(NULL,0,12,1)); // Take the largest value of the ATR, either yesterday's or today's ProcessedWithoutError=MyFunction(MyIntResult, MyDoubleResult, CurrentInputA, CurrentInputB); // MyFunction would be coded to change MyIntResult and MyDoubleResult directly if(ProcessedWithoutError==false) // check to see if MyFunction returned true or false, is coded to return false if an error occurred { Print("Error occurred while processing the call function MyFunction()"); return(0); } if(MyIntResult>10 && MyDoubleResult<=2.) ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-25*Point,Ask+25*Point,"My order #2",16384,0,Green); else return(0);
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
How to return more than two parameters?