Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Check the existing order Name

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

    Check the existing order Name

    Thank You NinjaForum

    I am trying to validate for an existing order name and if it exists then placing a second order . here is an example:
    //

    var order2 = Orders.FirstOrDefault(O => O.Name == "LD");

    {
    if ((order2 != null) && ((Closes[0][0] < SMA(10)[0])))
    {

    EnterLong(1, "LD2");
    return;
    }
    }

    The above code is not returning the First order "LD"

    Could you please help me.

    Thanks​

    #2
    Hello NRITV,

    Where is the Orders collection coming from?

    Is this something you created yourself?

    What code is putting orders in this collection?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea B.

      here is the code for the first order entry:
      if ((Position.Quantity == 0) && ((Closes[0][1] > SMA(10)[0]) )
      {
      EnterLong(1, "LD");
      return;
      }

      Here is the code for checking the above order name:
      //
      var order2 = Orders.FirstOrDefault(O => O.Name == "LD");

      {
      if ((order2 != null) && ((Closes[0][0] < SMA(10)[0])))
      {

      EnterLong(1, "LD2");
      return;
      }
      }

      Not sure about the order collection. Could you please help me.

      Thanks​

      Comment


        #4
        Hello NRITV,

        Orders.FirstOrDefault(O => O.Name == "LD");

        Where is the Orders collection defined?

        What code is adding orders to this collection?

        If there isn't any, then likely this is an empty collection and nothing is going to be returned from .FirstOrDefault()?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello Chelsea

          how do I define order collection or is there any other way to code for my above requirements?

          I just want to validate if there is an existing order name "LD"

          Thanks

          Comment


            #6
            Hello NRITV,

            As an example if this Orders variable is a List<Order> object, it would be declared as:
            private List<Order> Orders;

            And instantiated in OnStateChange() when State is DataLoaded as:
            Orders = new List<Order>();

            And elements added to the list from OnOrderUpdate() as:
            if (!Orders.Contains(order))
            {
            Orders.Add(order);
            }

            Below is a link to an educational site on using lists.

            The collection also could be an array, or dictionary, or sortedlist, or other data structure type.
            Learn how to use collections and data structures in .NET. Use generic and non-generic collections in thread-safe operations.

            What kind of collection have you coded the variable Orders as in the code of your script?


            Also just to confirm, your post is in the NinjaTrader 7 section of the forums as this is for NinjaTrader 7, is this correct?
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            649 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            370 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            109 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            574 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            576 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X