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

Unmanaged approach: Syncing Accounts

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

    Unmanaged approach: Syncing Accounts

    I'm coding with unmanaged approach method, which makes me to think any detail regarding logic flow of orders, accounts..etc

    One critical aspect is the syncing accounts and strategy position, which triggers doubts:

    - Is the settings about syncing accounts kept the same regardless managed or unmanaged approach methods?

    - If I suffered a disconnection, when NT comes back to be connected, how can I call the real position and quantity held in my broker account?
    I don't think that is as simple as calling Market.Position and Market.Position.Quantity, cause this info could comes from the Script Strategy Position. As a matter of fact, everytime after the typical few minutes resetting of IB's servers, the Strategy Position and the real Account position are not synced any longer; it was necessary then tweeking all that settings, substitute Recalculate by KeepRunning but that's not 100% a reliable solution.

    - After a disconnection which is the best and reliable method to get what's my broker's account position and quantity?
    Thanks

    #2
    Since several times my Scripts has suffered unsyncing cause resettings from IB's servers or ADLS connection, I consider extremely important to be able to code a manual syncing between my accounts. Let's suppose that I can call correctly my broker account's position, knowing that then I could assign manually that position to Market.Position and Market.Position.Quantity ?

    Comment


      #3
      Hello pstrusi,

      Originally posted by pstrusi View Post
      - Is the settings about syncing accounts kept the same regardless managed or unmanaged approach methods?
      Yes

      Originally posted by pstrusi View Post
      - If I suffered a disconnection, when NT comes back to be connected, how can I call the real position and quantity held in my broker account?

      - After a disconnection which is the best and reliable method to get what's my broker's account position and quantity?
      NinjaTrader will try to get any account positions updates and update them inside of your strategy but if you want to manually check your real position and quantity there is some unsupported code that you may want to try to use to get this information.
      JCNinjaTrader Customer Service

      Comment


        #4
        Thanks for your response JC, let me ask you this:

        Since I consider extremely important to sync my accounts, and sometimes under certain circumstances NT is not able to do so ( Despite correct settings ) so I'd like be able to code a manual syncing between my accounts. Let's suppose that I can call correctly my broker account's position, knowing that then:
        I could assign manually that real position to my Strategy Position by setting Market.Position and Market.Position.Quantity as it should be?

        Comment


          #5
          JC, seeing your example of getting broker's account position and quantity, I did this little snippet that intends to sync manually in case that NT could not do it:

          Code:
          foreach (Account acct in Cbi.Globals.Accounts)				
          {				
          	if (acct.Positions != null && acct.Name == "Sim101")			
          	{			
          		PositionCollection positions = acct.Positions;		
          		foreach (Position pos in positions)		
          		{		
          			if (pos.Instrument.FullName == "ES 03-14")	
          			{	
          				Position.MarketPosition = pos.MarketPosition;
          				Position.Quantity = pos.Quantity;
          				Position.AvgPrice = pos.AvgPrice;
          			}	
          		}		
          	}			
          }
          What do you think ? could it do its job ?

          Comment


            #6
            Hello pstrusi,

            You would not want to set "pos" values to the "Position" values but you will want to check to see if they are equal. If they are not equal then you may want to add logic in your strategy to make them sync up.
            JCNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_JC View Post
              Hello pstrusi,

              You would not want to set "pos" values to the "Position" values but you will want to check to see if they are equal. If they are not equal then you may want to add logic in your strategy to make them sync up.
              Thanks for the suggestion, it makes sense, but, a doubt:

              Wouldn't I want to do it because it could lead to an error or just is simple that I can't do that ?

              Imagine for example that after comparing those positions, the broker account position is larger than the strategy position, so, what would I do?
              1. Send orders to the broker in order to sync to my strategy position?
              2. How Can I assign to the Strategy Position my Broker account values?

              Thanks
              Last edited by pstrusi; 12-17-2013, 05:22 PM.

              Comment


                #8
                Hello pstrusi,

                You wouldn't get an error but changing those values would be meaning less since, the strategy still has its own virtual Performance of the trades. The best way I can think of to be able to handle this is to display the differences in your Strategy Position and Account Position and then manually place orders to get them to match.

                If you Position is greater in your Account than your Strategy I am not sure this is much that you can do since place orders in real-time data will submit live orders. The only thing that you can try is submit orders Historically to get them to match but then that can throw off your Strategy Logic.
                JCNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_JC View Post
                  Hello pstrusi,

                  You wouldn't get an error but changing those values would be meaning less since, the strategy still has its own virtual Performance of the trades. The best way I can think of to be able to handle this is to display the differences in your Strategy Position and Account Position and then manually place orders to get them to match.

                  If you Position is greater in your Account than your Strategy I am not sure this is much that you can do since place orders in real-time data will submit live orders. The only thing that you can try is submit orders Historically to get them to match but then that can throw off your Strategy Logic.
                  Thanks for your response JC.

                  NT has the well known sync feature that will take care of assessing accounts and submit live orders to equalize them; but my worry here is for the very often situation where IB's servers reset around midnight for about 2 or 3 minutes, interrupting the data feed, thus very often affecting the normal flow of the strategy and more over the syncing process. The final results is that after connection is recovered you could find yourself with unsynced accounts despite you set for a full syncing. So in order to have a reliable script that can handle this situation, I'd like to code a manual syncing, where after assessing the whole strategy and broker account, I can send real live order to equalize all. It makes sense comparing values then sending orders. I'll try to code this,if any further help I'll let you know.

                  Best

                  Comment


                    #10
                    Hi JC,

                    The syncing process by NT most of times works pretty well, except when a disconnection occurs and afterwards the connection is back again. In those cases, if changes have occurred, the syncing between your accounts won't be any longer. I've posted this thread which addresses the issue.


                    In order to avoid that risk, and still having in mind that NT wasn't meant to be a blackbox, it's convenient to have some logic procedure for the very often case, when IB's servers are reset about midnight for about 2 or 3 minutes. This disconnection is not the programmed IB login-off, that's different.

                    So, back in designing this manual procedure of syncing accounts if any disconnection occurs, this there's a problem that seems not to have solution. Imagine that your Script has a Long position perfectly synced with your broker's account, suddenly a disconnection, when NT recovers its connection, your position in the broker's account is different, so you must sync accounts. It's easy to calculate what's missing and sending live order to equalize the accounts, BUT: by doing this, it seems there will be always a difference, cause by sending live orders to equalize them, will affect always your Strategy Position in the same way, therefore they will never match again. So:

                    - Under this circumstance, is there any way, command, procedure to RESET the Strategy Position when actually your broker's account is totally flat?

                    - Is there any way to send live orders automatically outside of the Strategy Position?
                    Last edited by pstrusi; 12-22-2013, 09:38 AM.

                    Comment


                      #11
                      pstrusi,

                      Thanks for your note.

                      If the strategy is out of sync due to an order that was placed by the strategy being filled while NinjaTrader was not connected, when the connection is re-established there should be an update to your strategy letting your strategy know the order has filled and should update the account as well as the strategy position.

                      If the strategy is out of sync due to an external order, or an order that was not submitted by the strategy, it will not be possible to re-sync the strategy with the account. You would need to disable and then re-enable the strategy so that it does the account sync again.

                      But just a thought, would it be better to have specific logic in your strategy for when the account and strategy are not in sync?
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Thanks Chelsea for your attention regarding this.

                        If the strategy is out of sync due to an order that was placed by the strategy being filled while NinjaTrader was not connected, when the connection is re-established there should be an update to your strategy letting your strategy know the order has filled and should update the account as well as the strategy position.
                        In that very often case when IB resetting its servers about midnight E.T. , and despite there are not orders out of the strategy, with settings on "Recalculate"...etc the Algo was not in syncing any longer. I asked this to a member of support team, answer:
                        strategy to recalcuate > this will mean it will rerun it's calculations on all historical data up to the reconnect point which could lead to a different strategy position and thus could mean the sync that prior to the disconnect existed is now not given anymore
                        I asked to others users which I consider well in the known with similar answers. In conclusion: it seems that syncing accounts is pretty sensible and easily lost when a disconnection occurs. So far the best way consist and manually to reset Algo with a flat position in your brokerage account.

                        If the strategy is out of sync due to an external order, or an order that was not submitted by the strategy, it will not be possible to re-sync the strategy with the account. You would need to disable and then re-enable the strategy so that it does the account sync again.
                        Unfortunately this is never the case.

                        But just a thought, would it be better to have specific logic in your strategy for when the account and strategy are not in sync?
                        The logic that I'd like would be to be able to sync accounts again, but if accounts are unsynced, there's no way to have an automated solution from the script itself. The only logic is to let you know there was a disconnection.

                        If any ideas please share: I'll take a look on it.
                        Last edited by pstrusi; 12-23-2013, 01:53 PM.

                        Comment


                          #13
                          Hello pstrusi,

                          That I know of, there isn't away to keep these in sync with these settings.

                          The issue you seem to understand, that by using recalculate this can cause your strategy to no longer be in sync and will no longer be able to be in sync with the account. If you submit a re-conciliatory order, this will increase both the account and strategy position keeping them out of sync.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            That's right Chelsea, that's why I decided to code a little snippet which prevents the Algo from trading, besides cancels all orders and closes any opened position.

                            However, and if it's possible, this could be a request for your developers: get better the function of Recalculate in order to keep a more reliable syncing. This is a feature that many miss really.

                            Thanks

                            Comment


                              #15
                              pstrusi,

                              I agree and I am submitting a feature request to allow a strategy's virtual position and quantity manually update-able.

                              Thank you for the great feedback about improving NinjaTrader.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Christopher_R, Today, 12:29 AM
                              0 responses
                              10 views
                              0 likes
                              Last Post Christopher_R  
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              166 responses
                              2,235 views
                              0 likes
                              Last Post sidlercom80  
                              Started by thread, Yesterday, 11:58 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post thread
                              by thread
                               
                              Started by jclose, Yesterday, 09:37 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post jclose
                              by jclose
                               
                              Started by WeyldFalcon, 08-07-2020, 06:13 AM
                              10 responses
                              1,415 views
                              0 likes
                              Last Post Traderontheroad  
                              Working...
                              X