I am currently working on developing an automated trading strategy. My objective is to be able to close all potentially open stopMarket orders and all potentially open positions at a specific point in time to prevent margin calls. Since I trade on tick charts, I think it wouldnt be sufficient to place such a logic under 'protected override void OnBarUpdate()' as sometimes, a lot of time can pass between bars are opening and closing.
For the orders, is there anything I can do to:
1. Identify all open stopMarket orders (I only use stopMarket orders to enter trades, nothing else)
2. Close them all at a specific point in time
For the positions, is there anything I can do to:
1. Identify all open positions
2. Close them all at a specific point in time
For reference:
I have tried to use the 'ExitOnSessionClose' thing in the strategy, but I still had a trade that was opened at 10:35PM and closed with 'exit on session close' at 10:59PM. I live in the german time zone if that makes a difference. The settings I have used below.
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 1200;
So according to my understanding, this should actually close everything 1200 seconds prior to session close, therefore 20 minutes prior to sessions close. Looking at the official trading times according to CME (I trade MES), there is a daily stop between 4pm and 5pm central time. To get the german time zone, it is basically +7 hours. Then, taking into account that traders are required to close their positions 15min prior to avoid margin calls, I thought I go with 20min just to be extra safe. This does not seem to work during backtesting. So I am a bit lost as to which is the best way to accomplish my objective here.
Hope this gives a good picture of what I am trying to achieve here.
Best wishes.

Comment