Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Updating Line.EndAnchor as bars close

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

    Updating Line.EndAnchor as bars close

    I am wondering if it is possible to update a Line drawing objects endanchor position as bars close on the chart.

    That is to say that the line is drawn at a certain time with a start point and a begging point. As the chart data progresses and bars close up or down I would like to update the bar to the new bar position of the most recently closed bar while maintaining the startanchor's starting bar location.

    This used to be accomplished by calling EndBarsAgo in NT7, what is it in NT8?

    #2
    Hi WHICKED, thanks for your question.

    All draw objects have anchors that can be changed e.g.

    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class TestLine : Indicator
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    //...
                }
            }
    
            bool flipswitch = false;
            NinjaTrader.NinjaScript.DrawingTools.Line MyLine;
            protected override void OnBarUpdate()
            {
                if(State == State.Historical) return;
    
                if(!flipswitch)
                {
                    MyLine = Draw.Line(this, "MyLine", 10, High[10], 0, High[0], Brushes.Red);
                    flipswitch = true;
                }
                else
                {
                    if (DrawObjects["MyLine"] != null && DrawObjects["MyLine"] is DrawingTools.Line)
                      {
                        var x = DrawObjects["MyLine"] as NinjaTrader.NinjaScript.DrawingTools.Line;
                        x.EndAnchor.BarsAgo = 0;
                        x.EndAnchor.SlotIndex = CurrentBar;
                        x.EndAnchor.Price = High[0];
    
    
                      }        
                }
            }
        }
    }
    You can also access without the DrawObjects array as the MyLine object.

    Please let me know if I can assist any further.

    Comment


      #3
      That worked, thanks!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      649 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      370 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      109 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      574 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      576 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X