Updating my previous post. If I am interpreting the resulting output picture correctly (attached), all trades are not closed until the very last bar.

Attached Files result.png