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

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

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by jclose, Today, 09:37 PM
    0 responses
    4 views
    0 likes
    Last Post jclose
    by jclose
     
    Started by WeyldFalcon, 08-07-2020, 06:13 AM
    10 responses
    1,413 views
    0 likes
    Last Post Traderontheroad  
    Started by firefoxforum12, Today, 08:53 PM
    0 responses
    10 views
    0 likes
    Last Post firefoxforum12  
    Started by stafe, Today, 08:34 PM
    0 responses
    10 views
    0 likes
    Last Post stafe
    by stafe
     
    Started by sastrades, 01-31-2024, 10:19 PM
    11 responses
    169 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Working...
    X