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 TiffanyMiller, Today, 10:19 PM
            0 responses
            2 views
            0 likes
            Last Post TiffanyMiller  
            Started by JackyP, 07-25-2023, 08:39 AM
            2 responses
            310 views
            0 likes
            Last Post j4trdr
            by j4trdr
             
            Started by algospoke, 05-13-2024, 06:53 PM
            12 responses
            132 views
            0 likes
            Last Post algospoke  
            Started by psangram, Today, 06:35 PM
            0 responses
            4 views
            0 likes
            Last Post psangram  
            Started by Alaina19, Yesterday, 04:38 PM
            2 responses
            16 views
            0 likes
            Last Post Alaina19  
            Working...
            X