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 Aviram Y, Today, 05:29 AM
    0 responses
    1 view
    0 likes
    Last Post Aviram Y  
    Started by quantismo, 04-17-2024, 05:13 PM
    3 responses
    25 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by ScottWalsh, 04-16-2024, 04:29 PM
    7 responses
    34 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by cls71, Today, 04:45 AM
    0 responses
    6 views
    0 likes
    Last Post cls71
    by cls71
     
    Started by mjairg, 07-20-2023, 11:57 PM
    3 responses
    216 views
    1 like
    Last Post PaulMohn  
    Working...
    X