This is an updated version of the script.
Updated version slightly modifies the exit strategy.
Exit will be not at the close of the day.
If a trade is opened and there are no exit signals at the eod, then it assumes the trade is to be carried over for the next day.
Alternatively you can exit the trade in such scenarios and re-enter at the next day's opening.