Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsRequest.Update BarsSeries.GetAsk/GetBid

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

    BarsRequest.Update BarsSeries.GetAsk/GetBid

    In an AddOn, a BarsRequest subscribes the Update event to an OnBarUpdate method that is based on the example in the AddOnFramework. The method uses e.BarsSeries.GetAsk(index) and the corresponding .GetBid. to get the current prices each update. Example, where ShowTheAskPrice merely displays the price as it updates:

    Code:
    for (int i = e.MinIndex; i <= e.MaxIndex; i++)
    if (TheBarsRequest.Instrument.FullName == e.BarsSeries.Instrument.FullName) {
    ShowTheAskPrice(e.BarsSeries.Instrument.MarketData.Ask.Price); // Works as expected
    ShowTheAskPrice(e.BarsSeries.GetAsk(i)); // Fails as described below
    }
    The first approach (using MarketData) works and provides regularly updated Ask data (and Bid if that is used instead). The second approach produces a single update only and the values never update after that. Additionally, the values for Ask and Bid (in Forex, at least) are always 0.1 pip apart, for every instrument.

    I notice that GetAsk/GetBid are not documented, although GetOpen etc used in the AddOnFramework example are documented. Am I using GetAsk/Bid correctly?

    Thanks.
    Last edited by jeronymite; 09-11-2020, 02:52 AM.

    #2
    Hello jeronymite,

    To process future updates for BarsRequest, add a method handler to the Update event.

    Below is a link to an example.
    https://ninjatrader.com/support/foru...208#post786208


    I'm finding that printing the Bars.GetAsk() is producing a value.
    https://drive.google.com/file/d/1Shu...w?usp=drivesdk


    Bars.GetAsk() and Bars.GetBid() is documented in the help guide.
    https://ninjatrader.com/support/help...nt8/getask.htm
    https://ninjatrader.com/support/help...nt8/getbid.htm
    Last edited by NinjaTrader_ChelseaB; 09-14-2020, 09:06 AM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks, Chelsea.

      Here is an extract of the code I am using:
      Code:
      internal void OnBarUpdate(object sender,BarsUpdateEventArgs e) {
      Bars TheBars = sender as Bars; Display(TheBars.GetAsk(0),TheBars.GetBid(0)); // Almost no change each update for (int i = e.MinIndex; i <= e.MaxIndex; i++) {
      if (TheBarsRequest.Instrument.FullName == e.BarsSeries.Instrument.FullName) if (e.BarsSeries.Instrument.MarketData != null && e.BarsSeries.Instrument.MarketData.Ask != null && e.BarsSeries.Instrument.MarketData.Bid != null) {
      Display(e.BarsSeries.Instrument.MarketData.Ask.Price,e.BarsSeries.Instrument.MarketData.Bid.Price); // Changes as expected Display(e.BarsSeries.GetAsk(i),e.BarsSeries.GetBid(i)); // No change each update
      }
      }
      }
      I note the following:
      • I have incorporated your approach at the start; i.e. use sender as Bars
      • I include my original approaches; i.e. using the event args BarsSeries (not the sender Bars), and taking the MarketData Ask/Bid vs the GetAsk/GetBid
      • Both uses of GetAsk/GetBid do not produce reliable update data -- they both either produce one initial update or minimal updates after the first
      • Use of the MarketData updates correctly
      • Our approaches are different (Bars vs BarsSeries), but the outcome for the use of GetAsk/GetBid is almost identical; i.e. updates are not occuring as expected
      • The Display method merely provides the data to the display engine
      • Although I have two Display invocations in my approach, I only use one or other to demonstrate the issue here, but I include both FYI.
      I have created a demonstration here: https://ln.sync.com/dl/63111b2e0#eg3...x43r9-49ffd63h It shows two identical, contemporaneous captures of data: the left is using your approach (Bars), the right is using my MarketData approach. It is obvious that the left is rarely updating, while the right is updating regularly.

      Your further investigation and advice appreciated.

      Thanks.

      Comment


        #4
        Hello jeronymite,

        Thank you for your reply.

        Chelsea is out of the office at this time, but as soon as he returns on Monday we'll review and test.

        Thanks in advance; I look forward to assisting you further.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Hello jeronymite,

          The video I have was just to show this information is available from a bars object.

          Are you adding a separate barsRequest for barsPeriod using a different MarketDataType? (one for MarketDataType.Last updates, one for .Ask updates, one for .Bid updates)
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Thanks for your kind assistance with this, Chelsea.

            I apologise if I have missed the obvious, but it wasn't apparent that one needed to submit individual BarsRequests for different MarketDataTypes. That wasn't apparent from the AddOnFramework example. Reading the documentation, I don't see where that is discussed and how to do that. Grateful if you would point to the documentation on that and any examples, please.

            Thanks.

            Comment


              #7
              Hello jeronymite,

              Below is a link to the help guide on BarsPeriod and BarsRequest.
              https://ninjatrader.com/support/help...barsperiod.htm
              https://ninjatrader.com/support/help...arsrequest.htm

              See the definition for 'BarsPeriod.MarketDataType'.

              Also, below is sample code I found through a google search of the forum.
              https://ninjatrader.com/support/foru...84#post1105384
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Thanks, Chelsea. I see.

                Questions:
                • What is the default BarsPeriod.MarketDataType if it is not explicitly set in a BarsRequest? Presumably, MarketDataType.Last?
                • Is there any benefit in submitting two BarsRequests, one for each of Ask and Bid, when a single BarsRequest (with default BarsPeriod.MarketDataType) returns relevant MarketData in the BarsSeries.Instrument? Two BarsRequests would seem to add overhead one could avoid.
                Thanks.

                Comment


                  #9
                  Hello jeronymite,

                  If no MarketDataType is specified this will default to MarketDataType.Last.

                  Two bars requests would stream two different prices at different events. One bars request would stream one set of prices with only the events from that one price type.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks, Chelsea. I understand the nature of BarsRequests in general, but it seems that a single BarsRequest provides all MarketData types via e.BarsSeries.Instrument.MarketData for every event. So, a single BarsRequest using the default MarketDataType returns data for Ask, Bid and Last via that structure. That would seem to suggest that a single BarsRequest is sufficient for all data types.

                    Is there some reason one would need to do individual BarsRequests if that is the case?

                    Thanks.

                    Comment


                      #11
                      Hello jeronymite,

                      That depends on when you want the update event to run.
                      Do you only want the update event to run when last data is received? Or do you want updates for ask and bid as well?
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Good point, Chelsea. Thanks.

                        What are the criteria for Last being updated? Is it as simple as every time either of Ask or Bid changes?

                        Thanks.

                        Comment


                          #13
                          Hello jeronymite,

                          Last means a trade occurred. The last will be at the ask or the bid.

                          Ask and bid are updated even if no trade occurred as orders are submitted and cancelled.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Thanks, Chelsea. That's helpful.

                            So, one could make the following reasoning on what to request: if one wants the absolutely current Ask/Bid, one must request those specifically. If one is "happy" to have the most recently "used" Ask/Bid, one could use Last. If the context is information only, perhaps Last is perfectly adequate. If the context is "place an order if certain conditions are met", it would be better to have the absolutely current Ask/Bid.

                            Would you agree with that approach, generally speaking?

                            Thanks.

                            Comment


                              #15
                              Hello jeronymite,

                              Yes, a bars request for ask or bid updates would update when the ask or bid changes and not just when the last changes.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by aslane, Today, 06:57 AM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_Kate  
                              Started by MisterGee, Yesterday, 09:27 PM
                              2 responses
                              18 views
                              0 likes
                              Last Post MisterGee  
                              Started by soyjesus, Today, 05:27 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post soyjesus  
                              Started by JarodB, Today, 04:44 AM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_Jason  
                              Started by mahmud999, Today, 04:54 AM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_Marco  
                              Working...
                              X