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

Multi-Instrument Multi-Entry Strategy: Getting EntryOrder Info

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

    Multi-Instrument Multi-Entry Strategy: Getting EntryOrder Info

    I have a strategy which is Multi-Instrument. Furthermore, it pyramids, so I can have multiple unclosed entries on each instrument.

    I would like to get info (entry price etc) on each separate trade E.g. Trade 1,2,3 each for instruments 1,2 and 3 (so 9 trades in total).

    The problem I have is that Positions[3].AvgPrice is the average of my 3 entries. I would like info for each separate entry.

    Is there an easy way to achieve this? Otherwise, what would you suggest?

    #2
    AntiMatter,

    To expose information specific to one order, you need to structure your orders as IOrder, and can then expose specific execution details using OnExecution()


    This IExecution page provides you with the types of details you can expose about an execution and an example.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks Ryan,

      Just to be clear, should I be having a different IOrder object for each trade, each instrument, or will a single object be fine?

      e.g. is one instance of this sufficient:
      private IOrder entryOrder = null;


      or do I need many IOrder objects e.g.:
      private IOrder entryOrder1 = null;
      private IOrder entryOrder2 = null;
      private IOrder entryOrder3 = null;
      etc....

      Comment


        #4
        A separate IOrder object for each unique order is what you should go for. Since you mention multiinstrument in your first post, you likely will need more than one. It depends what order methods you have exactly, but each distinct Enter() or Exit() statement can have its own IOrder object associated with it.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          OK, thanks.... I'm pushing my c# knowledge beyond the limits now ;-)

          I'm unsure how many IOrder objects I am going to need. I'm going to have to use some sort of 2-dimensional data structure (e.g. list of lists) and create the objects on-the-fly as I need them. Is this going to be possible?


          e.g. I guess I could do something like this..... e.g. create a list of IOrder objects:

          private List<IOrder> entryOrders = new List<IOrder>();

          protected override void Initialize(){
          ...
          foreach(string ticker in tickerList){
          Add(ticker, PeriodType.Minute, 1);
          entryOrders.Add(new IOrder(ticker));
          ...



          However, that last statement doesnt't work.
          Can I create a list of IOrder objects?
          Can I create them on-the-fly within my OnBarUpdate()?

          Comment


            #6
            This may be possible, but general C# like this is outside our scope of support. It may be best to start with a simple strategy using one or two IOrders, so you can be familiar with all the structure required for proper management.

            For populating items to a list consider using OnStartup() instead of Initialize()
            Last edited by NinjaTrader_RyanM1; 06-22-2011, 10:27 AM.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Thanks.

              I have a script using a individual entry/exit/stop IOrder objects nicely. I'm pretty sure If I could just create the darn list of IObjects, I could work out how to reference it. Any problems that occur will all be my own fault.

              I have previously created lists of objects like this:

              private List<IOrder> entryOrders = new List<IOrder>();

              ...then later...

              entryOrders.Add(new IOrder("ticker"));

              However, I get the error:
              "Cannot create an instance of the abstract class or interface 'NinjaTrader.Cbi.IOrder'.

              Any ideas what I am doing wrong?

              Comment


                #8
                This sample may provide some clues on adding different object types to a list.


                You won't use a new keyword here, but will need to pass in an IOrder object into your Add() statement. All we can suggest here is to play around with it, and hopefully community members can offer their input on working with an IOrder list.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Ah yes, I am making some headway with this approach.....

                  Comment


                    #10
                    Is there any reason to declare my IOrder objects? It would be easier for me to leave them undeclared e.g:

                    Code:
                    entryOrders.Add(EnterLong(BarsInProgress, quantity1, Instrument.FullName +  openBar + "MKT");
                    then, if I want to alter/access any information for the IOrder objects, I can loop over them thus:

                    Code:
                    foreach ( IOrder enOrder in entryOrders) {
                                                
                                                Print(enOrder.Name + enOrder.Instrument);
                    
                    do stuff....
                                            
                    }
                    Could this cause problems?

                    Comment


                      #11
                      As you're wandering into unsupported territory, I can't really comment on anticipated problems. You'll have to troubleshoot and test thoroughly on your side.
                      Ryan M.NinjaTrader Customer Service

                      Comment


                        #12
                        No worries, thanks for the help.

                        As long as you can't envisage any problems *in theory*, I will push on, it seems to be working. As always, I will be thoroughly checking everything.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by alifarahani, Today, 09:40 AM
                        6 responses
                        31 views
                        0 likes
                        Last Post alifarahani  
                        Started by Waxavi, Today, 02:10 AM
                        1 response
                        17 views
                        0 likes
                        Last Post NinjaTrader_LuisH  
                        Started by Kaledus, Today, 01:29 PM
                        5 responses
                        14 views
                        0 likes
                        Last Post NinjaTrader_Jesse  
                        Started by Waxavi, Today, 02:00 AM
                        1 response
                        12 views
                        0 likes
                        Last Post NinjaTrader_LuisH  
                        Started by gentlebenthebear, Today, 01:30 AM
                        3 responses
                        17 views
                        0 likes
                        Last Post NinjaTrader_Jesse  
                        Working...
                        X