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

Bid/Ask/Last Tick DataSeries Count

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

    Bid/Ask/Last Tick DataSeries Count

    If I create 3 Tick DataSeries as in the following code snippet, why would the count of the number of Closes in each series be different?

    Initialize():
    Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Last); //idx 1
    Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Bid); //idx 2
    Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Ask); //idx 3

    OnStartUp() or OnBarUpdate():
    Print("Closes[1].Count: "+Closes[1].Count+" Closes[2].Count: "+Closes[2].Count+" Closes[3].Count: "+Closes[3].Count);

    reports:

    Closes[1].Count: 331443 Closes[2].Count: 625472 Closes[3].Count: 610226

    What am I missing?

    #2
    CriticalTrader,

    The bid, ask and last prices are all updated individually essentially. This is expected behavior. The bid price can change when the ask doesn't, and the last price is basically the "last traded price".
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      So how can I determine the size of the last trade as being on the bid or ask price if the Times are all identical? Is this also the case with the realtime OnMarketData MarketDataEventArgs data?

      Comment


        #4
        CriticalTrader,

        OnMarketData is guaranteed to be called in sequence of how Bid/Ask/Last are received from your data provider.



        You could see if you have a bid or ask before a last for example in this case by keeping track of what MarketDataType the previous update was.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Okay, but I'm attempting to create a historical view of the bid/ask volume and it seems quite problematic.
          DataSeries doesn't even make sense to me. For instance, with the 3 DataSeries as in my initial post I have this snippet

          in OnBarUpdate():

          if (BarsInProgress == 1)
          {
          int i = 0;
          if (CurrentBar == 1)
          Print("OnBarUpdate 1: CurrentBar = "+CurrentBar+" Time[0] = " + Time[0] + " Close[0] = " + Close[0] + " Times[2].Count = " + Times[2].Count);
          while
          (CurrentBar == 1 && i < Times[2].Count && Time[0] == Times[2][i])
          {
          Print("OnBarUpdate LOOP: Times[2]["+i+"] =" + Times[2][i] + " Closes[2]["+i+"] = "+Closes[2][i]+ " Volumes[2]["+i+"] = "+Volumes[2][i]);
          i++;
          Print ("OnBarUpdate LOOP: i = "+i);
          }
          }

          Generates following output. Notice the Error when i=2, well below Count.

          OnBarUpdate BEORE LOOP: CurrentBar = 1 Time[0] = 6/24/2012 6:00:00 PM Close[0] = 1325.5 Times[2].Count = 2817
          OnBarUpdate IN LOOP: Times[2][0] =6/24/2012 6:00:00 PM Closes[2][0] = 1325.5 Volumes[2][0] = 229
          OnBarUpdate IN LOOP: i = 1
          OnBarUpdate IN LOOP: Times[2][1] =6/24/2012 6:00:00 PM Closes[2][1] = 1325.5 Volumes[2][1] = 232
          OnBarUpdate IN LOOP: i = 2
          Error on calling 'OnBarUpdate' method for indicator 'CDA_VolumeProfile_v232' on bar 1: Bar index needs to be greater/equal 0

          Comment


            #6
            CriticalTrader,

            DataSeries are like the data structure known as lists. They get an element added as its available from the data provider. Each one of the data series in a multi-series script isn't guaranteed to have the same number of elements. It helps to download the historical data for example in another chart to increase the availability of second or third added data series, etc.

            Ticks come in asynchronously in time. There is no way to guaranteed one tick will have the same exact time stamp as another tick because these come in sporadically based on when the price changes. The price doesn't change in set time intervals because people trading don't place orders at set time intervals. There may be 100 ticks one minute, and only 10 the next depending on how many people are participating in the market.
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              Thanks AdamP. I understand now why the data series wouldn't have same number of elements.
              I also understand the data in the bid/ask/tick are stored as they arrive asynchronously.

              But I'm not sure your response actually answers my question. My only point in the last example is that if the Close[2] data series has 625472 elements, then why would selecting Closes[2][2] result in an error? Is it because I'm accessing that element within the BarsInProgress==1 and CurrentBar==1 event and Closes[2][2] may not have arrived yet, even though this is historical data and not realtime data?

              Comment


                #8
                CriticalTrader,

                Basically, indicators/strategies will start at the most-historical bar, then iterate forward through historical data until it reaches the most current bar. When you are on this "most-historical" bar there won't exist a bar before it, so it causes the error. You can check for CurrentBars[X] > 1 for example and it should work.
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  A light just went off and I now realize my mistake in thinking. I was forgetting the Closes[2][2] wasn't accessing the third sequential element in series 2, but rather the element that was 2 bars ago! Unbelievable. Thanks for your patience Adam.

                  Comment


                    #10
                    CriticalTrader,

                    No problem, we're happy to help.

                    Yes, these dataseries act like lists with any new element being added getting assigned an index of 0, and all other element's indexes get increased by 1.
                    Adam P.NinjaTrader Customer Service

                    Comment


                      #11
                      Display the Last Price

                      Hello.

                      I want to display the last price on the chart. What is the proper syntax for the following?

                      DrawHorizontalLine("Last Price",false,???,LineColor,HorizLineStyle,line_siz e);

                      What should I replace ??? with to display the last traded price?

                      Comment


                        #12
                        rcsingleton, that would be simply Close[0] with CalculateOnBarClose set to false for your indicator / script.
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          That's what I originally had and it wasn't working, so I thought there was a different syntax. I see two things now.

                          One, the "CalculateOnBarClose = false;" statement was not the final statement in the protected override void Initialize().

                          Two. Because of that, I see that CalculateOnBarClose = true was applied when the indicator was put on the chart.

                          I've got it now. Thanks.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by rocketman7, Today, 09:41 AM
                          3 responses
                          7 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Started by traderqz, Today, 09:44 AM
                          2 responses
                          4 views
                          0 likes
                          Last Post NinjaTrader_Gaby  
                          Started by stafe, 04-15-2024, 08:34 PM
                          8 responses
                          40 views
                          0 likes
                          Last Post stafe
                          by stafe
                           
                          Started by rocketman7, Today, 02:12 AM
                          7 responses
                          31 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by guillembm, Yesterday, 11:25 AM
                          3 responses
                          16 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Working...
                          X