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

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.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      That worked, thanks!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by morrnel, Today, 06:07 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by thumper57, Yesterday, 04:30 PM
      6 responses
      20 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by sastrades, 05-10-2024, 09:59 AM
      3 responses
      55 views
      0 likes
      Last Post rc5781
      by rc5781
       
      Started by guyonabuffalo, Yesterday, 10:01 PM
      2 responses
      22 views
      0 likes
      Last Post guyonabuffalo  
      Started by reynoldsn, 05-10-2024, 07:04 PM
      5 responses
      27 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Working...
      X