Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
            Create a new List, add elements to it, and loop over its elements with for and foreach.

            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 NeoTraderBot, Yesterday, 10:55 PM
            0 responses
            6 views
            0 likes
            Last Post NeoTraderBot  
            Started by OliverWaters, Yesterday, 10:35 PM
            0 responses
            6 views
            0 likes
            Last Post OliverWaters  
            Started by Graci117, 07-06-2024, 09:32 AM
            6 responses
            37 views
            0 likes
            Last Post Graci117  
            Started by AdamDJ8, 07-01-2024, 06:50 PM
            2 responses
            121 views
            0 likes
            Last Post AdamDJ8
            by AdamDJ8
             
            Started by AdamDJ8, 07-01-2024, 05:55 PM
            3 responses
            32 views
            0 likes
            Last Post AdamDJ8
            by AdamDJ8
             
            Working...
            X