- Returning an "int".
If you want to return an "int", why have you declare your function to return a "double"?
double rvifun() {...}
If you want to return an "int", then declare it to return an "int"?
int rvifun() {...}
- Use the return value. Don't try to access internal local variables.
int retRviSignal = rvifun(); Print( retRviSignal ); if( retRviSignal == 1 ) { // BUY }
- Also, your code seems to be about MQL4 and not MQL5. The MQL4 section is at the end of the forum. In future, please post in the MQL4 and MetaTrader 4 section if it be the case.
Thank you and sorry for using wrong section. You are absolutely right, I am using MQL4. Is it possible to move this thread into the right section?
However, I did not quite get everything you wrote.
So in the on Tick (where I call the function) I declare and call the function all in once, like
int retRviSignal = rvifun()
And later, within the function
int rvifun(){
I compute the int variable retRviSignal that I want to return and at the end of the function, I return the fuction itself?
return(rvifun);
Or the variable I want to use?
return(retRviSignal);
Sam Flowdux #: I compute the int variable retRviSignal that I want to return and at the end of the function, I return the fuction itself?
No you don't.
} else { // in all other cases: no action rvisignal = 0; } Print(rvisignal); return (rvisignal);You computed the variable rvisignal and return its value. You don't return a function, the function returned a value. All variables inside the function no longer exist.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
Hi everyone
I recently started writing scripts. I wrote a function that creates a variable that contains a signal based on the RVI, that is 1 = buy, 2 = sell, 0 = no action. This is the function I wrote
In on tick I want to call the function
rvifun(); Print(rvisignal);
And then work with it, like place an order etc. (not solely on rvi but thats not the point)
My intention was to outsource the rvi function out of the on tick block, call the function at the beginning and then work with the int variable rvisignal.
But I do not manage to actually return rvisignal! Currently I cannot work with the int variable rvisignal within my main on tick block, even though I coded to return it. What is wrong with the code?