I updated your question title to fully describe the context of your question. There is no way to write the code to exit "at end of the day". We can only write code that specifies a time of day to exit.
input exitTime = 1555;
def exitBar = SecondsTillTime(exitTime) == 0;
AddOrder(OrderType.SELL_TO_CLOSE, exitBar[-1], close[-1]);
AddOrder(OrderType.BUY_TO_CLOSE, exitBar[-1], close[-1]);
You will need to update the input parameter "exitTime" to match the time stamp on the last bar of your chart. The selected time frame will impact this and you will need to select the correct time accordingly.
Screenshot below shows this on a 5 min chart using the built-in strategy named: "MovAvgTwoLinesStrat".