Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

How GetCurrentAsk/GetCurrentBid differs from GetAsk/GetBid

Collapse
X
 
  • 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)
    return;


    // 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:

    Code:
    Realtime 64 | 90.75
    Realtime 65 | 90.75
    Realtime 66 | 90.75
    ...

    but if refresh chart, then sometimes it shows different:

    Code:
    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?

    #2
    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

    Comment


      #3
      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.

      Comment


        #4
        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

        Comment


          #5
          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.

          Comment


            #6
            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

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by XXtrader, Yesterday, 11:30 PM
            2 responses
            11 views
            0 likes
            Last Post XXtrader  
            Started by Waxavi, Today, 02:10 AM
            0 responses
            6 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Started by TradeForge, Today, 02:09 AM
            0 responses
            11 views
            0 likes
            Last Post TradeForge  
            Started by Waxavi, Today, 02:00 AM
            0 responses
            2 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Started by elirion, Today, 01:36 AM
            0 responses
            7 views
            0 likes
            Last Post elirion
            by elirion
             
            Working...
            X