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

Collection of Open Working Orders?

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

    Collection of Open Working Orders?

    Hello,

    I would like to loop through all open active orders to help manage the stop orders associated with multiple legs (i.e. multiple signal names). I want to access the StopPrice of each open stop order to determine if it should be updated.


    Is there a collection of Orders that I can use or do I have to maintain collection of each order I place and make entry in the collection (i.e. List<Order>).

    I see an interface of ITrackedOrdersProvider that has a property TrackedOrders. Does this get all open orders? If so, which class implements this interface?

    If I have to implement Interface in new class how to I populate the List<Order> here:

    Code:
    [FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]
     public [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]class [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]myTrackedOrders[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2][COLOR=#000000] : [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]ITrackedOrdersProvider
    [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]{
     [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]List[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]<[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Order[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]> [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]ITrackedOrdersProvider[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].TrackedOrders
     {
     [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]get
    [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]{
           <How to populate here> [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]
     }
     [/SIZE][/FONT][/SIZE][/FONT]
    Last edited by tornadoatc; 12-13-2015, 09:22 PM.

    #2
    Hello,

    Thank you for the question.

    Generally it is best to use a list or collection to store the strategies orders, this is because you will know these orders are specifically from this strategy only.

    In the case that type of system will not work in your logic, you could look into this post which shows an undocumented approach to accessing orders : http://www.ninjatrader.com/support/f...78&postcount=2

    This would be for the total account though, in this you would get orders from all instruments so you would need to pay close attention on what orders are being used in your logic from this collection.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse,

      I have reviewed the other post you mentioned. This seems to be based on the NT7 object structure. How might the same be done in NT8?

      For instance, I see that the Account class has a collection of Accounts which has a collection of Positions which has a collection of Orders. I want the StopPrice from Active orders. I believe something like the following would work?

      Code:
       [COLOR=#2b91af]Account[/COLOR] myAcct; 
       [COLOR=#2b91af]Position[/COLOR] myPosition = [COLOR=blue]null[/COLOR]; 
       [COLOR=blue]double[/COLOR] myStopPrice;   
        
       [COLOR=green]//lock (Account.Accounts) ?? Not sure when this is needed ... [/COLOR]
       myAcct = [COLOR=#2b91af]Account[/COLOR].Accounts.FirstOrDefault(x => x.Name == [COLOR=#a31515]"myAccountName"[/COLOR]); 
      myPosition = myAcct.Positions.FirstOrDefault(x => x.Instrument == Strategies.FirstOrDefault(y => y.Name == [COLOR=#a31515]"NameOfStrategy"[/COLOR]).Instrument);   
        
      [COLOR=blue]foreach[/COLOR] ([COLOR=#2b91af]Order[/COLOR] order [COLOR=blue]in[/COLOR] myAcct.Orders) 
      {     
       [COLOR=blue]  if[/COLOR] (order.OrderType == [COLOR=#2b91af]OrderType[/COLOR].StopMarket && myPosition != [COLOR=blue]null[/COLOR])     
         {         
                myStopPrice = order.StopPrice;      
          } 
      }
      Please confirm that all orders within the Orders Collection are "Active" orders ?

      Also how do I get the Name of Strategy from Strategy?

      Thanks,

      Comment


        #4
        Hello,

        Thank you for the reply,

        Regarding NT8, I do see the code provided can access the orders, when you Printed and Tested this what was the result you had seen or what problem are you facing?

        I tried a simple test using your code and do see this can access the account and print the orders, filtering would just be a matter of picking the properties you want to filter based on and forming if statements for those properties of the order.

        Code:
        var myAcct = Account.Accounts.FirstOrDefault(x => x.Name == "Sim101");
        
        foreach (Order order in myAcct.Orders)
        {
        	Print(order.ToString
        }
        You could check any of the order properties in a condition such as the type of order or if it is filled or working.

        For the Name of the strategy, this would be the same name property you set in SetDefaults or:
        Code:
        if (State == State.SetDefaults)
        {
             Name								= "Test1";
        }
        The property is "Name"

        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello Jesse,

          My example really loops through all Orders of a given Account. What I want is to find the collection that holds Orders for a given Account, Strategy, and Position. I saw a statement from Matthew here :
          [QUOTE=NinjaTrader_Matthew;414285]Strategies now have a concept of Strategy Position and Account Position.

          That suggests I can get access to such collection.

          I would think there would be something like Account.Strategies[0].Position.Orders (being generic with the indexing of the collections). But there is no collection maintained here.

          Can I get to an Orders collection on a given Account, Strategy, and Position?

          Thanks.

          Comment


            #6
            Hello,

            Thank you for the reply.

            I will post a few different items in my reply here as there are various ways about your question depending on what you ultimately want to do with the accounts/ orders/ strategies.

            You can get orders from an Account and A Strategy, as for a Position, there is no Orders property for the Position object specifically so for that I would need to get further clarification if there is such a collection.

            For the samples I have used linq to simplify the expressions, you could of course use as you demonstrated the standard indexing or Strategies[0].

            First off, from an indicator or strategy you could of course access the Static Account class in the Cbi namespace as we have discussed already which you could further filter. Anyway you go about this you are still going to need to iterate over the Accounts and Strategies and Orders etc to find the data:

            Code:
            Account myAcct = NinjaTrader.Cbi.Account.Accounts.FirstOrDefault(x => x.Name == "Sim101");
            if (myAcct != null)
            {
            	StrategyBase strategy = myAcct.Strategies.First(strat => strat.Name == "Test1");
            	if (strategy != null)
            	{
            		Collection<Order> orders = strategy.Orders;
            
            		Position position = strategy.Position;
            
            		Order positionOrder = position.FirstEntry.Order;
            	}
            }
            Otherwise from a Strategy specifically you can access the Strategies specific accounts orders property or:

            Code:
            this.Account.Orders 
            or just 
            Account.Orders
            This would be in general for the account so you would need to still filter the orders as needed to locate the data you want.

            Regarding the Account and Strategy positions, you can find more on that in the help guide here: http://ninjatrader.com/support/helpG...ionaccount.htm



            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Segwin, 05-07-2018, 02:15 PM
            10 responses
            1,767 views
            0 likes
            Last Post Leafcutter  
            Started by Rapine Heihei, 04-23-2024, 07:51 PM
            2 responses
            30 views
            0 likes
            Last Post Max238
            by Max238
             
            Started by Shansen, 08-30-2019, 10:18 PM
            24 responses
            943 views
            0 likes
            Last Post spwizard  
            Started by Max238, Today, 01:28 AM
            0 responses
            9 views
            0 likes
            Last Post Max238
            by Max238
             
            Started by rocketman7, Today, 01:00 AM
            0 responses
            7 views
            0 likes
            Last Post rocketman7  
            Working...
            X