Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Accessing orderId in onbarupdate

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Accessing orderId in onbarupdate

    HI in Onbarupdate when working with trail i need to create a condition to check only for Xiphos Long trade and then set stopOrder. Or maybe its better to check for particular orderid I have 3 strategies and strategy sends duplicate orders
    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?

    Code:
    #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​
    if (
    (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.
    }​


    Code:
    #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​

    #2
    Never mind . Actually i went and just used a bool ithat i placed when placed an order nstead of orderid.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    77 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    40 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    63 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    63 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    53 views
    0 likes
    Last Post CarlTrading  
    Working...
    X