Trouble understanding Return(0);

 

I have a working EA and want to add this code I found in an old article so no new trades open on Friday.

What I don't understand is how the Return(0); operates here (and can't search for it) because it's not in a function but an "if" statement. Where does it return to? It also looks like there's a bracket missing, right, that would be after "more things"?:

extern bool Trade_Friday = FALSE;

if (OpenOrders<1)
{
if (!Trade_Friday)
{//check for Friday
if (DayOfWeek()==5)
{Comment("No trading on Friday!");
return(0);//End of Friday check
}
}//continues on to process more things related to if (OpenOrders<1)

So if Trade_Friday is True, then it processes "more things". If Trade_Friday is False, then it checks for DayOfWeek==5; if False it continues to "more things", but if it's True, how does the Return(0); cause it to skip the "more things"?

Now that I'm trying to figure it out, does the Return(0); just skip everything and pass control back to int start()? and is that the only thing it's used for?

thanks,

Eric

 
ericjschroeder:

I have a working EA and want to add this code I found in an old article so no new trades open on Friday.

What I don't understand is how the Return(0); operates here (and can't search for it) because it's not in a function but an "if" statement. Where does it return to? It also looks like there's a bracket missing, right, that would be after "more things"?:

extern bool Trade_Friday = FALSE;

if (OpenOrders<1)
{
if (!Trade_Friday)
{//check for Friday
if (DayOfWeek()==5)
{Comment("No trading on Friday!");
return(0);//End of Friday check
}
}//continues on to process more things related to if (OpenOrders<1)

So if Trade_Friday is True, then it processes "more things". If Trade_Friday is False, then it checks for DayOfWeek==5; if False it continues to "more things", but if it's True, how does the Return(0); cause it to skip the "more things"?

Now that I'm trying to figure it out, does the Return(0); just skip everything and pass control back to int start()? and is that the only thing it's used for?

thanks,

Eric


Eric,

I think that those if statements would go into the routine that places new orders before any get placed. I dont know where it returns to in your EA. Note Friday comes many hours ahead of Eastern Time as DayOfWeek() is determined by the data ticks date and time. See the date and time on your chart this Thursday night.

Bill H.

 

return will immediately leave the function in which it is and return to wherever this function was called. If the return its located somewhere inside the start() function then it will leave the start() function and return to metatrader because metatrader itself called the start() function.


You cannot have any code outside of a function, it must be at least inside the start() function (or init() or deinit()), so there is always a function to return from and there will always be something that has called this function. If the code above is inside your start() function, what I assume, then it will just exit from the start() function and return to wherever start() was called from (which is probably somewhere deep inside the internals of metatrader and is not really of interest to us). All we need to know is that metatrader will call our start() on every tick and when we are done with the tick we let the start() function return (to metatrader itself).


Edit: This sounds only complicated because it seems I repeated myself at least 3 times while writing this, but I'm too lazy to edit it now. Its actually really quite simple.
 
Reason: