In retested if you set the limit time range to say 18:06 and exit at end of range - it works. Checking the list of trades you see exits at 18:06.
Doing the same thing in the optimizer and running a basic WF, trades do no respect this and close at 18:30 instead.