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

Order Collection

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

    Order Collection

    Hi NinjaTrader,

    is it possible to retrieve a collection of all the Orders objects opened in an account?

    All the automated platform I am aware let us to do that, but I do not find anything similar on Ninja. We have a trader collection, why can't we have an order collection?

    My aim is to access pending orders from external strategies and eventually cancel them when my current strategy tells me so.

    Thanks and Regards.

    #2
    Well, it seems that my answer is here: http://www.ninjatrader.com/support/f...ad.php?t=40535

    But I can not understand how this can be possible so I guess there is an other way to do what I am trying to achieve which is very basic stuff finally.

    Comment


      #3
      This is not supported by NT but might give you some ideas. You can access stuff on an account basis that transcends strategies.

      Code:
      [FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]#region[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2][COLOR=#000000] OnTerminition()[/COLOR][/SIZE][/FONT]
      [/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]protected[/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]override[/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]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] OnTermination()[/SIZE][/FONT]
      [/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000]//This method is called once when a stratgey is disabled[/COLOR][/SIZE][/FONT]
      [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2]
      [SIZE=2][FONT=Consolas]{[/FONT][/SIZE]
      [SIZE=2][FONT=Consolas]Print([/FONT][/SIZE][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]); [/SIZE][/FONT]
      [SIZE=2][FONT=Consolas]Print([/FONT][/SIZE][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]);[/SIZE][/FONT]
      [SIZE=2][FONT=Consolas]Print([/FONT][/SIZE][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]DateTime[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].Now + [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]" SYSTEM MONITOR TERMINATED."[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]);[/SIZE][/FONT]
      [SIZE=2][FONT=Consolas]Print([/FONT][/SIZE][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"Total Open Positions: "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] + Account.Positions.Count);[/SIZE][/FONT]
      [SIZE=2][FONT=Consolas]System.Collections.[/FONT][/SIZE][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]IEnumerator[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] ListPositions = Account.Positions.GetEnumerator();[/SIZE][/FONT]
      [/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]for[/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=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] i = 0; i < Account.Positions.Count; i++)[/SIZE][/FONT]
      [SIZE=2][FONT=Consolas]{[/FONT][/SIZE]
      [SIZE=2][FONT=Consolas]ListPositions.MoveNext();[/FONT][/SIZE]
      [SIZE=2][FONT=Consolas]Print([/FONT][/SIZE][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"Open Position: "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] + ListPositions.Current);[/SIZE][/FONT]
      [SIZE=2][FONT=Consolas]}[/FONT][/SIZE]
      [/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000]// TRY THIS >>> Print(Account.Orders. etc etc[/COLOR][/SIZE][/FONT]
      [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]Print([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]); [/SIZE][/FONT]
      [SIZE=2][FONT=Consolas]Print([/FONT][/SIZE][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]""[/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=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] (alertsWindow && Account.Positions.Count != 0) Alert([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"openpositions"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2], NinjaTrader.Cbi.[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Priority[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].High, [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"Open Positions/SystemMonitor terminated"[/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=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"triple_klaxon.wav"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2], 10, [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Color[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].Red, [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Color[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].White); [/SIZE][/FONT]
       
      [SIZE=2][FONT=Consolas]myTimer.Dispose(); [/FONT][/SIZE][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000]// Cleans up the resources[/COLOR][/SIZE][/FONT]
      [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]pingSender.Dispose();[/SIZE][/FONT]
       
      [SIZE=2][FONT=Consolas]}[/FONT][/SIZE][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000]//Close OnTermination()[/COLOR][/SIZE][/FONT]
      [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2]
      [/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]#endregion[/COLOR][/SIZE][/FONT]
      [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]

      Comment


        #4
        Thanks a lot MXASJ. I'll try that.

        Comment


          #5
          Originally posted by MXASJ View Post
          This is not supported by NT but might give you some ideas. You can access stuff on an account basis that transcends strategies.

          Code:
          [SIZE=2][FONT=Consolas]Print([COLOR=#a31515]"Total Open Positions: "[/COLOR]+ Account.Positions.Count);
          System.Collections.[/FONT][/SIZE][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]IEnumerator[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] ListPositions = Account.Positions.GetEnumerator();[/SIZE][/FONT]
          [/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]for[/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=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] i = 0; i < Account.Positions.Count; i++)[/SIZE][/FONT]
          [SIZE=2][FONT=Consolas]{[/FONT][/SIZE]
          [SIZE=2][FONT=Consolas]ListPositions.MoveNext();[/FONT][/SIZE]
          [SIZE=2][FONT=Consolas]Print([/FONT][/SIZE][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"Open Position: "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] + ListPositions.Current);[/SIZE][/FONT][SIZE=2][FONT=Consolas]}[/FONT][/SIZE][/SIZE][/FONT]
          I've been looking at this kind o thing with a "foreach". Would this work for what you're looking for?

          Code:
          [SIZE="2"][COLOR="Blue"]foreach[/COLOR] (Position accpos in Account.Positions)
          {[INDENT]Print([COLOR="#a31515"] "Open Position: "[/COLOR] + accpos.ToString() );
          [/INDENT]}[/SIZE]
          If so, it's sure a lot simpler.

          Comment


            #6
            But his would not work for Orders. Indeed it seems to be easier to deal with positions.

            Comment


              #7
              You can get orders, too...

              Code:
              [SIZE="2"][COLOR="Blue"]foreach[/COLOR] (Order accOrder [COLOR="Blue"]in[/COLOR] Account.Orders)
              {
                  Print( [COLOR="DarkRed"]"Order: "[/COLOR] + accOrder.ToString() );
              }[/SIZE]

              Comment


                #8
                That works great, thanks. I was able to cancel a pending order opened out of the strategy.

                So finally I do not understand why it is told as unsupported.

                Comment


                  #9
                  Originally posted by AlgoNaute View Post
                  That works great, thanks. I was able to cancel a pending order opened out of the strategy.

                  So finally I do not understand why it is told as unsupported.
                  AlgoNaute - that's great & you're welcome.

                  Generally when a software company says that internal interfaces are "not supported", this is done for one or more of several reasons:

                  1) So they have the flexibility to change those internal interfaces without having to worry about breaking thousands of people's code who might have used the interfaces had they been published. It can be time-consuming to have to make all changes "backwards compatible".

                  2) To keep inexperienced users from getting themselves in trouble, which would then lead to their use of additional tech-support resources, and additional expense for the company.

                  3) Because it's easier to not have to document everything that your product does. Especially when many of the features will only be used by 1% of your potential customer base, and that 1% can probably figure it out anyway.

                  Comment


                    #10
                    Account position / Order status

                    I have been using these two lines of logic for strategy2 to make sure that the account doesnt have a position in strategy1 before it fires about 2 seconds later. Hasnt been working reliably so wonder if any of you guys have found a reliable and fast "cantrade" method.


                    && Account.Orders.Count <=0
                    && Account.Positions.Count <=0

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by bill2023, Yesterday, 08:21 AM
                    3 responses
                    18 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by DawnTreader, Yesterday, 05:58 PM
                    4 responses
                    17 views
                    0 likes
                    Last Post DawnTreader  
                    Started by lorem, 04-25-2024, 09:18 AM
                    10 responses
                    45 views
                    0 likes
                    Last Post lorem
                    by lorem
                     
                    Started by swjake, Today, 12:04 PM
                    1 response
                    3 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by kevinenergy, Today, 12:01 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post kevinenergy  
                    Working...
                    X