how does different returns work ?

 

Hi, I'm new to programming, I have some questions, one is that I can't understand what does different returns mean, for example

return(0) , return(NULL), return(INIT_SUCCEEDED)

my second question is that how can I go from a function to another one, for example

function a ()

{

if (condition  = true) go to function b (),

}

function b()

{

}

the third question is that what functions is necessary to be in our expert advisor because when I delete all the default functions and I start to write a function like below, it doesn't work and show error


1

 thanks for your help

 

The documentation answers your first two questions:

https://www.mql5.com/en/docs/basis/function

You should maybe get a handle on language basics before attempting your third question.

A general programming book or tutorial may be of use to you.

 
saraaaa:

Hi, I'm new to programming, I have some questions, one is that I can't understand what does different returns mean, for example

return(0) , return(NULL), return(INIT_SUCCEEDED)

my second question is that how can I go from a function to another one, for example

function a ()

{

if (condition  = true) go to function b (),

}

function b()

{

}

the third question is that what functions is necessary to be in our expert advisor because when I delete all the default functions and I start to write a function like below, it doesn't work and show error



 thanks for your help

Your function is correct, but you have to tell it when will be called this function, that's the "event handler". 

void OnStart() //<--- when the script will start
{
hello(); //<----- hello(); will be called.
}

Then about the return : 

  • int hello() must return an integer (0,1,2,3,4,5,6,7 ...)
  • string hello() must return a string ("one","two","three","four")
  • double hello() must return a double (1.232255 etc ...)
  • bool hello() must return a boolean (true/false)
  • void hello() returns nothing - your case, since you're asking only for an alert()

So you should use : 

int hello(a,b) 
{
int c = a + b;
return(c);
}

void OnStart()
{
Alert(hello(5,2)); // bring up an alert with 7
}

The third question is about event handler, you'll need : OnStart() (when it starts) ; OnTick() (when a new tick arrive) - for now I suppose it'll be enough.

It's newbie programming but I respect people who wants to learn.

 
Icham Aidibe:

Your function is correct, but you have to tell it when will be called this function, that's the "event handler". 

Then about the return : 

  • int hello() must return an integer (0,1,2,3,4,5,6,7 ...)
  • string hello() must return a string ("one","two","three","four")
  • double hello() must return a double (1.232255 etc ...)
  • bool hello() must return a boolean (true/false)
  • void hello() returns nothing - your case, since you're asking only for an alert()

So you should use : 

The third question is about event handler, you'll need : OnStart() (when it starts) ; OnTick() (when a new tick arrive) - for now I suppose it'll be enough.

It's newbie programming but I respect people who wants to learn.

wow it was so helpful, thank you very much :-)
 
Anthony Garot:

The documentation answers your first two questions:

https://www.mql5.com/en/docs/basis/function

You should maybe get a handle on language basics before attempting your third question.

A general programming book or tutorial may be of use to you.

oh thanks
 
Icham Aidibe:

Your function is correct, but you have to tell it when will be called this function, that's the "event handler". 

Then about the return : 

  • int hello() must return an integer (0,1,2,3,4,5,6,7 ...)
  • string hello() must return a string ("one","two","three","four")
  • double hello() must return a double (1.232255 etc ...)
  • bool hello() must return a boolean (true/false)
  • void hello() returns nothing - your case, since you're asking only for an alert()

So you should use : 

The third question is about event handler, you'll need : OnStart() (when it starts) ; OnTick() (when a new tick arrive) - for now I suppose it'll be enough.

It's newbie programming but I respect people who wants to learn.

Thank you very much Icham, you answered al my questions
 
Anthony Garot:

The documentation answers your first two questions:

https://www.mql5.com/en/docs/basis/function

You should maybe get a handle on language basics before attempting your third question.

A general programming book or tutorial may be of use to you.

it was so helpful,thanks
Reason: