Whenever I set a range an by the time it runs through the historical time range, the strategy might leave a position open as the trigger has not been reached. Usually my triggers are either a stopLoss order or a target profit. By the time the strategy evaluates the last candle of the range, I have an Open order and two "Working" orders. The two "working orders are OCO since they where associated with the same entry order string.
I am am using the Managed approach for order management using the techniques outline in Advance Order handling (using order objects and OnOrderUpdate() and OnExecutionUpdate() methods.
I would like to close and destroyed the "Working" orders (stopLoss and targetProfit).
Where should I do this?
I am trying to do it in the else if (State == State.Transition) state.
When I do this I get an error that I am trying to cancel a Live order. I am never reaching out the state of RealTime since the Date range end in another date which is not the current day.
I am also aware of a strategy parameter which allows you to close all open position x number of seconds before the EOD. I was thinking of locating an event, check to see that (Position.MarketPosition != MarketPosition.Flat) and then submit a ExitLong or ExitShort order pase of the Position.MarketPosition.
Please advice.
Comment