How to Trade only once per 24hour period

 

Hi,

I have a EA that I only want to trade once per day..... It puts a BuyStop in at a particluar level and if it doesnt get trigged by the end of a 24 hour period it expiires.

If it does get triggered though, i want to ensure that my code wont put the trade on again.

Normally i would just use a BarCount check like this

if (BarCount != Bars) {put order placement code in here}

But the 24 hour period i want my order to exist in is staggered, as seen below so i cant use a daily bar count check.

Can anyone tell me the best way to get my order placement code to run only once in this period? I have thought about just telling the code to run in the first hour, but then if my order gets triggered in the first hour it would put in on again.......

I have also thought about just using a boolean that resets once the first minute of the new period passes but if my connection is down for that small period the boolean wont reset....... can anyone suggest an efficient way?

Thanks in advance for any help...

 

You can use datetime to place your stoptrades and remove them if they not triggered when newtime > oldtime + 86400 (24 hours * 60 minutes * 60 seconds)

if newtime > oldtime + 86400 ==>> check and delete open stoptrades open new stoptrade if newstoptrade is placed oldtime = oldtime +86400

 
  1. if (BarCount != Bars) 
    Bars is unreliable (max bars on chart) Volume is unreliable (you can miss ticks) Always use Time
  2. static datetime nextTrade;
    if (TimeCurrent() > nextTrade){
       int ticket = OrderSend(...);
       if (ticket < 0) Alert("OrderSend failed: ", GetLastError());
       else            nextTrade = TimeCurrent() + 86400;
    }

 
Thanks Guys, great stuff. Just the answer i was looking for!