I'm encountering an odd situation with my unmanaged orders, using the same sequence of code that worked flawlessly with NT7.
The code segments, a screenshot of the Output Window, as well as the .txt of the Output window is appended.
Brief summary of events.
1. Entered an unmanaged SellShort order, using iOrder entryShort.
2. First execution of order. However, entryShort is still showing as null (entryShort == null returns as true, blue box in Output Window). The UNKNOWN entries are from OnOrderUpdate.
3. entryShort == null turns false after the first execution (which is a PartFill) - red border
4. Execution proceeds as normal until order is filled, or canceled.
My question is why, or how, is #2 occuring? And how is it possible for an execution of the "entryShort" iOrder to happen, when entryShort == null?
It's causing a lot of issues because I'm using (execution.order == entryShort) to determine the quantity of the stop order, which due to entryShort == null on the first execution, is no longer accurate. I didnt encounter this situation in NT7, so its a bit of headscratcher when transitioning my code to NT8.
Any assistance is much appreciated.
protected override void OnBarUpdate() {[INDENT](bunch of code) if (entryShort==null)[/INDENT][INDENT]{[/INDENT][INDENT=2]CandleOutlineBrushes[0] = Brushes.DeepSkyBlue; Print(Time[0] + " Entered Entry Short Order"); entryShort = SubmitOrderUnmanaged(0, OrderAction.SellShort, OrderType.Limit, (int) entryShortQuantity, entryShortPriceWithOffset, 0, "", "Sell");[/INDENT][INDENT] }[/INDENT] } 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) {[INDENT]if (order == entryShort)[/INDENT][INDENT=2]Print(Time[0] + " EntryShort: " + order);[/INDENT][INDENT]else if (order == entryLong)[/INDENT][INDENT=2]Print(Time[0] + " entryLong: " + order);[/INDENT][INDENT]else if (order == stopShort)[/INDENT][INDENT=2]Print(Time[0] + " stopShort: " + order);[/INDENT][INDENT]else if (order == stopLong)[/INDENT][INDENT=2]Print(Time[0] + " stopLong: " + order);[/INDENT][INDENT]else if (order == closeLong)[/INDENT][INDENT=2]Print(Time[0] + " closeLong: " + order);[/INDENT][INDENT]else if (order == closeShort)[/INDENT][INDENT=2]Print(Time[0] + " closeShort: " + order);[/INDENT][INDENT]else if (order == exitShort)[/INDENT][INDENT=2]Print(Time[0] + " exitShort: " + order);[/INDENT][INDENT]else if (order == exitLong)[/INDENT][INDENT=2]Print(Time[0] + " exitLong: " + order);[/INDENT][INDENT]else if (order == null)[/INDENT][INDENT=2]Print(Time[0] + " null: " + order);[/INDENT][INDENT]else[/INDENT][INDENT=2]Print(Time[0] + " UNKNOWN: " + order);[/INDENT] } protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity, Cbi.MarketPosition marketPosition, string orderId, DateTime time) {[INDENT]Print(Time[0] + " Execution: Is entryshort null: "+ (entryShort==null) + ", and : "); Print(Time[0] + " Execution ID: " + execution.Order); if (entryShort != null)[/INDENT][INDENT=2]Print(Time[0] + " entryShort IS NO LONGER NULL!!!!!!");[/INDENT][INDENT] if (execution.Order==entryShort) {[/INDENT][INDENT=2]stopShortQuantity += execution.Quantity; Print(Time[0] + " entryShort q: " + stopShortQuantity);[/INDENT][INDENT]}[/INDENT] }
Comment