I have a strategy that I have written that is working well on a simulated account. However, last night, the strategy apparently lost connection, then got two exceptions when the connection came back, but somehow left a position open with no target or stop. I do not know how that would happen since every entry always has a target and a stop. It did disable the strategy, which is ok, but I it lost $7*4*TickSize*NumberContracts, which is very dangerous as you might assume, in the process before I closed it by hand. Below is a bit of my log as to what happened.
Strategy 'MachTrade/153775916' lost price connection for more than 10 seconds and will be restarted.
Disabling NinjaScript strategy 'MachTrade/153775916'
Enabling NinjaScript strategy 'MachTrade/153775916' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes
Indicator 'HMAColourChange': Error on calling 'OnBarUpdate' method on bar 158: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
Strategy 'MachTrade': Error on calling 'OnBarUpdate' method on bar 3937: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
Disabling NinjaScript strategy 'MachTrade/153775916'
My question is: How do I ensure that when the strategy is stopped, even in an exception, that it closes all orders? And also, how to handle connection loss like above?
Thanks for the help,
Steve
Comment