Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to identify first bar of second data series

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

    How to identify first bar of second data series

    So - I have two data series, the chart data series and a higher time frame data series, input by the user. For example, chart could be 15m and user input series could be 60m, or 500 volume and 2000 volume.

    I want to mark the chart bars that correspond to the 1st bar in the user-input data series. I have tried code in OnBarUpdate that compares Time[0] of the two data series, based on BarsInProgress - and this works for time-based periods, but not for tick or volume based periods. For tick/volume, my test works on time based historical bars, but then fails on real time bars.

    Is there a recommended method to test this?

    Edit: I'm drawing the marker via OnRender, so I am storing a flag in a series that is later referenced in OnRender.
    Last edited by john_44573; 10-28-2024, 11:31 AM.

    #2
    Hello john_44573,

    When you say first bar, do you mean of the session or just in general the first bar of the series?

    Comment


      #3
      Hi Jesse - each bar of series[0] that is a first bar of series[1].

      Comment


        #4
        Hello john_44573,

        I am not sure what that means, there is only 1 first bar per series which is bar 0. That never repeats and would never happen in realtime. Do you mean the first bar of the trading session?

        Comment


          #5
          No - for example, if we have Data Series 0 (the chart data) is 500 tick and the user-input series (series 1) is 2000 tick, I want to mark the first 500 tick bar (series 0) for each 2000 tick bar (series 1). Sorry, I hope that makes it more clear.

          Comment


            #6
            Hello john_44573,

            I believe there is some confusion with the wording here, you said the first 500 tick bar, do you just mean to mark the chart each time a 2000 tick bar closes?

            Comment


              #7
              Apologies for the wording issues. No, I want to mark the first chart bar (500 ticks) of a new 2000 tick bar. So, if a new data series (1) bar starts, mark the current data series 0 bar, or if they start concurrently (which should typically be the case) mark the data series 0 bar.

              Comment


                #8
                Hello john_44573,

                To clarify, the first 500 tick bar would be a single bar on the chart only marked a single time, that would be the first 500 tick bar once the 2000 bar closed equaling 1 single marking in historical on the chart. You mentioned realtime earlier which that would not mark anything in realtime. Do you mean to mark every 500 tick bar where the 2000 bar closed? That would be various bars throughout the chart each time a 2000 tick bar closes.

                Comment


                  #9
                  Hi Jesse - no, I want to mark every bar on the chart that is the first bar of the 2nd data series. So, in this example, it's each bar on the 500 tick chart when the 2000 tick starts a new bar. On a time chart, it would be marking the first 15m bar on an hourly chart: 12:15, 1:15, etc. I was using the Time[] parameter, and this worked for historical data (state.historical) on a tick chart, but is not consistent nor correct when the chart moves to realtime data.

                  Comment


                    #10
                    Hello john_44573,

                    You want to mark each 500 tick bar when the 2000 tick bar closes. When it starts would only be able to be done in realtime when using OnEachTick processing so for historical data that would be each time a 2000 tick bar closes. To do that you would have to use a variable and set that variable to true when the 2000 tick bar has closed to signal the next time a 500 tick bar closes to mark it.

                    Comment


                      #11
                      Originally posted by NinjaTrader_Jesse View Post
                      Hello john_44573,

                      To do that you would have to use a variable and set that variable to true when the 2000 tick bar has closed to signal the next time a 500 tick bar closes to mark it.
                      Hi Jesse - thanks for the information. I was using:
                      Code:
                      if (BarsInProgress == 1) // user input data series
                      {
                      if (IsFirstTickOfBar)
                           //set flag
                      To look for the new bar. What condition tells me that the 2000 tick bar has closed?

                      Comment


                        #12
                        Hello john_44573,

                        That would be what I had explained so that looks right. The set flag part could be a bool variable being set to true, then in BarsInProgress 0 you would mark the chart if that bool is true and set it back to false.

                        IsFirstTickOfBar is true on all bars for historical because that is just an OnBarClose event so that logic would work for both historical and realtime. You will see it differ in realtime because the first tick of bar will be true only on the first tick of a bar, the rest of the ticks of that bar it will be false so it would be at the beginning of the bar instead.

                        The first tick of the bar is also the tick that closed the last bar so potentially you just need to adjust the drawing to be 1 bars ago, that would then match the historical drawings OnBarClose, you would be drawing on the last closed bar.

                        Comment


                          #13
                          Ok, thanks, that's a modification to my prior approach.

                          Let me make some changes and see if this solves my issue, or I can let you know more specifically what I can see is not operating as expected.

                          Comment


                            #14
                            Originally posted by NinjaTrader_Jesse View Post
                            Hello john_44573,

                            That would be what I had explained so that looks right. The set flag part could be a bool variable being set to true, then in BarsInProgress 0 you would mark the chart if that bool is true and set it back to false.

                            IsFirstTickOfBar is true on all bars for historical because that is just an OnBarClose event so that logic would work for both historical and realtime. You will see it differ in realtime because the first tick of bar will be true only on the first tick of a bar, the rest of the ticks of that bar it will be false so it would be at the beginning of the bar instead.

                            The first tick of the bar is also the tick that closed the last bar so potentially you just need to adjust the drawing to be 1 bars ago, that would then match the historical drawings OnBarClose, you would be drawing on the last closed bar.
                            Hi Jesse - I appear to be encounting two problems: (1) when state changes to realtime, "IsFirstTickOfBar" becomes true again, and
                            Code:
                            if (BarsInProgress == 1) // HTF bar
                            {
                            if (IsFirstTickOfBar)
                                  //set flag to true
                            reexecutes, even though it's not the first tick of the series 1 bar, and (2) BarsInProgress appears to execute for series 0 before series 1, so when the series 1 flag is set to true, it doesn't execute until the second series 0 bar.

                            Any suggestions to address these issues?
                            Last edited by john_44573; 10-31-2024, 06:48 AM.

                            Comment


                              #15
                              Hello john_44573,

                              When entering realtime and using OnEachTick the first realtime tick is going to be the first tick of the bar that gets processed.

                              For the secondary series processing, that would be correct. You will see your primary process first and then the secondary series when using the same instrument. You would have to use 1 bars ago values for drawing purposes because of the order of processing in that use case.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              601 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              347 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              103 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              559 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              558 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X