• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


Target hit while connection lost

  • Filter
  • Time
  • Show
Clear All
new posts

    Target hit while connection lost

    I have an Unmanaged strategy that was running fine with IB until the following situation:

    Pre connection loss:
    Strategy was Long with a Target and Stop (oco).

    During connection loss:
    Target was filled. So my broker account was Flat.

    After re-connection:
    NT knows nothing about the Target being hit. So strategy incorrectly reports MarketPosition.Long, and will not do anything because it just waits for an update from either the Stop or Target orders.
    Looking at the NT Orders I see it has marked the Target and Stop orders with Status (OrderState)=Unknown.

    Question: Is there any way I can force (preferably in code) the NT Target and Stop order objects to resync from the correct status on the Broker's server?

    Hi DaveE,

    Thank you for your post.

    Can you please send me your log and trace to support by going to Help -> Mail to Support
    Put ATTN Cal in the subject and reference this thread in the body.
    Cal H.NinjaTrader Customer Service


      I've done some more testing.
      Problem 1: Target and Stop hit at broker during disconnection, are not updated on NT, after reconnection, to correct status from the server, but both get set to OrderState.Unknown.
      This problem occurs regardless of whether Managed or Unmanaged strategy is used.

      Problem 2: If Unmanaged=true then OnPositionUpdate is not called after reconnection (even though the position did change at server during disconnect due to either Target or Stop being hit). So the strategy does not work correctly after reconnection since it thinks its in a different MarketPosition to reality.
      This problem does not occur in a Managed strategy since OnPositionUpdate does get called after reconnect, so position of strategy correctly reflects server after reconnect.

      Since Problem 2 is the most serious. What I really need is some code (I dont care if its unsupported/undocumented) that will force Position to be resync'd from the server.

      Has anyone who runs an Unmanaged strategy on IB found a solution to this problem?



        The paper trading account has a random interval for when it sends position updates to NinjaTrader. This is limitation with the paper account
        I tested out the concept on a different account and connection and got the expected results of the strategy.

        Let me know if I can be of further assistance.
        Cal H.NinjaTrader Customer Service


          Hi Cal,

          When you say a "different account" do you mean a Live IB account?
          When you say "got the expected results" do you mean that Position was updated correctly on a Live IB account after reconnect (even for an Unmanaged strategy)?
          Do you also mean that the OrderState for the Target and Stop IOrder objects get set correctly after reconnect on a Live IB account (rather than being set to Unknown)?

          It would still be useful to know how to call 'PositionUpdate' from code (whatever function it is that NT reconnection calls), because I cant test on my Live account and I cant reliably backtest a strategy that uses Target and Stop at the same time (because of lack of information in historical bars).



            I tested the strategy with a different demo account from a different broker.

            When I say got expected results, I mean that when I tested the disconnection and reconnected the strategy called the position update as expected from the broker I was using.

            The strategy will always call OnPositionUpdate() when you get reconnected but that doesn't mean there was a position update from the broker side with the IB demo account as it is a random event with the demo account.

            There is no way to force the code to call OnPositionUpdate with manually disconnecting and reconnecting.
            Cal H.NinjaTrader Customer Service


            Latest Posts


            Topics Statistics Last Post
            Started by Johnny Santiago, Today, 06:18 PM
            1 response
            Last Post Johnny Santiago  
            Started by EnveousColnago, Today, 05:43 PM
            0 responses
            Last Post EnveousColnago  
            Started by Zigfried, Today, 02:30 PM
            2 responses
            Last Post Zigfried  
            Started by lunardiplomacy, Today, 11:35 AM
            4 responses
            Last Post lunardiplomacy  
            Started by silverm3170, Today, 11:24 AM
            3 responses
            Last Post NinjaTrader_Jesse