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

Using Order Objects

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

    Using Order Objects

    Hi,

    Not really sure if my title is correct or not. Until now, I've only employed Enter, Exit ans Set statements to effect orders in my strategies. I've glanced at a couple of the sample code files that use object variables (eg. myOrder = EnterLong() or some such thing).

    It looks like there is so much more power with this approach, but try as I might by perusing the sample code, I'm not really getting how this works and can't find any specific instructions or very simple stripped down examples so I can understand exactly what's going on.

    I do have some cursory knowledge of objects in c#, but I'm always used to seeing a "new" key work when creating objects. That doesn't appear to be the case in ninja. Perhaps this has something to do with the fact that the orders are worked with through an interface. Just a guess on my part.

    I guess I'm looking for some suggestions on where to begin understanding and using order objects instead of just using the order statements (Enter, Exit, Set).

    #2
    Hello,

    Sure let me clarify a bit more for you.

    The Order objects are created by the NinjaTrader CORE itself, Not the strategy this is why you do not see the new key work.

    All the strategy is doing is storing the order object reference in an iOrder object in the strategy.

    This allows you read only access to the object to allow you to access information about the order state.

    If you switch over to unmanaged approach you can use CreateOrder() to create specific orders with more control then just EnterLong for example. However there is a lot you can do with accessing order states with the iOrder object without switching over to unmanaged mode.

    Let me know if you have any further questions.

    -Brett

    Comment


      #3
      Thanks Brett,

      I'm wondering if I've totally over-complicated this deal. Putting in my own words, when I assign an order to a variable like myOrder, that allows me to access the list of order properties shown in the documentation.

      I guess the other thing I'm not 100% clear on it this: how do you actually submit an order using this type of syntax? Or, perhaps I've over complicated again... when you initialize myOrder by setting it equal to something like EnterLong(), does that submit the order in the same way as if you merely coded EnterLong(); all by itself?

      Comment


        #4
        I'm wondering if I've totally over-complicated this deal. Putting in my own words, when I assign an order to a variable like myOrder, that allows me to access the list of order properties shown in the documentation.
        Correct



        I guess the other thing I'm not 100% clear on it this: how do you actually submit an order using this type of syntax? Or, perhaps I've over complicated again... when you initialize myOrder by setting it equal to something like EnterLong(), does that submit the order in the same way as if you merely coded EnterLong(); all by itself?
        Correct there is virtually no difference in what is being done. The only difference is that you are storing the reference to what EnterLong() is doing in the variable(Object reference). This way you can access it later and find out its details. Otherwise we have no way to access it.

        -Brett

        Comment


          #5
          Hi Brett,

          Here's a follow up question:

          How long do the IOrder properties persist?

          For example, lets say an order is submitted, but not yet filled. Then it's obvious the IOrder properties for the submitted order still exist. But, let's say the order was filled, then....

          1) assumming no new order has been submitted since the fill, are the IOrder properties still accessable?

          2) assuming a new order was submitted, I'm guessing that the IOrder properties now represent the latest sumbitted order

          3) to clarify: the IOrder properties are always those properties for the most recently placed order, whether filled or not? Correct?

          Comment


            #6
            1) Correct.

            2) Correct

            3) Semi Correct More specifically its the last order you assigned for it to be the reference too:

            For example:
            OnBarUpdate()
            {
            Iorder myFancyIOrder = EnterLong("ENTRY 1');

            EnterLong("ENTRY 2");

            Print(myFancyIOrder.Name);
            }
            OUTPUT:

            ENTRY 1

            -Brett

            Comment


              #7
              I have a further question on IOrder logic and/or syntax. I grabbed this line from the Ninja user guide:

              if (entryOrder != null && entryOrder == order)

              I understand the null check, but I can't figure out the second condition. There is no "order" in the properties list. Can you please tell me -

              a) where "order" comes from

              and

              b) what does it mean?

              Thanks!

              Comment


                #8
                Hello,

                Thanks for the note.

                The is the order that is passed in as a parameter to the method OnOrderUpdate( iOrder order)

                When this method is called it is called with the order object that it is updating the order status of here and you can access it via its identifier, order.

                -Brett

                Comment


                  #9
                  Hello Again,

                  I'm still not getting this, and suspect that once I do I'm going to be REALLY embarrassed how simple it is. Please bear with me while I ask the question a bit differently, which hopefully will let things connect in my head.

                  In this line of code: if (entryOrder != null && entryOrder == order)

                  is "order" a variable? an undocumented property? or what? At my current level of understanding, I don't even see the need to check whatever this is, as if entryOrder is not null, then there must be an order present, right? The way I'm barely able to read it now, it seems like you're checking for the same thing as a null check. So, an additional question is what exactly is entryOrder == order checking for? What is it that is either true or false?

                  I appreciate your patience while working through this with me.

                  Comment


                    #10
                    Sure,

                    This is an aspect of object oriented c# programming.

                    You can think of it like a variable.

                    I don't even see the need to check whatever this is, as if entryOrder is not null, then there must be an order present, right?
                    Correct.

                    entryOrder == order checking for? What is it that is either true or false?
                    This is different, what you are doing here is you are checking is the Order that we are currently processing, match the ID of the order that we submitted.

                    So it works like this:

                    NinjaTrader Recieved Order Fill
                    NinjaTrader Triggers OnOrderUpdate() with the details of the order(Details of the order are stored in an object (variable) called order
                    Your code checked to make sure entryOrder has been submitted (entryOrder != null)
                    You code checked to see if the order we are currently processing is our entryOrder (order == entryOrder)

                    Hopefully that fills in the blanks let me know if it does not and I will try once more.

                    -Brett

                    Comment


                      #11
                      5:20pm on Friday and you send a complete, well thought out answer when virtually every other trading platform's support offices are closed

                      You guys continue and continue to impress. I'm very grateful because now I can work this weekend with a complete understanding.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by dcriador, Today, 12:06 PM
                      0 responses
                      6 views
                      0 likes
                      Last Post dcriador  
                      Started by dcriador, Today, 12:04 PM
                      0 responses
                      4 views
                      0 likes
                      Last Post dcriador  
                      Started by cutzpr, Today, 08:54 AM
                      0 responses
                      10 views
                      0 likes
                      Last Post cutzpr
                      by cutzpr
                       
                      Started by benmarkal, Today, 08:44 AM
                      0 responses
                      16 views
                      0 likes
                      Last Post benmarkal  
                      Started by Tin34, Today, 03:30 AM
                      2 responses
                      28 views
                      0 likes
                      Last Post Tin34
                      by Tin34
                       
                      Working...
                      X