Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

DrawnOnBar for Draw.VerticalLine

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

    DrawnOnBar for Draw.VerticalLine

    Hi Guys,

    how can I use the ChartAnchor Propertie DrawOnBar for a Draw.VerticalLine like the example in the NT HelpGuide?




    Text myText;
    protected override void OnBarUpdate()
    {
    if(CurrentBar == 50)
    myText = Draw.Text(this, "tag", "test", 0, High[0]);

    if(myText != null)
    {
    Print(myText.Anchor.DrawnOnBar); // drawn on bar 50
    }

    }

    Thanks for your support

    #2
    Hello Martin89,

    Thank you for your post.

    VerticalLine has a StartAnchor and an EndAnchor, both of which would be on the same bar. Here's an example of printing the bar a line is drawn on - this indicator will draw a line every 5 bars and print the bar number the line was printed on:

    Code:
     public class ExampleDrawnOnBarVertLine : Indicator
    {
    private int NextBar;
    private VerticalLine MyLine;
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "ExampleDrawnOnBarVertLine";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    }
    else if (State == State.Configure)
    {
    }
    }
    
    protected override void OnBarUpdate()
    {
    if (CurrentBar == 0)
    {
    NextBar = 4;
    }
    if (CurrentBar == NextBar)
    {
    MyLine = Draw.VerticalLine(this, "myLine" + CurrentBar,0, Brushes.Gold);
    Print("Line Drawn on " + MyLine.StartAnchor.DrawnOnBar);
    
    NextBar += 5;
    }
    }
    }
    Please let us know if we may be of further assistance to you.

    Comment

    Latest Posts

    Collapse

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