Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Kate W.NinjaTrader Customer Service

    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:	104
Size:	131.9 KB
ID:	1191086

        Thanks in advance; I look forward to assisting you further.
        Kate W.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by rayyyu12, Today, 12:47 AM
        0 responses
        2 views
        0 likes
        Last Post rayyyu12  
        Started by ETFVoyageur, 05-07-2024, 07:05 PM
        17 responses
        133 views
        0 likes
        Last Post ETFVoyageur  
        Started by ETFVoyageur, Yesterday, 10:13 PM
        1 response
        8 views
        0 likes
        Last Post ETFVoyageur  
        Started by somethingcomplex, Yesterday, 10:36 PM
        0 responses
        9 views
        0 likes
        Last Post somethingcomplex  
        Started by sofortune, 05-10-2024, 10:28 AM
        5 responses
        22 views
        0 likes
        Last Post sofortune  
        Working...
        X