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

GetBid() for 1 Tick Series vs GetCurrentBid()

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

    GetBid() for 1 Tick Series vs GetCurrentBid()

    In the notes for returning the bid price value at the selected bar index, it states that this method does not return the current real-time bid price. However, if I add a 1 tick data series to the indicator, will it get the current bid price at the time of the last trade during the State == State.Realtime?

    The reason I ask is the docs, GetCurrentBid() or GetCurrentAsk() says that it will return the current bid or ask, but I am interested in the bid or ask when the last trade occurred.



    Code:
    protected override void OnBarUpdate(){
        if(BarsInProgress == 1){
            double bid = Bars.GetBid(CurrentBar);  //GetCurrentBid();
            bool isLastTradeAtBid = Close[0] <= bid;
        }
    
    }

    #2
    Hello habibalex,

    Thank you for the post.

    A 1 tick granularity will be the highest resolution of bars possible to use, but you will access the current ask and bid of the instrument in OnMarketData(). OnMarketData is for real time market data events. It does not matter what data series you are using in this function. Use the MarketDataEventArgs like so:

    Code:
    protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
    {
        // Print some data to the Output window
        if (marketDataUpdate.MarketDataType == MarketDataType.Last) 
              Print(string.Format("Last = {0} {1} ", marketDataUpdate.Price, marketDataUpdate.Volume));
        else if (marketDataUpdate.MarketDataType == MarketDataType.Ask)
            Print(string.Format("Ask = {0} {1} ", marketDataUpdate.Price, marketDataUpdate.Volume));
        else if (marketDataUpdate.MarketDataType == MarketDataType.Bid)
            Print(string.Format("Bid = {0} {1}", marketDataUpdate.Price, marketDataUpdate.Volume));
    }
    More on OnMarketData here:


    More on MarketDataEventArgs here:


    Please let us know if we may be of any further assistance.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      I am not interested in the current ask / bid but what the ask and bid are when the last trade occurred. Will this data be correct using the Bars.GetBid(CurrentBar) for a 1 tick data series added to the indicator?

      Comment


        #4
        Hello habibalex,

        Thank you for the reply.

        Yes, GetBid(barsAgo) will return the bid at that historical bar. I tested this by adding these print statements in OnBarUpdate():

        Code:
        protected override void OnBarUpdate()
        		{
        			Print(Bars.GetBid(CurrentBar) + "Bars.GetBid(int)");
        			Print(GetCurrentBid() + "GetCurrentBid()");
        		}
        I had this running on a 1 Tick chart.

        The prices were sometimes the same and sometimes off by one tick. The safest approach will be this:

        To access the current bid (the bid right this second) use GetCurrentBid()

        To access the bid price of the historical bar, you must use Bars.GetBar(barsAgo). Think of this as if we called GetCurrentBid() at that time.

        You should expect Bars.GetBid(CurrentBar) to be an inaccurate representation of the current bar's bid price. Since you want the bid of the last trade, and since you are already on a 1 tick data series, the bid of the last trade will be Bars.GetBid(CurrentBar-1);

        Please let us know if we may be of any further assistance.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Let say the current bid is 2400 and current ask is 2400.25. A trade occurs at 2400. That trade clears out the bid, so that the new current bid is now 2399.75.

          1. When OnBarUpdate is called, will Bars.GetBid(CurrentBar) be equal to 2400 or 2399.75?
          2. Will Close[0] be equal to 2400?

          Comment


            #6
            Hello habibalex,

            If someone sold everything on the bid at 2400 at 11:59:59, so that the best bid became 2399.75, and 1 second later your 60 minute chart closed i.e OBU was called, well the CurrentBid would be 2399.75. The close would be 2400, as that was the last trade.

            Please let us know if you need further assistance.
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              Im referring to the 1 tick data series in OnBarUpdate (as shown in my example in post #1)

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by cre8able, Today, 03:20 PM
              1 response
              9 views
              0 likes
              Last Post cre8able  
              Started by fiddich, Today, 05:25 PM
              0 responses
              3 views
              0 likes
              Last Post fiddich
              by fiddich
               
              Started by gemify, 11-11-2022, 11:52 AM
              6 responses
              804 views
              2 likes
              Last Post ultls
              by ultls
               
              Started by ScottWalsh, Today, 04:52 PM
              0 responses
              4 views
              0 likes
              Last Post ScottWalsh  
              Started by ScottWalsh, Today, 04:29 PM
              0 responses
              9 views
              0 likes
              Last Post ScottWalsh  
              Working...
              X