Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw.Text to place label based on primary data not secondary data position

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

    Draw.Text to place label based on primary data not secondary data position

    Hi,
    I have AddDataSeries to the primary series and need to Draw.Text from the secondary data on the primary chart. Howver, when I use the 'CurrentBar' or 0, Draw.Text places the label corresponding to the secondary data location. How do I force or make Draw.Text place the label relative to the primary data?

    #2
    Try to use Closes[0][0] instead of Close[0]

    Comment


      #3
      Hello kashter,

      Thanks for your post.

      Each data series will have its own CurrentBar. Each data series will call the OnBarUpdate() and will switch references such as Close[0] to point to the data series that called OnBarUpdate(). As forum member muratb35 pointed out Closes[0][0] is the current bar value of the primary (chart) dataseries. Closes[1][0] would be the current bar value of the 1st added data series. In a multi series script you use plurals of the price followed by the barsarrayindex and then the bar index, so for example Highs[2][1] would be the previous bar [1] from the [2]nd added data series

      I suspect you want to segment your code so that it only draws when the chart bars call OnBarUpdate(). You can do this by check the value of BarsInProgress. BarsInProgress will be equal to 0 when the chart bars call OnBarUpdate and will be one when the first added data series calls OnBarUpdate().

      You can segment like this:

      if(BarsInProgress == 0)
      {
      // do something
      }

      I highly recommend that you review this section of the help guide to gain a better and complete understanding of Multi time frame/series coding: https://ninjatrader.com/support/help...nstruments.htm

      Comment


        #4
        Hi Paul,
        Thanks for your informative and I did use the reference you mention to come up with the separate data. Maybe my original post was not clear, I have the data from the first added data series which is prior session high (Highes[1][0]). The issue is how to use Draw.Text to place a label on the primary's CurrentBar position? I tried CurrentBars[1] but the doesn't put the label at the right most candle.

        Comment


          #5
          Hello kashter,

          Thanks for your reply.

          What specific text are you trying to draw and what price level are you trying to draw it at on the current bar of the chart?

          Comment


            #6
            Paul,
            I got the right prior session high (checked on print) and level plots on the chart. I want to place a label at the right most candle (CurrentBar). I am using this;
            Code:
            Draw.Text(this, "H[1]", "H[1]", 0, Highs[1][0], Brushes.Firebrick);
            But places the label on the first data series added (at the end of the prior session). I need it on the present session 'CurrentBar'.

            Comment


              #7
              Hello kashter,

              Thanks for your reply.

              Try this:

              if (BarsInProgress == 0)
              {
              Draw.Text(this, "H[1]", "H[1]", 0, Highs[1][0], Brushes.Firebrick);
              }

              Comment


                #8
                Paul,
                Using the BarsInProgress does not plot the label at all.
                Last edited by kashter; 08-23-2021, 08:54 AM. Reason: Missed the BarsInProgress

                Comment


                  #9
                  Hello Kashter,

                  Thanks for your reply.

                  I meant to write it as if (your existing conditions to draw && BarsInProgress == 0)

                  Please change, recompile, then make sure you remove the indicator from the chart after compiling and then reapply the indicator to ensure you are working with the recent changes.

                  If that does not resolve the issue, please post a screenshot of what the chart looks like and the code section that draws the text

                  Comment


                    #10
                    Paul,
                    Here is the snippet

                    Code:
                    if (BarsInProgress == 1)// && CurrentBars[1] > 0)
                    {
                    ClearOutputWindow();
                    Print(string.Format("CurrentBar1 {0} \nOpen[1] {1} \nHigh[1] {2} \nLow[1] {3} \nClose[1] {4} ", CurrentBar, Opens[1][0], Highs[1][0], Lows[1][0], Closes[1][0]));
                    
                    
                    // extend the larger time frame for each primary bar so there are consecutive bars set so we can see it on the chart
                    if (!Values[1].IsValidDataPoint(0))
                    Values[0][0] = Highs[1][0];
                    Values[1][0] = Lows[1][0];
                    Values[2][0] = Closes[1][0];
                    
                    Draw.Text(this, "H[1]", "H[1] " + Highs[1][0].ToString(), 0, Highs[1][0], Brushes.Firebrick);
                    Draw.Text(this, "L[1]", "L[1] " + Lows[1][0].ToString(), 0, Lows[1][0], Brushes.Snow);
                    Draw.Text(this, "C[1]", "C[1] " + Closes[1][0].ToString(), 0, Closes[1][0], Brushes.LimeGreen);

                    Comment


                      #11
                      Hello Kashter,

                      Thanks for your reply.

                      You would need to draw only when the chart bars plot, BasrinProgress == 0.

                      Please post a screenshot of your chart that shows the output on the chart.

                      Comment


                        #12
                        Chart attached

                        Comment


                          #13
                          Hello kashter,

                          Thanks for your reply.

                          With reference to the screenshot you posted, can you clarify where you want the text to appear?

                          Comment


                            #14
                            Hi Paul,
                            I hope the attached image is clear. Thank you.

                            Comment


                              #15
                              Hello kashter,

                              Thanks for your reply.

                              You would need to run the Draw.Text statements when the chart bars call the OnbarUpdate() which is BarsInProgress 0. This will put the text at the current bar on the chart instead of the current bar of the added data series.


                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              579 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              334 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
                              554 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