Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Clarification on GetBid() and Close[0]

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

    Clarification on GetBid() and Close[0]

    Hello,

    I'm trying to understand real time and historical behavior of GetBid() and the wording is a bit confusing (https://ninjatrader.com/support/help...tml?getbid.htm). I understand that for real time bid/ask prices we should use GetCurrentBid(), but then my confusion is on the difference between GetBid(CurrentIndex) and Close[0] for historical calculations? Ultimately, I'm writing a function that returns the most appropriate bid/ask price based on the State variable.

    Also, if Close[0] returns the historical bid price, then what is the analog for historical ask price?

    Example:

    Code:
    GetBidPrice()
    {
      if (state == realtime)
      return GetCurrentBid();
    
      return GetBid(CurrentBar) or Close[0]
    }
    Thank you

    #2
    Hello jflaggs,

    If the data provider provides ask/bid stamped last historical data, the Bars.GetBid() / Bars.GetAsk() will return the ask or bid stamped on that historical bar.

    The Close[0] would be the last, while the Bars.GetBid() would be the bid stamped on that bar and the Bars.GetAsk() would be the ask stamped on that bar.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      If the provider does not provide historical bid/ask data, what will those methods default to? Close[0]/Last?

      Comment


        #4
        Hello jflaggs,

        Most likely it will return the last, but could return 0.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          NinjaTrader_ChelseaB Hello,

          How about getting the min Ask from 1 bar ago on a renko chart where the Low[1] was not reached?

          For example in this scenario with a renko chart:

          1 bar ago renko:

          Open[1] = 1.9
          High[1] = 1.12
          Low[1] = 1.0
          Close[1] = 1.11

          Lowest Ask value of the previous bar = 1.5

          How do you formulate this?

          double value = MIN(Bars.GetAsk(CurrentBar-1)​,2)[0];​

          If not as above, what else?

          Comment


            #6
            Hello PaulMohn,

            Your understanding on using Bars.GetAsk() is correct.

            Bars.GetAsk() uses an absolute bar index (and not a barsAgo index) and CurrentBar - 1 would be the index of the previous bar.

            This wouldn't be the lowest ask reached, but would be the ask at the time the bar closed. If you wanted the lowest ask reached you would need to add a 1 tick series and find the lowest 1 tick bar from the time the renko bar opened to the time the renko bar closed.


            However, I'm not quite sure about where the Low[1] was not reached. Do you mean you are comparing an indicator value to the Low[1] and the indicator value did not reach the low? Or do you mean the close of the current bar doesn't reach the low of the previous bar?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_ChelseaB View Post
              Hello NinjaTrader_ChelseaB ,

              If you wanted the lowest ask reached you would need to add a 1 tick series and find the lowest 1 tick bar from the time the renko bar opened to the time the renko bar closed.

              A more precise way, on real time data, would be to add a 1 tick series and use Bars.IsFirstTickOfBar on the primary series and collect the time from the tick series bar.
              Reference: https://ninjatrader.com/support/help...ttickofbar.htm
              Do you have a sample showcasing the 1 tick series use with Bars.IsFirstTickOfBar recommended by PaulH reply?

              How to collect the time of the Open of 1 renko bar ago from the 1 tick series and Bars.IsFirstTickOfBar?

              How to collect the time of the Close of 1 renko bar ago from the 1 tick series and Bars.IsFirstTickOfBar?​

              Then how to formulate getting the lowest Ask from 1 renko bar ago using the open time and close time of 1 bar ago? What else other than How do you formulate this?

              double value = MIN(Bars.GetAsk(CurrentBar-1)​,2)[0];​​

              Comment


                #8
                Hello PaulMon,

                Below is a link to an example that demonstrates detecting the first tick of the primary bar in historical without tickreplay.


                Add a 1 tick ask series and a with 1 tick bid series with AddDataSeries().

                Use the logic from the example above to detect the first tick of a new bar.

                Print BarsArray[1].GetClose(CurrentBars[1]);
                Print BarsArray[2].GetClose(CurrentBars[2]);

                Or if the data is ask bid stamped just add a 1 tick last series with AddDataSeries().

                Print BarsArray[1].GetAsk(CurrentBars[1]);
                Print BarsArray[1].GetBid(CurrentBars[1]);
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Today, 05:17 AM
                0 responses
                20 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                119 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                63 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                41 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                45 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X