How to close trade after X Minutes / Hour or Day

 

Hey

Is there a piece of code I can add to my EA so all new trades expire after x Minutes?

Many Thanks

John 

 
John Fasheyiku:

Hey

Is there a piece of code I can add to my EA so all new trades expire after x Minutes?

Many Thanks

John 

Hi John

Do you mean pending orders? Or orders that have actually opened?
 

Yes, you would first need to code a loop to search through all the open orders, you will then have to select the order you wish to add an instruction to.

 

So let's say you want to select an order.

 

for(int da=OrdersTotal()-1;da>=0;da--)
          {
          if(OrderSelect(da,SELECT_BY_POS,MODE_TRADES))
           {
            if(OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol()&& OrderType()==OP_BUY)
              {

 now you can narrow things down by saying, if(OrderOpenTime() - TimeSeconds>=numberOfMinutes*60){some close order code}

Reason: