Thanks for the script, but it won't produce a wrong exit time. The script that you sent by PM won't either.
So the problem is still elsewhere. If it's not the script, it can be the price data you're using. It seems that you downloaded it yourself. Check it for gaps - I've posted a gap checker some days ago. Gaps can delay the exit because a trade can't exit when no price data is available.
BTW, you normally don't need to guess in such a case. If trades behave wrong, check them on the chart. And look in the log and examine them in detail. Normally you can then quickly see the reason.