Download MetaTrader 5

How do I get my ea to stop trading for the rest of the day after... - page 3

To add comments, please log in or register
Interested in the Market activity? Come and track!
Keith Watford
Keith Watford 2015.05.01 00:51  

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.

Demos Stogios
Demos Stogios 2015.05.01 10:28  

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

 best regards 


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 :)

amitabh 2015.05.01 16:52  



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". :)

Warm wishes



To add comments, please log in or register