Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Tagging bars based on a condition

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

    Tagging bars based on a condition

    Hi all,
    I appreciate your help.
    I am trying to tag the bars on the chart based on a condition. I wrote this but it works only on the first bar that achieve the condition; not all. Would you please help where is the mistake?
    Thank you.

    protected override void OnBarUpdate()
    {
    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = Bars.BarsSeries.BarsType as
    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;
    NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New", 12) { Size = 20, Bold = true };

    if (barsType == null)
    return;

    int count=1;

    if (CurrentBar < Count-2)

    for(count = 1; count < Count-1; count++)
    {

    if (Bars.GetClose(Count-(count+1)) > (Bars.GetHigh(Count-count)+Bars.GetLow(Count-count))/2)
    Draw.Text(this, "tag1", false, "*", Bars.GetTime(Count-(count+1)), Bars.GetHigh(Count-(count+1)), 10, Brushes.Blue, myFont, TextAlignment.Center, Brushes.Transparent, null, 1);

    }

    }

    #2
    Hello MSerag,

    Thank you for your post.

    I think your main issue here is that you're not making the tag for the drawing objects unique, so instead of having multiple different objects, you just have a single object being redrawn on different bars so you only see the final time it's drawn. Try making the objects unique by using count in the tag name:

    Code:
     protected override void OnBarUpdate()
    {
    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = Bars.BarsSeries.BarsType as
    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;
    NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New", 12) { Size = 20, Bold = true };
    
    if (barsType == null)
    return;
    
    int count=1;
    
    if (CurrentBar < Count-2)
    {
    for(count = 1; count < Count-1; count++)
    {
    
    if (Bars.GetClose(Count-(count+1)) > (Bars.GetHigh(Count-count)+Bars.GetLow(Count-count))/2)
    Draw.Text(this, [B]"tag1" + count[/B], false, "*", Bars.GetTime(Count-(count+1)), Bars.GetHigh(Count-(count+1)), 10, Brushes.Blue, myFont, TextAlignment.Center, Brushes.Transparent, null, 1);
    
    }
    }
    
    }
    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Appreciation Kate for pointing out the mistake.
      However, the text "*" now appears at the correct X value which is Bars.GetTime(Count-(count+1)) but at a wrong, fixed Y value at the lower end of the chart. I suppose that it should appear at Bars.GetHigh(Count-(count+1)) of each bar. Would you please help on how to resolve this?
      Thanks again.

      Comment


        #4
        Hello MSerag,

        Thank you for your reply.

        Can you provide a screenshot of what you're seeing as far as the asterisk being plotted at a wrong Y value? Here's what I'm seeing on the chart, which is what I'd expect to see - the asterisk plotted at a 10 pixel offset from the bar high:

        Click image for larger version

Name:	2022-02-22_09-51-36.png
Views:	138
Size:	131.9 KB
ID:	1191086

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

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        57 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        78 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        39 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        101 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        61 views
        0 likes
        Last Post PaulMohn  
        Working...
        X