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 to get Ask/Bid for historical bars

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

    #16
    Hi Joydeep! I'm sorry to bring up this old thread, but I am having trouble with something that is related to this. I have been using the Add() method you suggested to add a bar series for the Ask price, used for currency markets. However, I just noticed that when this series is added, the FirstTickOfBar internal logic gets really messed up! Here is the code:


    Code:
    protected override void Initialize()
            {
    //            if (Instrument.MasterInstrument.InstrumentType == InstrumentType.Currency) Add(Instrument.FullName.ToString(), BarsPeriod.Id, BarsPeriod.Value, MarketDataType.Ask);
                Add(Instrument.FullName.ToString(), BarsPeriod.Id, BarsPeriod.Value, MarketDataType.Ask);
                CalculateOnBarClose = false;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                if (BarsInProgress != 0) return;  // Only process the primary bars on the chart.  The secondary dataseries is just for reference in the code.
                if (FirstTickOfBar)
                     Print("Bar:" + CurrentBar + " (Tick:" + Bars.TickCount.ToString() + "), Bar Series:  " + BarsInProgress + ", FirstTickOfBar = " + FirstTickOfBar);
             }

    Here is the output from a test strategy:

    Bar:30382 (Tick:19), Bar Series: 0, FirstTickOfBar = True
    Bar:30383 (Tick:19), Bar Series: 0, FirstTickOfBar = True
    Bar:30383 (Tick:18), Bar Series: 0, FirstTickOfBar = True
    Bar:30384 (Tick:18), Bar Series: 0, FirstTickOfBar = True
    Bar:30384 (Tick:23), Bar Series: 0, FirstTickOfBar = True
    Bar:30384 (Tick:3), Bar Series: 0, FirstTickOfBar = True
    Bar:30385 (Tick:3), Bar Series: 0, FirstTickOfBar = True
    Bar:30385 (Tick:5), Bar Series: 0, FirstTickOfBar = True
    Bar:30385 (Tick:1), Bar Series: 0, FirstTickOfBar = True
    Bar:30386 (Tick:1), Bar Series: 0, FirstTickOfBar = True
    Bar:30386 (Tick:4), Bar Series: 0, FirstTickOfBar = True
    Bar:30386 (Tick:12), Bar Series: 0, FirstTickOfBar = True
    Bar:30386 (Tick:14), Bar Series: 0, FirstTickOfBar = True
    Bar:30386 (Tick:10), Bar Series: 0, FirstTickOfBar = True
    Bar:30387 (Tick:10), Bar Series: 0, FirstTickOfBar = True
    Bar:30388 (Tick:10), Bar Series: 0, FirstTickOfBar = True
    Bar:30388 (Tick:2), Bar Series: 0, FirstTickOfBar = True
    Bar:30389 (Tick:2), Bar Series: 0, FirstTickOfBar = True
    Bar:30389 (Tick:5), Bar Series: 0, FirstTickOfBar = True

    I have attached an example strategy you can run to show what's happening. Put it on a new 1 minute chart. I used both ES and $EURUSD and they both produced this result.

    1) Why is FirstTickOfBar not true on the first tick of the bar?
    2) Why is FirstTickOfBar true for more than one tick in the same bar?

    Thanks!
    Bryan
    Attached Files
    cassb
    NinjaTrader Ecosystem Vendor - Logical Forex

    Comment


      #17
      Hello Bryan,
      Unfortunately I am not able to replicate it. When I try the toy code I could get the correct prints. Can you please let me know the exact steps to replicate it.

      I look forward to assisting you further.
      JoydeepNinjaTrader Customer Service

      Comment


        #18
        Originally posted by NinjaTrader_Joydeep View Post
        Hello Bryan,
        Unfortunately I am not able to replicate it. When I try the toy code I could get the correct prints. Can you please let me know the exact steps to replicate it.

        I look forward to assisting you further.
        Yes, thank you. I just reproduced it again. This is what I did:

        1) Start up Ninjatrader. I have v7.0.1000.11 (Multi-Broker Live).
        2) Download replay data for the ES 12-12 instrument for 11/5/2012.
        3) Connect to the Market Replay Connection and set replay to start at 11/5/2012.
        4) Open a new chart for ES 12-12, 1 min. bars.
        5) Put the Test strategy on the chart and enable it. Click OK.
        6) Open the Output Window.
        7) Click on the "Play" button for Market Replay.
        8) Observe the Output Window:

        Bar:5370 (Tick:1), Bar Series: 0, FirstTickOfBar = True
        Bar:5370 (Tick:6), Bar Series: 0, FirstTickOfBar = True
        Bar:5370 (Tick:13), Bar Series: 0, FirstTickOfBar = True
        Bar:5371 (Tick:13), Bar Series: 0, FirstTickOfBar = True
        Bar:5371 (Tick:17), Bar Series: 0, FirstTickOfBar = True
        Bar:5372 (Tick:20), Bar Series: 0, FirstTickOfBar = True
        Bar:5372 (Tick:23), Bar Series: 0, FirstTickOfBar = True
        Bar:5372 (Tick:30), Bar Series: 0, FirstTickOfBar = True
        Bar:5372 (Tick:34), Bar Series: 0, FirstTickOfBar = True
        Bar:5372 (Tick:37), Bar Series: 0, FirstTickOfBar = True
        Bar:5372 (Tick:42), Bar Series: 0, FirstTickOfBar = True
        Bar:5372 (Tick:44), Bar Series: 0, FirstTickOfBar = True
        Bar:5373 (Tick:1), Bar Series: 0, FirstTickOfBar = True
        Bar:5373 (Tick:4), Bar Series: 0, FirstTickOfBar = True
        Bar:5373 (Tick:6), Bar Series: 0, FirstTickOfBar = True
        Bar:5374 (Tick:1), Bar Series: 0, FirstTickOfBar = True
        Bar:5375 (Tick:1), Bar Series: 0, FirstTickOfBar = True
        Bar:5375 (Tick:3), Bar Series: 0, FirstTickOfBar = True
        Bar:5375 (Tick:6), Bar Series: 0, FirstTickOfBar = True
        Bar:5375 (Tick:10), Bar Series: 0, FirstTickOfBar = True
        Bar:5375 (Tick:13), Bar Series: 0, FirstTickOfBar = True
        Bar:5375 (Tick:22), Bar Series: 0, FirstTickOfBar = True
        Bar:5376 (Tick:1), Bar Series: 0, FirstTickOfBar = True
        Bar:5376 (Tick:11), Bar Series: 0, FirstTickOfBar = True
        Bar:5376 (Tick:23), Bar Series: 0, FirstTickOfBar = True
        Bar:5376 (Tick:25), Bar Series: 0, FirstTickOfBar = True
        Bar:5377 (Tick:1), Bar Series: 0, FirstTickOfBar = True
        Bar:5378 (Tick:7), Bar Series: 0, FirstTickOfBar = True
        Bar:5378 (Tick:16), Bar Series: 0, FirstTickOfBar = True
        Bar:5378 (Tick:19), Bar Series: 0, FirstTickOfBar = True
        Bar:5378 (Tick:21), Bar Series: 0, FirstTickOfBar = True
        Bar:5378 (Tick:23), Bar Series: 0, FirstTickOfBar = True
        Bar:5378 (Tick:25), Bar Series: 0, FirstTickOfBar = True
        Bar:5378 (Tick:29), Bar Series: 0, FirstTickOfBar = True
        Bar:5378 (Tick:36), Bar Series: 0, FirstTickOfBar = True
        Bar:5378 (Tick:39), Bar Series: 0, FirstTickOfBar = True
        Bar:5378 (Tick:45), Bar Series: 0, FirstTickOfBar = True
        Bar:5378 (Tick:54), Bar Series: 0, FirstTickOfBar = True
        Bar:5378 (Tick:58), Bar Series: 0, FirstTickOfBar = True
        Bar:5379 (Tick:3), Bar Series: 0, FirstTickOfBar = True
        Bar:5379 (Tick:6), Bar Series: 0, FirstTickOfBar = True
        Bar:5380 (Tick:3), Bar Series: 0, FirstTickOfBar = True
        Bar:5380 (Tick:14), Bar Series: 0, FirstTickOfBar = True
        Bar:5380 (Tick:18), Bar Series: 0, FirstTickOfBar = True
        Bar:5381 (Tick:1), Bar Series: 0, FirstTickOfBar = True
        Bar:5382 (Tick:2), Bar Series: 0, FirstTickOfBar = True
        Bar:5382 (Tick:5), Bar Series: 0, FirstTickOfBar = True
        Bar:5382 (Tick:8), Bar Series: 0, FirstTickOfBar = True
        Bar:5382 (Tick:16), Bar Series: 0, FirstTickOfBar = True
        Bar:5382 (Tick:19), Bar Series: 0, FirstTickOfBar = True
        Bar:5382 (Tick:22), Bar Series: 0, FirstTickOfBar = True
        Bar:5382 (Tick:24), Bar Series: 0, FirstTickOfBar = True
        Bar:5383 (Tick:1), Bar Series: 0, FirstTickOfBar = True
        Bar:5383 (Tick:7), Bar Series: 0, FirstTickOfBar = True
        Bar:5383 (Tick:9), Bar Series: 0, FirstTickOfBar = True
        Bar:5383 (Tick:15), Bar Series: 0, FirstTickOfBar = True
        cassb
        NinjaTrader Ecosystem Vendor - Logical Forex

        Comment


          #19
          Hello Bryan,
          Thanks for the detailed instructions.

          I can replicate it at my end and have send it to development for review.

          Thanks for your patience.
          JoydeepNinjaTrader Customer Service

          Comment


            #20
            Originally posted by NinjaTrader_Joydeep View Post
            Hello Bryan,
            Thanks for the detailed instructions.

            I can replicate it at my end and have send it to development for review.

            Thanks for your patience.
            OK very good, thank you!
            cassb
            NinjaTrader Ecosystem Vendor - Logical Forex

            Comment


              #21
              Hello Bryan,
              Development has confirmed it was working not as expected and is scheduled for resolution in our next major release. Unfortunately we do not have a release date at this time for next major release.
              JoydeepNinjaTrader Customer Service

              Comment


                #22
                Originally posted by NinjaTrader_Joydeep View Post
                Hello Bryan,
                Development has confirmed it was working not as expected and is scheduled for resolution in our next major release. Unfortunately we do not have a release date at this time for next major release.

                OK, thank you! Can you tell me -- is the problem only when you add the new bar series with Ask prices? It seems when I remove that ADD() line in Initialize, it works OK.

                Is there a way to make this work until Development fixes it?
                cassb
                NinjaTrader Ecosystem Vendor - Logical Forex

                Comment


                  #23
                  Hello Bryan,
                  Yes, it relates to bid/ask data only. I suppose its how NinjaTrader appends the bid/ask data.

                  Any workable alternatives would depend on what you are trying to do. If you are only want to access the Bid Ask data, then you can use the GetCurrentBid/Ask fucntion. You can also create your own data series and construct the bid/ask data series (for realtime quotes only).
                  JoydeepNinjaTrader Customer Service

                  Comment


                    #24
                    Originally posted by NinjaTrader_Joydeep View Post
                    You can also create your own data series and construct the bid/ask data series (for realtime quotes only).

                    Isn't that what I am doing with this line?

                    Add(Instrument.FullName.ToString(), BarsPeriod.Id, BarsPeriod.Value, MarketDataType.Ask);
                    cassb
                    NinjaTrader Ecosystem Vendor - Logical Forex

                    Comment


                      #25
                      Hello Bryan,
                      Yes, you are. However Bid/Ask data series are not constructed the way last or any data series are referenced. For example, Bid/ask series are build only if there is a corresponding last series. These internal logic's makes it different from the normal logic.
                      JoydeepNinjaTrader Customer Service

                      Comment


                        #26
                        What would it be a solution just to build an independet Bid series then?

                        Thanks

                        Comment


                          #27
                          You can use GetCurrentBid() to get the current bid but for historical Bid/Ask please see the following: http://www.ninjatrader.com/support/h..._ask_serie.htm

                          Let me know if I can be of further assistance.
                          LanceNinjaTrader Customer Service

                          Comment


                            #28
                            I appreciate your help Lance, yes this is ok for calling Bid real-time, but it doesn't still answer my question: How can I build an independent Bid,Ask series? Cause I´ve read from this forum, that your Bid-Ask series build as it Last trade occurs, so it sounds uncomplete, cause many Bid-Ask events occur without any "Trade" occuring.

                            What I want is to build a complete and independet Bid-Ask serie.

                            If I have just a Bid series chart for any instrument, the database will build as it comes from the exchange or depending on Last trade ?

                            Thanks

                            Comment


                              #29
                              You would have to build this using MarketDataType.Bid if your provider supports it.
                              Here are the MarketDataTypes


                              Also see: http://www.ninjatrader.com/support/h...marketdata.htm

                              Let me know if I can be of further assistance.
                              LanceNinjaTrader Customer Service

                              Comment


                                #30
                                Hi Lance, this is a useful info whenever you´re ready for real time.

                                Maybe I´m misscommunicating what I meant. What I want to know is how can I build independent Bid-Ask series in my historical database, and not just a Bid-Ask series related to Last trades. Apparently NT updates its database from your data provider as it comes from the exchange in three series: Bid-Ask-Last. I thought that this was the normal way, BUT The problem is that I´ve read that Bid-Ask series build whenever a Last trade occurs. As you know too many Bid-Ask events occur without any last trade.

                                This was what I read from a support team member:

                                "However Bid/Ask data series are not constructed the way last or any data series are referenced. For example, Bid/ask series are build only if there is a corresponding last series. These internal logic's makes it different from the normal logic."

                                So, can you guarantee that this is not true, and NT build a real independent Bid-Ask-Last series?

                                I´m looking forward for your answer

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by rhyminkevin, Today, 04:58 PM
                                3 responses
                                48 views
                                0 likes
                                Last Post Anfedport  
                                Started by iceman2018, Today, 05:07 PM
                                0 responses
                                5 views
                                0 likes
                                Last Post iceman2018  
                                Started by lightsun47, Today, 03:51 PM
                                0 responses
                                7 views
                                0 likes
                                Last Post lightsun47  
                                Started by 00nevest, Today, 02:27 PM
                                1 response
                                14 views
                                0 likes
                                Last Post 00nevest  
                                Started by futtrader, 04-21-2024, 01:50 AM
                                4 responses
                                50 views
                                0 likes
                                Last Post futtrader  
                                Working...
                                X