This snippet is of a code that will close all trades at the end of the day. The percise time can be modified to your preferations.
Source code viewer
#include <Trade\PositionInfo.mqh> #include <Trade\Trade.mqh> CPositionInfo position; CTrade trade; input bool CloseTradesDayEnd = true; // Close all trades at the end of the day input int CloseTradesDayEndTime = 2357; // GMT Time for close all trades at the end of the day (hmm) datetime gmtTimeCurrent; // OnTick() function content: // TimeGMT gmtTimeCurrent = TimeGMT(); MqlDateTime gmtTimeCurrentStruct; TimeToStruct(gmtTimeCurrent, gmtTimeCurrentStruct); int hoursAndMinutes = (gmtTimeCurrentStruct.hour * 100) + gmtTimeCurrentStruct.min; // Close trades at the end of the day. uint PositionsCount = PositionsTotal(); if(CloseTradesDayEnd && PositionsCount > 0 && hoursAndMinutes == CloseTradesDayEndTime) { for(int i = PositionsCount - 1; i >= 0; i--) { if(position.SelectByIndex(i)) { if(position.Symbol() == Symbol()) { trade.PositionClose(position.Ticket()); } } } }Programming Language: MQL5