Strategy turns off on this line Print(stopOrder.OrderId with output error on calling 'OnBarUpdate' method on bar 15287
I was following SampleOnOrderUpdate strategy example how can get orderid to check?
#endregion
#region On OrderUpdate variables
private Order entryOrder = null; // This variable holds an object representing our entry order
// private Order entryOrder = null; // This variable holds an object representing our entry order
private Order stopOrder = null; // This variable holds an object representing our stop loss order
private Order targetOrder = null; // This variable holds an object representing our profit target order
private int sumFilled = 0; // This variable tracks the quantities of each execution making up the entry order
#endregion
(Position.MarketPosition == MarketPosition.Long) //Needs to be in a long position
&& (Close[0] >= trailTriggerLong )
&& (Low[1] > Low[2]) //Ensure the trail will only move up if the new candles low is higher.
)
{
// Print("========"+stopOrder.FromEntrySignal);
stopLong1 = trailLong;
if(Position.MarketPosition == MarketPosition.Long && trailLong <= GetCurrentBid() ){
Print(stopOrder.OrderId);
stopOrder = ExitLongStopMarket(1, true, Position.Quantity, trailLong, "SLL", "Xiphos Long"); //Sets Stop
ExitLongStopMarket(1, true, Position.Quantity, trailLong, "SLL", "Dory Long");
ExitLongStopMarket(1, true, Position.Quantity, trailLong, "SLL", "Kopis Long");
}
trailTriggeredCandle = false; //You can move around trail stop freely until new candle.
}
#region OnOrderUpdate
protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
{
// Handle entry orders here. The entryOrder object allows us to identify that the order that is calling the OnOrderUpdate() method is the entry order.
// Assign entryOrder in OnOrderUpdate() to ensure the assignment occurs when expected.
// This is more reliable than assigning Order objects in OnBarUpdate, as the assignment is not gauranteed to be complete if it is referenced immediately after submitting
if (order.Name == "Xiphos Long" || order.Name == "Xiphos Short"
|| order.Name == "Kopis Long" || order.Name == "Kopis Short"
|| order.Name == "Dory Long" || order.Name == "Dory Short")
{
entryOrder = order;
// Reset the entryOrder object to null if order was cancelled without any fill
if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
{
entryOrder = null;
sumFilled = 0;
}
}
}
#endregion

Comment