In this case, return exits the start() function, so in effect, it exits your code until the next tick.
The -1 is the value returned to whatever called the start() function, which is MT4.
To my knowledge MT4 doesn't do anything with the values returned by start(). I could be wrong.
The coder was trying to express "an error occurred", and the code run was terminated due to lack of data.
In this case, return exits the start() function, so in effect, it exits your code until the next tick.
The -1 is the value returned to whatever called the start() function, which is MT4.
To my knowledge MT4 doesn't do anything with the values returned by start(). I could be wrong.
The coder was trying to express "an error occurred", and the code run was terminated due to lack of data.
Many thanks,
So is it specifically the -1 value responsible for terminating start. What if return(0) was returned.
What is the difference between return(0), and return(-1)?
I think the actual return value is ignored.
The coder just made it look like an error state caused the exit.
There is nothing I have seen in the documents about return values for the special functions start, init and deinit.
------
However, when YOU write a function, the return value can mean whatever you want it to.
int count; int start(){ count = Increment(count); return(0); int Increment(int aNumber){ aNumber++; return(aNumber); }
The function "Increment" takes an integer as an argument, and "returns" an integer, equal to the argument value +1.
To my knowledge MT4 doesn't do anything with the values returned by start().
....
I think the actual return value is ignored.
- 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,
I am new to coding in general and I was hoping somebody could explain something to me. I'm sure you are familiar with the script below, and I understand it's purpose, but;
Can please somebody tell me what the return(-1) in this following statement does: I know that the return|(-1) terminates the start function. But I don't understand why it does this. What does return(0) return(-1) do.
I'm sorry for the stupid question. This has become a real sticking point for me and I'm not moving on until I understand this.
Please help!
thanks
Simon
int start ()
{
int counted_bars = IndicatorCounted ();
//---- check for possible errors
if ( counted_bars < 0 ) return (- 1 );
//---- last counted bar will be recounted
if ( counted_bars > 0 ) counted_bars --;