return(0);

 

Hello everyone,

I'm still learning how to code,

can somebody explain the meaning of the function, return(0); in an EA code.?

and how does it affect closing of opened orders?

any help will be highly appreciated.

thanks.

 
int start() {
  ...
  return(0);
}

return is not a function. it supplies the return value and terminates the function.

has nothing to do with opened orders.

see Lessons - Forex Trading

 
When 'return' is encountered inside the start() function, the execution of your code ends until the next tick, when it is restarted. That's all.
 
phy wrote >>
When 'return' is encountered inside the start() function, the execution of your code ends until the next tick, when it is restarted. That's all.

What is the purpose/value of including return(0) in the init() or deinit() functions?

What happens if return(0) is not included in the start() function?

 
1005phillip:

What is the purpose/value of including return(0) in the init() or deinit() functions?

What happens if return(0) is not included in the start() function?

Why not just try declaring init(), deinit() and start() as voids?


CB

 
cloudbreaker wrote >>

Why not just try declaring init(), deinit() and start() as voids?

CB

Do you mean "try it and find out for yourself what happens" or do you mean "use void declaration and then you don't have to worry about return(0) anymore"?

I am a fairly novice programmer, I don't know where/why/when a return(0) is needed versus redundant and unnecessary, hence my question regarding it. Sometimes I see it used and other times I see codes where it is not used.

Likewise with void declarations. From what I have gathered from the MQL manual as well as looking thru other people's posted codes the void declaration is used when the routine is not expected to return anything. Are init(), deinit() and start() supposed to be declared as voids?

Are the following two routines equivalent?

int start()
  {
  Print("Hello World");
  Return(0);
  }

and

void start()
  {
  Print("Hello World");
  }
I appreciate the time you are taking to help me out here.