• 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


How GetCurrentAsk/GetCurrentBid differs from GetAsk/GetBid

  • Filter
  • Time
  • Show
Clear All
new posts

    How GetCurrentAsk/GetCurrentBid differs from GetAsk/GetBid

    i.e. I have two questions. Please, number answers relatively to question number:

    I have indicator with:

    AddDataSeries(Instrument.FullName, BarsPeriodType.Tick, 1, MarketDataType.Last);

    in OBU i have:

    if (BarsInProgress == 1)
    if (BarsPeriod.MarketDataType != MarketDataType.Last)

    // problem 1
    Print(State.ToString()+" "+CurrentBar + " | " + BarsArray[1].GetAsk(CurrentBar) );

    // problem 2
    Print(State.ToString()+" "+CurrentBar + " | " + GetCurrentAsk(1) + " " + BarsArray[1].GetAsk(CurrentBar) );


    (questions 1)

    The problem 1 is that the values are different on historical and realtime.
    For example, in realtime it might print:

    Realtime 64 | 90.75
    Realtime 65 | 90.75
    Realtime 66 | 90.75

    but if refresh chart, then sometimes it shows different:

    Historical 64 | 90.75
    Historical 65 | 90.5 <--------------  different
    Historical 66 | 90.75
    that happens not rarely. about once 1 in 4-7 bars. Why?

    (question 2)

    the problem 2 is that in realtime, these two values differ from each other (only rarely they are same). Why ? what is the correct way to collect the ask data correctly for specific bar-index? (i am testing MarketReplay too, and i am describing the problems what i see).
    i've tried this, but either this seems incorrect:

    double ask = State==State.Realtime ? GetCurrentAsk(1) : BarsArray[1].GetAsk(CurrentBar);

    Can you advise me?

    Hello TazoTodua,

    Thank you for your post.

    The difference you are seeing is due to the methods accessing data from different threads at different times. GetCurrentAsk/Bid will get the price from the instrument thread as soon as it is provided from the connection. A MarketDataType will take the bid/ask price from the instrument thread when the market data is provided to instrument thread consumers (charts, additional series, etc.). To get an instant snapshot of current ask/bid, use GetCurrentAsk/Bid()

    Please let me know if I can assist further.
    Chris L.NinjaTrader Customer Service


      ChrisL, thanks for taking time, but that doesnt answer question well. I read in docs what was GetCurrentAsk, and that's not my first problem. my main problem i asked is that I get different results for specific bar in Realtime and in historical, and what function should i use to get them correctle, nevertheless it's realtime or historical.

      and, what's the advantage of `GetCUrrentAsk` over .GetAsk(CurrentBar)?
      Last edited by ttodua; 03-12-2019, 08:31 AM.


        Hello TazoTodua,

        Thanks for the reply.

        GetCurrentAsk only returns the close price in State.Historical, this fact is noted on the HG page on GetCurrentAsk. GetCurrentAsk is designed to be used in real time to get a snap shot of the current ask data, it is not bar related. GetAsk() is how you will access historical ask prices at a specific index. GetAsk is best used for State.Historical. Also, instead of accessing the ask price from the 1 tick last series, you could make the market data type ask in your AddDataSeries method and do the same thing.

        Please let me know if I can assist further.
        Chris L.NinjaTrader Customer Service


          Chris, many thanks again for explanation.

          1) i know that GetCurrentAsk is for realitme, and GetAsk for hisotrical, but I ask for help, what to to in order to get the correct calculations, to get scpecific bar's Ask data.

          I mean, i.e. for bar index 456, whether it's realtime or not, i want to have a code, that will return ASK for that bar index.

          what code can i use to correctly get Ask data correctly for the bar X, nevertheless the code is run in RT or HISTORICAL (using AddDataSeries(tick) ) ?

          2) why it has drawbacks to .GetAsk() for currentbar, like GetAsk(CurrenBar), why cant i use that ? if not that, what code should I use to get Ask value for current bar?

          I've tried to use like this:

          myAskArray[CurrentBar] = State==State.Realtime ? GetCurrentAsk() : BarsArray[1].GetAsk(CurrenBar);

          but for any bar index, it still doesnt work correctly. What code can i use? can i completely disregard `GetCurrentAsk()` and only use `GetAsk` even to realtime or historical?

          3) so, AddDataSeries( .... Ask ) will provide the same value for CurrentBar, as does BarsArray[1].GetAsk(CurrentBar) ?

          please answer in numbered, like : 1,2,3

          many thanks ! ! !
          Last edited by ttodua; 03-12-2019, 09:41 AM.


            Hello TazoTodua,

            Thank you for the reply.

            1. To target a specific bar for its ask price, you must use Bars.GetAsk() because it takes an index parameter. GetCurrentAsk does not take any bar index parameter for historical access. The additional 1 tick ask series is also a solution for tick by tick historical ask updates. Another way to do the same historically would be to turn on Tick Replay and follow this section of the help guide titled "Accessing the current best bid and ask at the time of a trade", that method would not require an additional 1 tick ask series. If you need to access the most current ask price at any given time, you would use GetCurrentAsk. GetCurrentAsk will go directly to the level 1 data feed and access the last ask data the connection adapter received, it does not wait for NinjaTrader to update its ask values from the bar. It can be thought of as a helper method, helping to avoid overriding OnMarketData.

            2. GetAsk is not so much a drawback but more like a different type of tool. GetAsk has the ability to access historical ask values while GetCurrentAsk does not, but GetCurrentAsk has the ability to access the most current ask price from the data provider. Developing for tick replay, or adding a 1 tick series are techniques of getting accurate bid/ask prices while in the historical data run through. To get the bid/ask data for the current bar (the most recent value possible) you would use GetCurrentAsk in real time, or additional tick series/tick replay for historical. If you do not mind the fact that the last ask price recorded by the bar might be different than the last ask price provided by your data provider, you may use GetAsk only.

            3. Adding a 1 tick ask series will give you the finest resolution for ask data versus time. It is the atomic price movement, so a 1 tick series will give you the exact movement of the ask price through time.

            Please let me know if I can assist further.
            Chris L.NinjaTrader Customer Service


            Latest Posts


            Topics Statistics Last Post
            Started by smcllr, Today, 08:25 PM
            0 responses
            1 view
            Last Post smcllr
            by smcllr
            Started by robforee, Today, 02:01 PM
            2 responses
            Last Post NinjaTrader_EricB  
            Started by ALIENFX, Today, 02:05 AM
            1 response
            Last Post bltdavid  
            Started by JTizz, Today, 02:45 PM
            0 responses
            Last Post JTizz
            by JTizz
            Started by papayax999, Today, 02:45 PM
            1 response
            Last Post NinjaTrader_ChelseaB