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

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 kempotrader, Today, 08:56 AM
              0 responses
              7 views
              0 likes
              Last Post kempotrader  
              Started by kempotrader, Today, 08:54 AM
              0 responses
              4 views
              0 likes
              Last Post kempotrader  
              Started by mmenigma, Today, 08:54 AM
              0 responses
              2 views
              0 likes
              Last Post mmenigma  
              Started by halgo_boulder, Today, 08:44 AM
              0 responses
              2 views
              0 likes
              Last Post halgo_boulder  
              Started by drewski1980, Today, 08:24 AM
              0 responses
              4 views
              0 likes
              Last Post drewski1980  
              Working...
              X