A common inquiry is that the Exit on close didn't work in a NinjaScript Strategy because there is a position after the exit on close should have occurred.
When viewing the log we often find that the Exit on close does indeed exit the position shortly before the end of the session (based on the Exit on close seconds), however, after the exit the strategy places a new order and re-enters the position.
The Exit on close trigger will not prevent a NinjaScript Strategy from placing new orders after this has triggered and this can cause your strategy to take a new position before the end of the session (causing a position to be left open when the session is closed).
I've created a video to demonstrate that first, the Exit on close does work, and second that a new position will be created if the script allows for it. Last, I demonstrate a script that uses a Session Iterator and the Exit on close seconds to set a flag that prevents trades after the exit on close until the new session has started.
https://drive.google.com/file/d/1KP5...Wh1Zp7s3X/view
Attached is the PreventEntryAfterExitOnCloseExample tested in the video.
PreventEntryAfterExitOnCloseExample_NT8.zip
ExitOnCloseTest_NT8.zip
Comment