Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Account position was not updated

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

    Account position was not updated

    Hi,
    I had the following situation today:

    - my strategy was running and had a position in ZN. I was one contract long
    - I switched the strategy off and did sell the ZN via TWS (I trade via IB) so that I was flat after (that was indended)

    so far so good

    After beeing flat the NT still showed me the one long position in the Strategies window. Why was the position there not updated? Can I update the accound position manually (like a refresh button)?

    I tried to find some similar topic here in the forum but could not find anything.
    Thanks for your help,
    Klaus

    #2
    Hi Klaus,
    Which Start Behavior do you use?
    The Start Behavior settings can be set from the Strategy Parameters when you are adding a strategy.

    NT-Roland

    Comment


      #3
      Hi Roland,
      I am using
      Immediately submit, synchronize account
      Is my issue related to the
      Start Behavior? The strategy was switched off when I flatened the position in TWS.
      Klaus

      Comment


        #4
        Hello Klaus,

        Strategy Positions are separate from Account Positions and are calculated by the trades that the strategy would have made. If you close your position manually, the strategy will not have any knowledge that you have closed this position. Additionally, when you re-enable the strategy, it will process historical data, and it will calculate that it should still be in a position because the strategy itself has not calculated an exit.

        If you would like an example of a strategy that uses the AdoptAccountPosition start behavior to inherit the account position, I have provided an example. This example uses the Unmanaged Approach because it protects a position that was not created by a Managed Approach Enter method.

        Please see the Start Behaviors page NT-Roland linked as well as the document below.

        https://ninjatrader.com/support/help..._account_p.htm

        We look forward to assisting.
        Attached Files
        JimNinjaTrader Customer Service

        Comment


          #5
          Hi Jim,
          thanks for the explanation.
          The thing here was that the strategy did submit a limit order which was not filled and the market moved away from the limit. That was why I disabled the strategy and closed the position manually. Meanwhile the strategy was also flat.
          After enabeling the strategy again the strategy thought I was still long one contract. After that and due to my "Immediately submit...." setting, the strategy sold the one contract which it thought I was still long.
          But I understand now that there is no way to update the account position in the Strategie Tab while there is no strategy running. Is that correct?
          Klaus

          Comment


            #6
            Hello Klaus,

            When you re-enable the strategy it processes historical data, calculates trades that the strategy would have made, and determines the strategy position.

            Wait until flat will wait until the historical position gets closed before a live order can be submitted.

            Immediately Submit does not care what the calculated historical position is and will allow the next trade to be submitted, and the strategy does not wait until it is flat/in sync with the account. This is typically used to resume a position after disabling and enabling.

            Sync Account Position is an additional behavior that syncs the account position to the strategy position, not vice-versa.

            Your strategy did not calculate that it should it close your position and this was done manually. When you re-enabled the strategy, it processed historical data, and calculated it should be in the position that you closed. Because the position was closed by you manually, the strategy would not have calculated that it should be flat.

            If you want to be able to close the position externally from the strategy and have the strategy inherit the account position, you can follow the example provided in post #3.

            If you want to have your strategy ignore historical processing, so it does not calculate a position when you re-enable it, you can add if (State == State.Historical) return; to the top of your strategy's OnBarUpdate method to skip historical processing.

            We look forward to assisting.
            Last edited by NinjaTrader_Jim; 04-13-2020, 09:05 AM.
            JimNinjaTrader Customer Service

            Comment


              #7
              Jim, shouldn't the following code in the AdoptAccountPositionTestUnmanaged example you linked-to in post #3 include an instrument name conditional test to guard against submitting stop and target orders to sell in a different market than a long position is in?
              Code:
                          else if (State == State.Realtime)
                          {
                              if (Position.MarketPosition == MarketPosition.Long)
                              {
                                  oco = GetAtmStrategyUniqueId() + "LongExits";
                                  stopOrder = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, Position.Quantity, 0, Position.AveragePrice - 10 * TickSize, oco, "StopLossLong");
                                  targetOrder = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Limit, Position.Quantity, Position.AveragePrice + 10 * TickSize, 0, oco, "TargetLong");
                              }
                          }

              Last edited by caveat_lector; 04-13-2020, 08:24 AM.

              Comment


                #8
                Hello caveat_lector,

                When AdoptAccountPosition is used the strategy's Position object inherits the position of he Account/Instrument. Since it is already specific to the Account/Instrument, an additional check for the instrument would not be necessary in this example.

                We look forward to assisting.
                JimNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by giulyko00, Today, 11:49 AM
                0 responses
                1 view
                0 likes
                Last Post giulyko00  
                Started by Skifree, Yesterday, 11:38 PM
                1 response
                15 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Started by Mathias79, Today, 10:38 AM
                6 responses
                21 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by eladlevi, Today, 11:02 AM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by Skifree, Yesterday, 11:41 PM
                2 responses
                13 views
                1 like
                Last Post eDanny
                by eDanny
                 
                Working...
                X