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 NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    79 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    148 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    79 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    52 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    58 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X