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

average fill price

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

    #16
    Hello kalli44100,

    The IsNullOrEmpty() is part of System.Collections.Generic.IEnumerable<> class which is available to List<>.


    I've copied the sample from the help guide and exported this to demonstrate it can compile.
    OnExecutionUpdateSampleTest_NT8.zip

    "This is GC/Gold, average fill price is at 2340.6 at 4 contracts short. Looks like too much division going on but should be correct from the example, not sure what's wrong,, any idea?"

    I think this loop is not necessary:
    for (int i = 0; i < LongEntry1Prices.Count; i++)

    Just call the add and divide assignment without the loop.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      Hello kalli44100,

      "where would i check if a limit order has been placed?"

      The order will update OnOrderUpdate() with OrderState.Accepted or OrderState.Working, and you can store this to a variable or in a List<Order> or Order[] array or Dictionary<string, Order>.
      When the OrderState is OrderState.Filled or OrderState.Cancelled or OrderState.Rejected remove the item from the list, array, or dictionary.


      The attached example may be useful.
      PositionEntryOrdersExample_NT8.zip
      Attached Files
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        Hi Chelsea, I think I found the issue, ,please see my last message, thank you

        Comment


          #19
          Ok thank you, I will play around with that

          Comment


            #20
            Oh just one more question on this: Gaby said with Tradovate these things get ccalled in order. so if i save the orderstate in onorderupdate but i want to check if an order has actually been placed in onbarupdatee, will it give me the old value since onorderupdate gets called after onbarupdate?

            Comment


              #21
              Hello kalli44100,

              If the order is submitted from OnBarUpdate(), it will take time for the order to be initialized, submitted, accepted, working.

              You could check the order state in OnBarUpdate(), but the OrderState won't be working right away, and it will be a later bar update where you'll see the order state has changed.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #22
                Thank you Chelsea!!

                Next Question:P

                How do i go about changing an order in unmanaged mode? It led me to the normal ChangeOrder Object and my attempt was:
                ChangeOrder("LongPos",newSize,Price, 0); // All my orders are called LongPos or ShortPos
                It's throwing an error of course but I can't quite gauge from the helpfile what to put in there. Is that even the correct way of changing an unmanaged limit order?

                So for example, I have 4 buy limit orders sitting below price at different levels, 1 contract each. My short position above is 8 contracts. I now want to spread the 8 out over the 4 levels where my limit orders are in other words change each order to quantity 2 from 1. (And beyond that in a different context change an order from 2 to 1 for example).

                Comment


                  #23
                  Hello kalli44100,

                  The order has to be assigned to a variable from OnOrderUpdate().
                  Then you will need to check the orderVariable.OrderState is OrderState.Accepted or OrderState.Working, and if it is supply the variable holding the order object to ChangeOrder().


                  The ProfitChaseStopTrailUnmanagedExample example uses ChangeOrder().
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #24
                    Thank you, I looked at the suggested example:

                    So in OnOrderUpdate
                    if the position == "LongPos" then myOrder=order; Is that the correct way to set it?

                    Can I not do the same in onbarupdate when i submitunmanaged? Can I do myOrder=submitunmanaged()....

                    But then if all my limit orders are inside the myOrder Variable, how can I then go and change a specific Limit Order? Does the LimitPrice act as identifier? Or do I need to have a different variable for each new limit order? In the example there is only 1 order, and I'm trying to do the nightingale thing with multiple limit orders merging into one order but being able to change the individual limit orders.

                    Comment


                      #25
                      Hello kalli44100,

                      If the order.Name is the order you want to cancel, assign the order to the variable.

                      In the example the orders are assigned by the order name to corresponding variable from the AssignOrderToVariable() method called from OnOrderUpdate() on lines 90 to 112, and 264, and then the order variables are supplied to CancelOrder() on lines 150, 153 in OnBarUpdate().

                      Order objects must be assigned to variables from OnOrderUpdate().
                      From the help guide:
                      "OnOrderUpdate() will run inside of order methods such as EnterLong() or SubmitOrderUnmanaged(), therefore attempting to assign an order object outside of OnOrderUpdate() may not return as soon as expected. If your strategy is dependent on tracking the order object from the very first update, you should try to match your order objects by the order.Name (signal name) from during the OnOrderUpdate() as the order is first updated."
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #26
                        Ok but what about multiple Limit orders? Can they all sit within the same variable or do they need a new variable each? I saw how it was assigned in the example but again it was only for a single order. I want to have hundreds of limit orders on either side and manage them along the way by changing their size. Would it then be better to delete? But then I'd also need them assigned to a variable wouldn't I?

                        So if for example habe 4 buy limit orders all called "LongPos", can i put them all into the var myOrder in onorderupdate together? And then then change the individual limit orders by using their price level as identifier or something?

                        As in i got the example and also what you're saying more or less but how do i specifically deal the issue of multiple Limit orders that i want to change/adjust individually?

                        Comment


                          #27
                          Hello kalli44100,

                          Try having a second look at the PositionEntryOrdersExample Chelsea provided in one of his previous replies.



                          This script uses a Dictionary<string, order> for the orders, not a single Order variable.

                          It demonstrates handling multiple entry orders from a single dictionary.

                          Please let us know if you need further assistance.
                          Gaby V.NinjaTrader Customer Service

                          Comment


                            #28
                            Hi again, just got around to looking into the dictionary example, thank you for that.

                            What is the difference between a dictionary and an array / List (and on that note what's the difference between an array and a List?

                            And how on earth do I access parts of the dictionary? So following the example script it prints the currently selected part of the dictionary only, the String and Order of the last order I presume, or maybe the first order in the Dictionary? As when I try it on the chart and multiple orders are filled, it only ever prints the first entryprice.

                            So do I cycle through the Dictionary every time and then calculate the average from the various entryPrices?

                            The example uses this line:
                            Print(string.Format( "{0} | entries contributing to Long position: {1}", Time[0], string.Join(", ", positionOrdersLong.Select(x => String.Format("{0}: {1}", x.Key, x.Value.AverageFillPrice))) ));
                            I'm a bit confused trying to pick apart this concatenation structure to get the right way of accessing the dictionary value as positionOrdersLong.Select(x.Key, x.Value.AverageFillPrice) just returns that X does not exist in the current scope.

                            Comment


                              #29
                              Hello,

                              What is the difference between a dictionary and an array / List (and on that note what's the difference between an array and a List?
                              how on earth do I access parts of the dictionary?


                              These are general C# questions. I encourage you to look at the Microsoft documentation for more info.



                              Store multiple variables of the same type in an array data structure in C#. Declare an array by specifying a type or specify Object to store any type.


                              Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists.


                              As when I try it on the chart and multiple orders are filled, it only ever prints the first entryprice.
                              I am testing this out and seeing it print out the entryPrice for all orders.

                              I'm a bit confused trying to pick apart this concatenation structure to get the right way of accessing the dictionary value as positionOrdersLong.Select(x.Key, x.Value.AverageFillPrice) just returns that X does not exist in the current scope.
                              This print uses a LINQ statement using x. Just trying to access x without using linq is why you are getting that error, x is not actually defined anywhere outside of that expression in the script.

                              The linq statement going through the dictionary and going to print out all the keys (orders) added to the dictionary, along with their averagePrice.

                              LINQ offers a consistent model for queries on data across various kinds of data sources and formats. In a LINQ query, you're always working with objects.




                              This website also has examples of other ways you can access values in the dictionary.

                              A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
                              Gaby V.NinjaTrader Customer Service

                              Comment


                                #30
                                I'm always amazeed at how well structured your responses are Gaby! Much appreciated!

                                Ok the issue with my code is that every new unmanaged order had the same String/Name and therefore the Dictionary would only ever have one entry that kept getting replaced. I added "LongPos"+i (within for loop) and now I can see the Dict print out the contained orders

                                I went through the examples you posted above: In the Dict example it only ever prints and doesn't assign any variables and in the Linq examples it uses a one dimensional uniform array. So to query a dict, do i have to create 2 queries? a string query for the ordername and a double (is it double in C#?) query for the fillprice?

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by MatthewLesko, 05-21-2021, 09:37 PM
                                4 responses
                                163 views
                                0 likes
                                Last Post Mahmad1323  
                                Started by samish18, Today, 03:02 PM
                                3 responses
                                15 views
                                0 likes
                                Last Post bltdavid  
                                Started by Jakub, Today, 11:06 AM
                                1 response
                                16 views
                                0 likes
                                Last Post NinjaTrader_LuisH  
                                Started by samish18, Today, 03:50 AM
                                10 responses
                                19 views
                                0 likes
                                Last Post samish18  
                                Started by Mestor, 06-03-2018, 10:09 AM
                                16 responses
                                2,872 views
                                0 likes
                                Last Post myaha1000  
                                Working...
                                X