Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw.Text on the last 10 bars

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

    Draw.Text on the last 10 bars

    I am having trouble displaying text on the last 10 bars of my chart (the 10 most recent bars on my chart). Here is what I'm working with:

    Code:
    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.
    if (CurrentBar < 10)
    return;
    
    for(int i = 0 ; i <= 10 ; i++)
    {
    Draw.Text(this, "MyLabel"+High[i].ToString(), false, High[i].ToString(), i, High[i] + 2*TickSize, 0, myColor, textFont, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
    }
    }
    The intention is to display the price above the high of each bar since the most current bar, back 10 bars. But this code randomly places the prices above random bars all over the chart (I have about a couple thousands bars loaded on my chart). I only want to make it display on the 10 most recent bars (as my chart is updating live).

    #2
    Hello daigo1,

    Thank you for your reply.

    The problem is that using the High[i] value in the tag for the text drawing objects makes the tags totally unique, and you want them to be replaced instead, so you want to have the same tags for the same number of bars back each time this cycles through. You can do that by just using i in the tag rather than High[i]:

    Code:
    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.
    if (CurrentBar < 10)
    return;
    
    for(int i = 0 ; i <= 10 ; i++)
    {
    Draw.Text(this, "MyLabel"+i, false, High[i].ToString(), i, High[i] + 2*TickSize, 0, myColor, textFont, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
    }
    }
    This works well for me to just display the text on the last 10 bars.

    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Originally posted by NinjaTrader_Kate View Post
      Hello daigo1,

      Thank you for your reply.

      The problem is that using the High[i] value in the tag for the text drawing objects makes the tags totally unique, and you want them to be replaced instead, so you want to have the same tags for the same number of bars back each time this cycles through. You can do that by just using i in the tag rather than High[i]:

      Code:
      protected override void OnBarUpdate()
      {
      //Add your custom indicator logic here.
      if (CurrentBar < 10)
      return;
      
      for(int i = 0 ; i <= 10 ; i++)
      {
      Draw.Text(this, "MyLabel"+i, false, High[i].ToString(), i, High[i] + 2*TickSize, 0, myColor, textFont, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
      }
      }
      This works well for me to just display the text on the last 10 bars.

      Please let us know if we may be of further assistance to you.
      Hi Kate, I'm having an issue whenever new bars form on my chart, the prices are updating fine but are overlapping the prices with the older prices since the older prices for the past 10 bars are still there since the bars form one at a time. So the 5th bar may have 2 different prices since the unique tags are overlapping on the same 5th bar.

      Comment


        #4
        Hello daigo1,

        Thanks for your reply.

        I'm not seeing that occur with this sample script - can you test the attached indicator to see if you see the same?

        If not, can you provide a code snippet that you're currently using in your script?

        Thanks in advance; I look forward to assisting you further.
        Attached Files

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        576 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
        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