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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    89 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    135 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    69 views
    0 likes
    Last Post PaulMohn  
    Working...
    X