Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-Timeframe indicator drawing objects

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

    Multi-Timeframe indicator drawing objects

    Hello everyone,

    I'm developing a multi-timeframe indicator that uses an additional data series. While the indicator correctly draws objects on historical data, I'm encountering an issue when starting the indicator in real-time:


    The indicator works on a 5-minute chart with an additional 15-minute data series

    It draws dots on each 5-minute candle (first line) and separate dots on 15-minute candles (second line)

    Problem: When launching the indicator, it immediately draws a 15-minute dot without waiting for the next 15-minute candle to begin

    What I've Tried:
    - Using IsFirstTickOfBar didn't resolve the issue
    - Various approaches to synchronize the drawing with candle starts

    Question:
    What would be the proper way to prevent this premature drawing of the 15-minute objects when the indicator initializes?​

    Thank you

    #2
    Hello vitaly_p,

    Drawing tool objects are associated with the primary series only.

    You can use logic to call draw methods using data from other series, or while other series are processing, but the objects themselves are attached to the primary series.

    What BarsInProgress is the draw tool method called from?

    Are you requiring that CurrentBars[0] and CurrentBars[1] are greater than 0?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      I call them from BarsInProgress=0 (main series) and BarsInProgress=1 (secondary series) and I check the Bars Quantity before the all logical conditions. The historical data works fine, but in realtime I have a problem: when I start the indicator in the middle of a 15-minute candle (for example, at the 2nd minute), it draws objects immediately instead of waiting for the complete 15-minute candle to close.
      For example:
      If I start at 10:02 AM during an active 15-minute candle (10:00-10:15), it draws at 10:02 AM rather than waiting until 10:15 AM.

      I already check the bar count before running the logic and use IsFirstTickOfBar, but it still doesn't wait for the full candle completion in realtime. How can I make sure the objects only draw when the 15-minute candle actually closes?

      For example:
      If I start at 10:02 AM during an active 15-minute candle (10:00-10:15), it will be draw at 10:15 AM not at 10:02 AM.​​

      Comment


        #4
        Hello vitaly_p,

        If you only want to draw when the 15-minute closes, call the method when BarsInProgress is 1.

        You should be checking CurrentBars[0] and CurrentBars[1] is greater than 0.

        if (CurrentBars[0] < 1 || CurrentBars[1] < 1)
        return;

        If you wanted two wait until there are 3 15-minute bars you could compare CurrentBars[1] to be greater than 2.

        Further, may I confirm the script is running with Calculate.OnBarClose?
        If not, it would be necessary to check that IsFirstTickOfBar is true (along with CurrentBars[1] being greater than 1) and to use BarsAgo index 1 to draw the object on the previous fully closed bar.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          No, I'm using Calculate.OnEachTick and checking IsFirstTickOfBar. I understand that bars have different indexes when using OnBarClose versus OnEachTick.

          However, I don't understand why the indicator draws graphic objects BarsInProgress == 1 immediately when I place it on the chart (you can see this in my screenshot). It shouldn't display anything until the first new realtime bar appears.​
          Attached Files

          Comment


            #6
            Hello vitaly_p,

            If you only want the script to draw in real-time then ensure the logic is only evaluated if state is realtime.

            if (State != State.Realtime)
            return;
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Chelsea,

              I’m using different conditions for State.Historical and State.Realtime. The indicator correctly draws all historical objects, but when I place it on the chart, it creates unexpected additional graphic objects.

              During the transition from State.Historical to State.Realtime, the indicator seems to recalculate ALL conditions—both for BarsInProgress == 0 and BarsInProgress == 1.

              Even with if (BarsInProgress == 1 && IsFirstTickOfBar) checks, it still draws objects prematurely.

              My Theory:
              Maybe need to use State.Transition because the logic isn’t properly synchronized? Perhaps adding specific conditions for the transition phase could help, but I’m not sure how to implement this.​

              Comment


                #8
                Hello vitaly_p,

                As you are using Calculate.OnEachTick, all bars will update for every tick. The first tick of real-time is going to set IsFirstTickOfBar to true.

                Are you trying to wait for the second real-time bar?

                Declare an int variable in the scope of the class.

                In State.DataLoaded assign the variable to BarsArray[1].Count - 1.

                In OnBarUpdate when CurrentBars[1] is equal to the variable + 1, this is the second real-time bar.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you for the information about IsFirstTickOfBar. I wasn't aware it returns true on the first tick of real-time. After adding print statements for both historical and real-time bars, I discovered that those "additional objects" were actually being drawn on the last historical bar (not the first real-time bar).
                  I implemented the condition you recommended, and it resolved the issue.

                  One remaining question:
                  In Real-time, all graphic objects for BarsInProgress == 1 appear with a +1 candle displacement relative to the main data series. For example:
                  Main series: 5-minute chart
                  Secondary series: 15-minute chart
                  When a 15-minute object should be created at 9:30, it instead appears on the 9:35 candle of the 5-minute chart.

                  I expected that using IsFirstTickOfBar would align objects with the secondary series timeline. Why does this displacement occur relative to the main series?​

                  Comment


                    #10
                    Hello vitaly_p,

                    As noted in post # 2 of this thread:
                    "Drawing tool objects are associated with the primary series only."

                    When you call a drawing tool method the bars ago or date time will be in relation to the primary series.

                    If the object is drawn after BarsInProgress 0 has updated, when BarsInProgress 1 is updating, it may be associated with the new currently open bar for BarsInProgress 0.

                    Use a barsAgo index of 1 to draw it on the previous bar.

                    If you are using a DateTime, choose a date and time previous to 9:30 but after 8:55.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Thank you Chelsea!

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      558 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      324 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
                      545 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      547 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X