• 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


Getting bid and ask from execution update

  • Filter
  • Time
  • Show
Clear All
new posts

    Getting bid and ask from execution update

    Is there an easy way to get the current Bid and Ask price from the Account_ExecutionUpdate callback without requiring an open MarketData connection?

    When the ExecutionUpdate callback is fired, I need to know what the spread is in order to determine the appropriate price for my Stop and Target orders.....

    It seems wasteful to be holding a MarketData connection open the whole time my entry order is working just so that I've got up-to-date spread/bid/ask info when the entry fills and I need to Submit the stop and target. Is there a better way to get this info ?

    Hello reach4thelasers,

    As the Tick Replay feature nearly does what you are describing, I have submitted a feature request to the product management team for the following feature :

    This customer would like checkboxes for the Tick Replay feature to access Bid and Ask data along with the Last data
    I will follow up with more information as soon as it's available. If the feature requests already exists, a vote will be added to it.

    Please let us know if there are any other ways we can help.
    Jessica P.NinjaTrader Customer Service


      Hey Jessica,

      I'm not sure I understand where TickReplay comes into this.... I'm working with an Addon. One which can submit orders. And when the ExecutionUpdate callback returns I need to submit my stops and targets - so need to know the Bid/Ask at that point so I can determine the spread.

      Not sure if you misunderstood me or if I'm misunderstanding you but I thought I would clarify!




        The misunderstanding was on my end, I thought you were describing a strategy. I will leave the feature request in place in case a similar request comes in from our user base; the vote will be coming from myself instead of you.

        Would it be possible to provide a stripped down copy of the add-on you are using to retrieve market data?
        Jessica P.NinjaTrader Customer Service


          Hey Jessica,

          I've attached an example addon of what i'm on about.

          It adds a button to chart trader, which submits an order on GBPNZD. So put the chart on this instrument.

          The Execution update handler adds a target of 2 pips and a stop of 2 pips.

          Since the spread on this Forex pair is usually 3 pips, I need to add the spread on to the stop and subtract from the target at this point, otherwise the stop would be below the current bid price and my target would make a -1 pip loss if hit.

          You'll see on SIM101 they fill immediately on the next tick (on a live account the orders would be rejected as invalid).

          So my question is: Is there an easy way to get the Current Bid and Ask Price at this stage, so that I can determine the spread? In my implementation, I am using a MarketData connection, which I am keeping open and is constantly updating fields in my class with the bid and ask just so that I have up-to-date spread info available for when the ExecutionUpdate callback fires and its time to submit the stop and target. However, it seems inefficient and wasteful to do this - especially because its happening for every entry order I have waiting to be filled, and I'm wondering if there's any easier way to get this info from the context of an addon in the ExecutionUpdate handler.
          Attached Files


            Thank you for this added information. Since you seem to know your way around add-on codes and WPF from the code sample you provided, the AutomationIDs for the Chart Trader ask and bid prices are



            Each is a WPF textblock, linked publicly available documentation.

            The above information was discovered using this advice, http://ninjatrader.com/support/forum...44&postcount=7 .

            Please let us know if there are any other ways we can help.
            Jessica P.NinjaTrader Customer Service


              Thanks Jessica,

              However I don't think that will work, because I might submit an order then switch to another instrument - so although the chart trader instance will be the same, the data it is displaying is for the new instrument.

              I am stumped on this - seems like such a waste holding open a MarketData connection the whole time just so I have the bid and ask available when I finally need it. but if there's no other way I might need to live with that.


                Thank you for helping me fully understand the situation. All the work-arounds I can imagine would require their own market data connections kept open as well.
                Jessica P.NinjaTrader Customer Service


                  I made an asynchronous proxy to wrap up market data access. It subscribes to the MarketData feed when it first gets accessed, and leaves the feed open for a few second after the last time it was accessed then closes it. It will start up again when it gets accessed again.

                  Might be a bit overkill but I feel happier with this approach rather than having MarketData updates ticking away constantly just waiting for an order to be filled so that I can get the spread.

                  Used as follows:

                  private MarketDataProxy _marketDataProxy;
                  var marketDataProxy = new MarketDataProxy(instrument);
                  var bid = await marketDataProxy.GetCurrentBid();
                  var ask = await marketDataProxy.GetCurrentAsk();
                  var spread = await marketDataProxy.GetSpread();
                  The await calls return instantly pretty much instantly so there's no delay in getting the data either.
                  Attached Files


                  Latest Posts


                  Topics Statistics Last Post
                  Started by TraderCAD, Today, 04:27 PM
                  1 response
                  Last Post TraderCAD  
                  Started by DavidHP, Today, 04:11 PM
                  0 responses
                  1 view
                  Last Post DavidHP
                  by DavidHP
                  Started by alexstox, 03-24-2019, 01:07 PM
                  6 responses
                  Last Post NinjaTrader_PatrickG  
                  Started by fredfred, Today, 11:29 AM
                  3 responses
                  Last Post NinjaTrader_JoshG  
                  Started by swcooke, Today, 10:38 AM
                  3 responses
                  Last Post NinjaTrader_Jesse