First of all, it is not clear from your post whether variables are global or local.
Any loops that include closing trades should count down, not up. You should at least read every new post on this forum, then you would know that.
Your whole block of code hinges on this
if(UseDailyTarget==true && my_equity>=overall_total && TimeCurrent()>=trade_hour)
So check that before executing the loop.
What is this meant to do?
It will always be true
What happened to tomorrow_midnight?
Once you have sorted this, you should then code to check whether the OrderClose is successful or not. If not, then retry.
I see you are telling return(0) or return(1). That means that you are using functions to make your program; in that case, what we are seeing here is a part of a single function? If so why are you declaring all those variables inside that function? Some of them would normally be in the global space. That been said, there are many ways to write your software, but you have to keep in mind that engineering your idea is propably the most time consuming part of all the work that has to be done in order to complete your program (see: figure out how to do things).
Regarding your last post, it looks like there are not enough informations for us to help you out as the critical part should be what are you are doing with the value returned. I am assuming that return(0) will make something such as trade_disabled=true and return(1) will make a false. But you must work out - or post here some more code on how you are using trade_disabled
edit: GumRai, my post may seem out of space regarding your last post but i noticed the presense of it only after submitting mine - I was stuck in page 2 to be precise. Apologies for that :)
Yet to read the answers. How about placing the order sending function in an "if" block checking for a flag. Then after closing all positions for the day, set the flag to false. Then, for every tick, check if the flag is false. If the flag is false, check what is current time. If the current time is the "next day pre-decided time", then the flag is set to true.
As I understand, once the advisor is activated, onTick function will be invoked until the advisor is deactivated.
Now, checking other replies from "Gurus". :)