Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Sync to Broker Positions and Orders

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

    Sync to Broker Positions and Orders

    Hello,

    I have read through the document regarding the "Sync Account Position", and how it will submit orders to attempt to make the account positions (real) match the strategy positions. This seems a bit backwards and potentially dangerous if you are submitting market orders in illiquid names, and possibly at a time of low trading volume.

    I understand that there isn't a setting to "Sync Strategy", and I would like to write my own. To do this I was wondering what classes/methods are available to query on startup:
    1) Broker Positions for all instruments
    2) Pending or Working orders for all instruments
    3) Current Margin
    etc

    Thanks!
    Last edited by Canadian123; 07-21-2011, 07:32 PM.

    #2
    Welcome to our forums - if you wish to monitor / execute the sync needed with other orders you could also not make use of this option, or work your strategy in WaitUntilFlat mode that would trigger the next fresh entry signal only.

    The strategy would only know about it's own orders, there's unfortunately no programmatic access to all account positions / orders per NinjaScript.

    What we would offer are those account related properties :

    http://www.ninjatrader.com/support/h...countvalue.htm
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks Bertrand, have been lurking the forum but this is my first issue I need to resolve looks like the GetAccountValue() will retrieve the cash/BP items.

      For positions & orders, I found this writen by NinjaTrader_Ray. Wouldn't this be programmatic access to all account positions / orders per NinjaScript?

      NinjaTrader_Ray
      03-28-2007, 07:58 AM
      No problem.

      My mistake actually. What we have in the layer under NinjaScript (which is not officially supported via documentation nor tech support) is

      Account.Positions.FindByInstrument(Instrument instrument)

      so, if you wanted to determine if an accountposition existed for the given instrument you would:

      Cbi.Position myPosition = Account.Positions.FindByInstrument(Instrument instrument);
      if (myPosition != null)
      // There is a position

      For clarification, account level propertiesare not supported in the NinjaScript layer although it is exposed for programmer who want to access it. We are just not in a position to provide the support you would expect with these lower level methods and properties.

      The above references the account as a whole.

      Ray

      I also see code floating around as follows:

      int iOrderCount = Account.Orders.Count;Print("Total Open Orders: " + iOrderCount );System.Collections.IEnumerator ListOrders = Account.Orders.GetEnumerator();for (int i = 0; i < iOrderCount; i++) { ListOrders.MoveNext(); Print(" Open Orders: " + ListOrders.Current );}


      Wouldn't this code access Account Positions? Thank you!

      Comment


        #4
        Canadian123, you are using unsupported methods in your code. As such, we can't help you out here. A quick rule of thumb is: if you can find what you're looking for in the help guide, it is supported. If you can't find it, it is not supported.
        AustinNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Austin View Post
          Canadian123, you are using unsupported methods in your code. As such, we can't help you out here. A quick rule of thumb is: if you can find what you're looking for in the help guide, it is supported. If you can't find it, it is not supported.
          Got it.. thanks Austin. However, you may want to clarify that you can in fact access Broker positions & orders from ninjascript but it isn't officially supported. (I was a bit confused)

          A question on reliability, are the values these methods return the same that are used in the background by the "sync strategy positions" functionality?

          Thanks!

          Comment


            #6
            Hi again, that is what these types of threads are for. We don't advertise unsupported methods because they can (and do) change over time with different releases.

            As for your second question, there is no documentation on this either. There are a few methods (most unsupported) you can use to get account positions, and I'm not sure which one is used by the "sync positions" function.
            AustinNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Austin View Post
              Hi again, that is what these types of threads are for. We don't advertise unsupported methods because they can (and do) change over time with different releases.

              Hello,

              To complete the sync, I was wondering how I can create or modify the Portfolio Positions/order to match what I retrieve from the broker if there is a mismatch?

              Supported or unsupported methods are fine. I searched the help manual but couldn't locate this information.

              Thanks!

              Comment


                #8
                Canadian, the sync is automatic. There are no methods you can use to fix a mismatch because it is fixed automatically.
                AustinNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Austin View Post
                  Canadian, the sync is automatic. There are no methods you can use to fix a mismatch because it is fixed automatically.
                  Hi Austin,

                  Just to avoid confusion, I am looking at syncing the strategy to what my broker knows (account positions and orders), not using the sync strategy option.

                  So to clarify with an example:
                  1) My broker knows 2 positions (which can be retrieved with the unsupported method) 2) Ninjatrader Strategy knows 1 position
                  3) How do I add a "historic" position to Ninjatrader Strategy so Ninjatrader strategy now knows 2 positions?

                  Similarly, if I retrieve 3 working orders from the broker unsing the unsupported method, and Ninjatrader strategy only knows 2.. how can I add this order to the strategy so it will show up in the Order tab and can be actioned upon in ninjscript?

                  Thanks

                  Comment


                    #10
                    Canadian123, I must stress here that you're on your own here playing in this territory as we don't have features available that would sync to a known account position, for us the historical strategy is position is paramount.

                    I think what you could do is use two strategies, one for firstly 'grabbing' the broker known position using the method you found and then the other where you would historically execute then the 'known / saved' amount of contracts / shares you need to match up what's currently being held in the account. The info could be passed between the strategies for example via text files using C# 's System IO.
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      It is doable but the solution is not easy to implement. I have a solution but it needs custom programming to adapt it to your strategy. Unfortunately not free and not even a bargain.. pm me if interested

                      Andreas
                      P.s. you will find some info in my thread posts on the topic
                      Www.zweisteintrading.eu

                      Comment


                        #12
                        Sharing information between strategies

                        In case anyone else is trying to do something like this, I finally figured out that you can just declare the object you want to share as static in UserDefinedFunctions.cs. This will make the object a member of the Strategies class and make a single instance of the object available to all of your strategies.


                        Originally posted by NinjaTrader_Bertrand View Post

                        I think what you could do is use two strategies, one for firstly 'grabbing' the broker known position using the method you found and then the other where you would historically execute then the 'known / saved' amount of contracts / shares you need to match up what's currently being held in the account. The info could be passed between the strategies for example via text files using C# 's System IO.

                        Comment


                          #13
                          Hi,

                          Does anybody know how to place Historical or Virtual order?
                          Basically, in order to manually synchronize strategy with broker account I'm trying to make Strategy.Position non-flat based on existing position on the broker account.

                          UPDATE:
                          It is possible to place Historical order by placing an entry order in the last Historical bar right before live trading begins.
                          All you need is to add this code in OnBarUpdate():

                          if(CurrentBar==Bars.Count-2)
                          {
                          if( [add your condition here] )
                          {
                          EnterLong(); // this order will be placed as historical right before live bars begin
                          }
                          }

                          Hope this helps
                          Last edited by michaelsh; 03-27-2013, 09:50 AM.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by AdeptistJune, Yesterday, 09:34 PM
                          1 response
                          7 views
                          0 likes
                          Last Post jeronymite  
                          Started by practical2k, Yesterday, 08:30 PM
                          1 response
                          5 views
                          0 likes
                          Last Post practical2k  
                          Started by johnok, Yesterday, 04:30 PM
                          0 responses
                          7 views
                          0 likes
                          Last Post johnok
                          by johnok
                           
                          Started by JTizz, Yesterday, 01:29 PM
                          1 response
                          10 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Started by yodaler, Yesterday, 02:10 PM
                          5 responses
                          15 views
                          0 likes
                          Last Post yodaler
                          by yodaler
                           
                          Working...
                          X