Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How order fill confirmation works between Interactive Broker and Ninjatrader?

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

    How order fill confirmation works between Interactive Broker and Ninjatrader?

    Hi, when the trading bot send order to Interactive Broker, will it get order filled confirmation from Interactive Broker, sometimes order doesn't get filled. If it is not filled, bot will try to close a position which hasn't been taken in the first place. How this works.

    #2
    Hello Murphy67,

    Orders will stay pending until an error is returned, or it is accepted by the broker. NinjaTrader will not try to timeout on pending orders, however a strategy will enter Connection Loss Handling behaviors if it detects a disconnection from the order feed, or the data deed.

    Custom behaviors can be created to monitor OnOrderUpdate and to watch orders change states, so it would be possible to program behavior in NinjaTrader to try to cancel and order if it has not been accepted at an appropriate time.

    Connection Loss Handling Behaviors are set in the Control Center's Tools > Options Strategies menu.

    https://ninjatrader.com/support/help...riptProperties

    Let us know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      I have another question related to this. I will have two separate trading bots which will work independently but sending orders to same IB account. One bot will only take long positions, other bot will take only short positions.

      In this case, when a long and a short order is sent, IB will not see any position, these two orders will cancel out.

      My question is: when I don't have any position on IB, trading bots will continue to operate regardless the status on IB or bots will also close the positions for themselves?

      I only want bots to check for confirmation of their buy/sell order and I don't want them to get feedback from IB for "position status", if it even exists.

      Comment


        #4
        Originally posted by Murphy67 View Post
        I have another question related to this. I will have two separate trading bots which will work independently but sending orders to same IB account. One bot will only take long positions, other bot will take only short positions.

        In this case, when a long and a short order is sent, IB will not see any position, these two orders will cancel out.

        My question is: when I don't have any position on IB, trading bots will continue to operate regardless the status on IB or bots will also close the positions for themselves?

        I only want bots to check for confirmation of their buy/sell order and I don't want them to get feedback from IB for "position status", if it even exists.
        Each strategy runs independently of the other and knows only about
        its own virtual strategy position. The real account position gets updated
        from buy/sell operations generated by each virtualized strategy position.

        The 'position status' reported by each strategy comes from it's own
        virtualized strategy position -- this status is never guaranteed to be
        an accurate reflection of the real account position.

        -=o=-

        You should understand the hazards when trading the same instrument
        in the same account with two separate bots (one for Long entries and
        another for Short entries).

        Your account position could quickly become out of sync with your strategy
        position, giving you unexpected and very surprising results.

        How so?
        Say the Long bot sends 'Buy 3', your account is now 'Long 3'. While
        this position is open, the Short bot sees an entry and sends 'Sell 3',
        (your IB account only knows two operations, called Buy and Sell, it
        knows nothing about your two running strategies), and so now your
        account position is flat.

        See that?
        Right there you have a massive problem: each strategy holds a virtual
        position and manages it accordingly -- but all the while your real account
        position is flat.

        Sometime later,
        Let's say your Long bot hits its profit target and sends 'Sell 3' to
        close its position, so now your account goes from flat to 'Short 3'.
        At about the same time, say your Short bot hits its profit target and
        sends 'Buy 3' -- your account becomes flat again.

        How much profit & loss did you generate? It's wildly unpredictable, and
        for certain the real account position will be completely different from what
        ever 'virtual' trade performance your two strategies are reporting.

        Because you're trading the same instrument in the same account, your two
        strategies are interfering with each other. Why? Because each strategy
        thinks it owns the account/instrument position, but there is only one real
        account position per each instrument, and that real account position is
        shared by all strategies trading that particular account/instrument
        combination.

        How to fix this?
        If you want to trade the same instrument with separate Long/Short bots,
        you must use two separate accounts. This eliminates the interference.

        If you insist on using the same account, then you need to write a 'lock'
        mechanism into your strategy code to guarantee only one position at a
        time is taken. That is, each bot needs to acquire the trade lock before
        it can enter its position. Eg, if the Long bot enters a trade, it holds the
        lock for its trade duration, which means the strategy must ignore all
        Short bot entries until the Long bot releases the trade lock.

        Make sense?
        Last edited by bltdavid; 02-09-2022, 07:14 AM.

        Comment


          #5
          Thanks you for your clear explanation.

          This "de-sync" problem you referred to is actually exactly what I intend to create. My script handles/should this de-synced operation. I was concerned about any feedback coming back from IB's real time status would disrupt bots but since bots live on their own virtual planet, it seems ok for the moment.

          Comment


            #6
            Originally posted by Murphy67 View Post
            Thanks you for your clear explanation.
            My pleasure.

            Originally posted by Murphy67 View Post
            This "de-sync" problem you referred to is actually exactly what I intend to create. My script handles/should this de-synced operation. I was concerned about any feedback coming back from IB's real time status would disrupt bots but since bots live on their own virtual planet, it seems ok for the moment.
            If I may ask ...
            What technique are your scripts using to handle it?

            Comment


              #7
              Longs and short trades are being taken according to recent price fluctuations under some rules. It means that while I have a long position, if price moves down, I take short position.

              In this case, long will be closed on IB side with newly acquired short position and I go flat and long trade will book profits. But in bot side, I still have an open short trade. If price moves further down and bounces back up, short bot will want to close the position (if it didn't get its profit target earlier which is the ideal strategy). When this happens, short bot will put a long order to close the short position but since IB doesn't have any position, "closing long order" from short bot will put me on a long trade on IB. This way, I won't have any loss in short trade, possibly a small gain, but I continue to ride the long rally.

              Idea here is to try my chance in both directions at the same time and closing/exiting one of the directional trades (or taking profits), when the ticker starts a strong trend and to capture the rally.

              I made a test on pine script with this. One of the directional trades (strategy) gets completely destroyed but other one books huge profits while maintaining my total drawdown relatively flat and small. I avoid huge drawdowns in grand plan.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Jonker, Today, 01:19 PM
              0 responses
              1 view
              0 likes
              Last Post Jonker
              by Jonker
               
              Started by futtrader, Today, 01:16 PM
              0 responses
              5 views
              0 likes
              Last Post futtrader  
              Started by Segwin, 05-07-2018, 02:15 PM
              14 responses
              1,791 views
              0 likes
              Last Post aligator  
              Started by Jimmyk, 01-26-2018, 05:19 AM
              6 responses
              844 views
              0 likes
              Last Post emuns
              by emuns
               
              Started by jxs_xrj, 01-12-2020, 09:49 AM
              6 responses
              3,294 views
              1 like
              Last Post jgualdronc  
              Working...
              X