I have the following code.
protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment) { int current_quantity = Position.Quantity; msg = string.Format("Order status = {0}, Market Postiion = {1}, Quantity ={2}, Filled = {3}, Position = {4}", orderState, Position.MarketPosition, quantity, filled, current_quantity); Print(msg); if((orderState == OrderState.Filled) && (order_accomplished == false)) { Manage_StopLoss(); Manage_Position(); if(State == State.Realtime) { order_accomplished = true; } } else if(orderState == OrderState.PartFilled) { Manage_StopLoss(); } }
So during entry when this function gets executed I should have a non flat position. However the Position.MarketPosition is still Flat when the order is filled.
This becomes cumbersome when tracking stoploss quantity
I have noticed that even Onposition update does not give accurate Position at all times. E.g i have had instances when the strategy position is 4 however it only gives 3 due to partial fills of 3 and 1. Any ideas?
Comment