#include input int CloseTimeHour = 23; input int CloseTimeMin = 58; int OnInit(){ return(INIT_SUCCEEDED); } void OnDeinit(const int reason){ } void OnTick(){ MqlDateTime structTime; TimeCurrent(structTime); structTime.hour = CloseTimeHour; structTime.min = CloseTimeMin; datetime timeClose = StructToTime(structTime); if(TimeCurrent() > timeClose){ CTrade trade; for(int i = PositionsTotal()-1; i >= 0; i--){ ulong posTicket = PositionGetTicket(i); if(PositionSelectByTicket(posTicket)){ if(trade.PositionClose(posTicket)){ Print(__FUNCTION__," > Pos #",posTicket," was closed because of close time."); } } } } Comment("\nServer Time: ",TimeCurrent(), "\nClose Time: ",timeClose); }