Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Check if second data series exists in primary

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

    Check if second data series exists in primary

    So for example, I am adding a second 1 tick data series. I want to be able to check if the index of the second dataseries falls into the current index of the primary data series. Any way to do this?

    For example is index x of second data series part of index 0 of primary dataseries

    #2
    Hello zextra,

    You can use Bars.GetBar() to get a bar index by time.

    Below is a public link to the help guide.


    This means you can compare the time of the bar of the added series you have selected and find the bar that was open during that time on the primary series.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Having some trouble putting it together. Can you provide an example? Thanks.

      Comment


        #4
        Hello zextra,

        Below is an example of using Bars.GetBar() to match a historical tick with the primary bar that was open when the tick was received.

        The code runs after the second to last primary bar has closed. The example gets the time of the tick received 1000 ticks ago. Then using the time of the tick finds the primary bar that was open when that tick was received.

        Code:
        if (CurrentBars[0] < 2 || CurrentBars[1] < 1000 || BarsInProgress != 1 || (State == State.Historical && CurrentBars[0] != Count - 3))
        	return;
        
        int primaryBarNum = BarsArray[0].GetBar(Times[1][1000]);
        
        if (primaryBarNum > CurrentBars[0])
        	Print("Tick belongs to open building bar");
        else
        	Print(string.Format("Tick within to {0}", Times[0][CurrentBars[0] - primaryBarNum] ));
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you for the code segment. I am trying to sum up the volume of the ticks from the 1 tick chart so that it equals the actual volume. I have a dataseries called myvolume that I am summing up the volume from the 1 tick chart. After doing this and printing myvolume dataseries, it does not match the actual volume dataseries. What am I doing wrong? Thank you.

          if (CurrentBars[0] < 2) return;
          if (BarsInProgress != 1) return;

          int primaryBarNum = BarsArray[0].GetBar(Times[1][0]);

          int mainBar = 0;

          if (primaryBarNum <= CurrentBars[0])
          mainBar = CurrentBars[0] - primaryBarNum;

          myvolume[mainBar] += Volumes[1][0];

          Comment


            #6
            Hello zextra,

            Thank you for your response.

            Attached is an example on how to pull the volume off the tick bars and then compare that to the primary bar series. This will ensure they match up.

            Please let me know if you have any questions.
            Attached Files

            Comment


              #7
              Thank you Patrick. I was able to get it working
              Last edited by zextra; 04-28-2018, 05:52 AM.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              574 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              332 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              101 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              553 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              551 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X