Hello Everyone,
I am unable to figure out how to code a custom function that returns multiple values.
- docs.mql4.com
I do not understand how this information applies to my question.
I have a function that when called returns three values.
How do I assign/associate/define & use each of those values when they are returned?
What is the structure, syntax & method?
How do I get to the values that are returned?
Hi_Lo_Avg_Candles=( how?=> lowest_price_candle, how?=> highest_price_candle how?=> average_price_candle )
I do not understand how this information applies to my question.
I have a function that when called returns three values.
- No you don't.
- void function return nothing.
- and you code doesn't even compiled.
- have you look at the link that i gave?
- you need to pass the parameters by reference (those 3 values), before you can use them. doesn't matter in OnticK() or OnCalculate() or anywhere else..
- No you don't.
- void function return nothing.
- and you code doesn't even compiled.
- have you look at the link that i gave?
- you need to pass the parameters by reference (those 3 values), before you can use them. doesn't matter in OnticK() or OnCalculate() or anywhere else..
how am I supposed to compile it when I do not know how to set it up?
ok so I do not use void. thank you!
yes I looked at the link. did you see my reply? I do not understand it. the link references passing the values "from" the function.
How do I use these values when returned from the function?
I am looking for the syntax, structure & method
if there were just "one" variable I know this would work: lowestCandlePrice=Hi_Lo_Avg_Candles();
this does not work
double lowestCandlePrice=Hi_Lo_Avg_Candles(double lowestCandlePrice);
this does not work
Hi_Lo_Avg_Candles(); double lowestCandlePrice; double highestCandlePrice; double averageCandlePrice;
this does not work
Hi_Lo_Avg_Candles(double lowestCandlePrice, double highestCandlePrice, double averageCandlePrice);
this does not work
Hi_Lo_Avg_Candles(lowestCandlePrice, highestCandlePrice, averageCandlePrice);
this does not work
Hi_Lo_Avg_Candles(lowestCandlePrice; highestCandlePrice; averageCandlePrice;);
Can you please complete the sentence?
How do you define each value that is returned?
how am I supposed to compile it when I do not know how to set it up?
ok so I do not use void. thank you!
yes I looked at the link. did you see my reply? I do not understand it. the link references passing the values "from" the function.
How do I use these values when returned from the function?
I am looking for the syntax, structure & method
if there were just "one" variable I know this would work: lowestCandlePrice=Hi_Lo_Avg_Candles();
this does not work
double lowestCandlePrice=Hi_Lo_Avg_Candles(double lowestCandlePrice);
this does not work
Hi_Lo_Avg_Candles(); double lowestCandlePrice; double highestCandlePrice; double averageCandlePrice;
this does not work
Hi_Lo_Avg_Candles(double lowestCandlePrice, double highestCandlePrice, double averageCandlePrice);
this does not work
Hi_Lo_Avg_Candles(lowestCandlePrice, highestCandlePrice, averageCandlePrice);
this does not work
Hi_Lo_Avg_Candles(lowestCandlePrice; highestCandlePrice; averageCandlePrice;);
Can you please complete the sentence?
How do you define each value that is returned?
Hi cowmodee:
for return multiple value from function, see follow example
double MyMovinAverageSimple(int period, double &multipleValueReturn) { double sum = 0.0; for( int i = 0; i < period; i++ ) { sum += Close[i]; } multipleValueReturn = sum; //in this mode you assign the sum price to reference parameter return sum / period; //this is the main return of function }
how to use it
int OnTick() { double MyMultipleReturn; double MyAvg = MyMovingAverageSimple(20, MyMultipleReturn); //at this point of code you will found two value the moving average value and the sum of all price //THIS IS ONLY AN EXAMPLE FOR RETURN ONE OR MORE MULTIPLE VALUES FROM A FUNCTION }
Hi, newbie here. i'm trying to convert a repetitive 'if-else' statement into a function. the "if" statement works as stand-alone but when inside a function, i keep getting 'not all control paths return a value' error message. How do i tell the function to "Do Nothing" if they do not return any value? is this the right way?
Appreciate pointers. Here's the code :
double DeMPriceChangeRatio = //<--this variable is obtained from a separate function and suppose to pass to the function below
static string DeMDir;
CommentandAlertfn (double DeMPriceChangeRatio,string DeMDir); //<-- is this call function correct?
//this Function to output to a Comment and alert. This function is located as global.
void CommentandAlertfn (double DeMPriceChangeRatio, string DeMDir ) { //<--this "if" statement works as stand-alone but as a function, i keep getting 'not all control paths return a value' error message.
.
if (DeMPriceChangeRatio >=0 && DeMDir!="POS")
{DeMDir ="POS";
Alert (_Symbol, " ", _Period, " NEG to ", DeMDir);
}
if (DeMPriceChangeRatio <0 && DeMDir != "NEG")
{DeMDir = "NEG";
Alert (_Symbol, " ", _Period, " POS to ", DeMDir);
}
}//end of RecordPosorNegfn function
Comment ( "\nDeM = ", DeMDir) ;
- www.mql5.com
Hi cowmodee:
for return multiple value from function, see follow example
how to use it
Hi, i'm new and wish to seek understanding on your above reply to cowmodee.
When you use
double MyMultipleReturn;
dont we need to pass 2 arguments to the Function since it requires 2 arguments to work right? why is it MyMultipleReturn has no argument ?
Please edit your post and use the code button (Alt+S) when pasting code.
EDIT your original post, please do not just post the code correctly in a new post.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello Everyone,
I am unable to figure out how to code a custom function that returns multiple values. Here is some code I started with for your review.
I have no clue what syntax, format & structure to use.
I'm sure it is crystal clear to everyone else and I'm hoping someone can help.
Thank you for your time and consideration!
My questions:
a) where would this function be located? onStart, onCalc, external, within onTick
b) where do I declare variables? inside brackets, locally, externally, where the sun doesn't shine?
c) after calculations and values are returned, how do I associate, format & use them? Can I keep the same variable names while passing/returning?
Thanks again for affording me thew opportunity to learn something!