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

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++)[INDENT]if (TheBarsRequest.Instrument.FullName == e.BarsSeries.Instrument.FullName)
    {[/INDENT][INDENT=2]ShowTheAskPrice(e.BarsSeries.Instrument.MarketData.Ask.Price);     // Works as expected[/INDENT][INDENT=2]ShowTheAskPrice(e.BarsSeries.GetAsk(i));    // Fails as described below[/INDENT][INDENT]}[/INDENT]
    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.
    Multi-Dimensional Managed Trading
    jeronymite
    NinjaTrader Ecosystem Vendor - Mizpah Software

    #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) {[INDENT]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++)
      {[/INDENT][INDENT=2]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)
      {[/INDENT][INDENT=3]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[/INDENT][INDENT=2]}[/INDENT][INDENT]}[/INDENT]
       }
      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.
      Multi-Dimensional Managed Trading
      jeronymite
      NinjaTrader Ecosystem Vendor - Mizpah Software

      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.
            Multi-Dimensional Managed Trading
            jeronymite
            NinjaTrader Ecosystem Vendor - Mizpah Software

            Comment


              #7
              Hello jeronymite,

              Below is a link to the help guide on BarsPeriod and BarsRequest.



              See the definition for 'BarsPeriod.MarketDataType'.

              Also, below is sample code I found through a google search of the forum.
              Hi, I'm developing an add-on. Data feed is Iqfeed. I'm not subscribing to level2 data for ZL(soybeans). In the Add-on, I'm subscribing to MarketData and MarketDepth. In the add on, when using ZL(level1) I don't get level2 MarketDepth events. I understand, I'm not subscribed to a level2 feed for ZL, so no MarketDepth events.
              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.
                Multi-Dimensional Managed Trading
                jeronymite
                NinjaTrader Ecosystem Vendor - Mizpah Software

                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.
                    Multi-Dimensional Managed Trading
                    jeronymite
                    NinjaTrader Ecosystem Vendor - Mizpah Software

                    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.
                        Multi-Dimensional Managed Trading
                        jeronymite
                        NinjaTrader Ecosystem Vendor - Mizpah Software

                        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.
                            Multi-Dimensional Managed Trading
                            jeronymite
                            NinjaTrader Ecosystem Vendor - Mizpah Software

                            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 sightcareclickhere, Today, 01:55 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post sightcareclickhere  
                              Started by Mindset, 05-06-2023, 09:03 PM
                              9 responses
                              258 views
                              0 likes
                              Last Post ender_wiggum  
                              Started by Mizzouman1, Today, 07:35 AM
                              4 responses
                              18 views
                              0 likes
                              Last Post Mizzouman1  
                              Started by philmg, Today, 01:17 PM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_ChristopherJ  
                              Started by cre8able, Today, 01:01 PM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X