Can I write FUNCTION/s in MQL4 what return/s the TWO DIFFERENT data types ?

 
For example :

ExampledFunction(string Txt, double ProfitFromOrder)
{
... expression... ;
... conditions... ;
return (Txt, ProfitFromOrder);
}


If YES, then what the TYPE should I use in order to properly DECLARE the FUNCTION as above example: double, string or the other ONE?


Then I would like call this function in start(){...} part of program.
The
ExampledFunction() should return two parameters:
1/. Txt as string type
2/.
ProfitFromOrder as double type

Is it possible ?
 
puncher:
For example :

ExampledFunction(string Txt, double ProfitFromOrder)
{
... expression... ;
... conditions... ;
return (Txt, ProfitFromOrder);
}


If YES, then what the type should I declare for the FUNCTION as above example: double, string or the other ONE?


Then I would like call this function in start(){...} part of program.
The
ExampledFunction() should return two parameters. Is it possible ?

Yes, it is possible.You can declare the function type void and assign the two different type results to two global variables.

 
robofx.org:

Yes, it is possible.You can declare the function type void and assign the two different type results to two global variables.


Ok, but I would like call this function in start(){...} part of program.

The ExampledFunction() should return two parameters:
1/. Txt as string type
2/.
ProfitFromOrder as double type

How to call this function in start() {...} part of program and compare the two data types with the other variables ?



 
Is the following the proper syntax ?
if ( ExampledFunction(Txt,ProfitFromOrder) == ("Strata",ProfitFromOrder<0) ) { Alert("Loss trade"); } else { Alert("Profitable trade");}
 
puncher:


Ok, but I would like call this function in start(){...} part of program.

The ExampledFunction() should return two parameters:
1/. Txt as string type
2/.
ProfitFromOrder as double type

How to call this function in start() {...} part of program and compare the two data types with the other variables ?



here is an example:

double A;
string B;

int start()
{
ExampledFunction();
// here check what A & B contain

return(0);
}

void ExampledFunction()
{
// some code
A = your double value;
B = your string value;
}

 
robofx.org:

...
int start()
{
ExampledFunction();
// here check what A & B contain

return(0);
}

...

How to check what A & B contain in start() after call to this function ? Can you please any MQL4 example ?

 
puncher:

How to check what A & B contain ? Can you please any MQL4 example ?


it depends what info A and B contain.
for example if A contains order profit:

if(A>0) Print("Profitable trade");
else Print("Losing trade");

 
An alternative way (and IMHO a much better way) is to return variables by reference. See the section "Functions that Return Several Values" in the article "MQL4 Language for Newbies - Technical Indicators and Built-In Functions".
 
robofx.org:

it depends what info A and B contain.
for example if A contains order profit:

if(A>0) Print("Profitable trade");
else Print("Losing trade");


Are you sure ? From what the program will know that "A" vairable is from the ExampledFunction() ?

you wrote:
void ExampledFunction()
{
// some code
A = your double value;
B = your string value;
}

Should not be there the return (B,A) at the end of declared function ?

 
puncher:


Are you sure ? From what the program will know that "A" vairable is from the ExampledFunction() ?

you wrote:
void ExampledFunction()
{
// some code
A = your double value;
B = your string value;
}

Should not be there the return (B,A) at the end of declared function ?

I'm sure. In ExampledFunction you change the values of A and B and store there what you want without using return. You first call the function then check the values.

 
robofx.org:

Yes, it is possible.You can declare the function type void and assign the two different type results to two global variables.

No!

Don't use global variables!


The only correct way is the following: (the & before the variable name in the declaration means: by reference, this is effectively a function argument through which you can pass data both ways, you are creating a wormhole through which the function can manipulate something outside but without being restricted to always the same hardcoded global variables only, you can instead call it with any variables you want.)

void ExampleFunction(string &Text, double &Profit){
   // ...
   // do some stuff
   // ...
   Text = something;
   Profit = somethingelse;
}


int start(){
   string SomeText;
   double SomeProfit;
   string SomeOtherText;
   double SomeOtherProfit;


   // ...
   // some other stuff maybe
   // ...


   // now call the function with the uninitialized variables
   ExampleFunction(SomeText, SomeProfit);

   // now the two variables contain the "return" values


   // now call it again with some other variables
   ExampleFunction(SomeOtherText, SomeOtherProfit);

   // this time it will have manipulated the other two variables
}
Reason: