Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plotting TrendLines and accessing values

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

    Plotting TrendLines and accessing values

    I want to plot TrendLines and be able to access TrendLine values on the Y axis. The following simplified version of my code generates the plot and TrendLine values are nicely displayed
    in the Data Box.
    HOWEVER, the TrendLine plotted is a zig zag rather than a straight line. I'm confident my coding format is OK as I plot several other indicators that behave perfectly. I guess there's
    something different about trend lines.
    Any insight, ye masters of Ninjascript?

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Name = "Plot TrendLines;

    AddPlot(new Stroke(Brushes.CornflowerBlue, 2), PlotStyle.Line, "TrendLines1");

    protected override void OnBarUpdate()
    {
    TrendLines1[0] = TrendLines(Close, 10, 1, 25, false)[0];
    }

    public Series<double> TrendLines1
    { get { return Values[0]; }}

    }
    }

    #2
    Hello Doctor JR,

    Thanks for your post.

    You are creating a plot called TrendLines1 and its value is being set by the current bar value of the indicator Trendlines.

    As the Trendlines indicator changes its value so will the plot.

    The TrendLines indicator will not determine a new swing high or swing low to create a new trendline until the "strength" number of bars have passed.

    I've created a short video to walk through this as it is easier to explain visually: https://paul-ninjatrader.tinytake.co...NV8xNzk5NTg2MQ

    In short, this would be the expected behavior because your indicator is showing the current value of the active trendline from the TrendLine indicator.

    Comment


      #3
      You are certainly correct that for this issue visual works better than written. Thanks a bunch for going an extra distance for me. I expected the plot to look like the indicator but now I understand.
      Thanks again.

      Comment


        #4
        I find the zig zags a bit distracting, but I discovered a cure:

        ShowTransparentPlotsInDataBox = true;
        AddPlot(new Stroke(Brushes.Transparent, 1), PlotStyle.Line, "TrendLines1");

        Now I can implement the indicator on my chart without the distracting zig zags while accessing the current TrendLine value for my strategy.

        Comment


          #5
          Paul,
          Thanks again for your short on-point Trendline video. Very nice.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          605 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          351 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          105 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          560 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          561 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X