Looking to autoclose positions after they have been open for x amount of time

 

Does anyone know of an expert/ utility that i can use to auto close an order after it has been open x minutes & x hours? 

 

you can code yourself

EA or script

 
#include <Trade\Trade.mqh>
CTrade trade;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool PositionCloseByTime(int hours,int minutes)
  {
   ulong ticket;
   int total=PositionsTotal();
   for(int i=total-1;i>=0;i--)
     {
      ticket=PositionGetTicket(i);
      if(PositionSelectByTicket(ticket))
         if(TimeCurrent()-PositionGetInteger(POSITION_TIME)>=hours*3600+minutes*60)
            return(trade.PositionClose(ticket));
     }     
//---
   return(false);
  }        
//+------------------------------------------------------------------+
 
Ernst Van Der Merwe #:
Thank you.
Reason: