Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Issue with Follow Line Indicator - No Line Displayed

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

    Issue with Follow Line Indicator - No Line Displayed

    Hello everyone,

    I'm encountering an issue with the Follow Line Indicator in NinjaTrader, and I'm seeking some assistance to resolve it. Despite following the code instructions and making the necessary modifications, I'm unable to see any lines displayed on the chart when I add the indicator.

    I have double-checked the code and ensured that I added two plots for the uptrend line (blue) and the downtrend line (red). I have also set the plot styles to "Line" and adjusted the plot widths.

    However, even after implementing these changes, the indicator still doesn't display any lines on the chart. I would greatly appreciate it if someone could review my code and provide guidance on what might be causing this issue.

    I have also checked for any error messages in the NinjaScript Output window, but there are no related error messages displayed.

    Any help or suggestions would be highly appreciated. Thank you in advance for your assistance.

    Best regards,




    region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class FollowLineIndicator : Indicator
    {
    private double TrendLine = 0.0;
    private double iTrend = 0.0;
    private double previousTrendLine;
    private double previousiTrend;

    private double BBUpper;
    private double BBLower;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "Follow Line Indicator";
    Name = "FLI";
    IsOverlay = true;
    BBperiod = 21;
    BBdeviations = 1.0;
    UseATRfilter = true;
    ATRperiod = 5;
    }
    else if (State == State.Configure)
    {
    AddPlot(Brushes.Blue, "UptrendLine");
    AddPlot(Brushes.Red, "DowntrendLine");
    Plots[0].PlotStyle = PlotStyle.Line;
    Plots[1].PlotStyle = PlotStyle.Line;
    Plots[0].Width = 2;
    Plots[1].Width = 2;
    }
    }

    protected override void OnBarUpdate()
    {
    BBUpper = SMA(Close, BBperiod)[0] + StdDev(Close, BBperiod)[0] * BBdeviations;
    BBLower = SMA(Close, BBperiod)[0] - StdDev(Close, BBperiod)[0] * BBdeviations;

    int BBSignal = Close[0] > BBUpper ? 1 : Close[0] < BBLower ? -1 : 0;

    if (BBSignal == 1 && UseATRfilter)
    {
    TrendLine = Low[0] - ATR(ATRperiod)[0];
    if (TrendLine < previousTrendLine)
    TrendLine = previousTrendLine;
    }
    else if (BBSignal == -1 && UseATRfilter)
    {
    TrendLine = High[0] + ATR(ATRperiod)[0];
    if (TrendLine > previousTrendLine)
    TrendLine = previousTrendLine;
    }
    else if (BBSignal == 0 && UseATRfilter)
    {
    TrendLine = previousTrendLine;
    }
    else if (BBSignal == 1 && !UseATRfilter)
    {
    TrendLine = Low[0];
    if (TrendLine < previousTrendLine)
    TrendLine = previousTrendLine;
    }
    else if (BBSignal == -1 && !UseATRfilter)
    {
    TrendLine = High[0];
    if (TrendLine > previousTrendLine)
    TrendLine = previousTrendLine;
    }
    else if (BBSignal == 0 && !UseATRfilter)
    {
    TrendLine = previousTrendLine;
    }

    iTrend = previousiTrend;
    if (TrendLine > previousTrendLine)
    iTrend = 1;
    else if (TrendLine < previousTrendLine)
    iTrend = -1;

    previousTrendLine = TrendLine;
    previousiTrend = iTrend;

    PlotBrushes[0][0] = iTrend > 0 ? Brushes.Blue : Brushes.Red;
    }

    region Properties
    [Range(1, int.MaxValue)]
    [NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "BB Period", GroupName = "Parameters", Order = 0)]
    public int BBperiod { get; set; }

    [Range(0.1, double.MaxValue)]
    [NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "BB Deviations", GroupName = "Parameters", Order = 1)]
    public double BBdeviations { get; set; }

    [NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "Use ATR Filter", GroupName = "Parameters", Order = 2)]
    public bool UseATRfilter { get; set; }

    [Range(1, int.MaxValue)]
    [NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "ATR Period", GroupName = "Parameters", Order = 3)]
    public int ATRperiod { get; set; }
    #endregion
    }
    }


    #2
    Hello nadire.sadiki60,

    Thanks for your post.

    I see you are calling AddPlot() within State.Configure. The AddPlot() method should be called in State.SetDefaults, not State.Configure.

    Also, I do not see where you are assigning a value to the UpTrendLine and DownTrendLine plots in the script. A value must be assigned to each plot for the plot to appear on the chart window.

    Values[0][0] = x could be used to assign a value to the first plot where 'x' should be the value you want to assign to the plot. Values[1][0] = x could be used to assign a value to the second plot where 'x' represents the value you want to add to the plot.

    See this help guide page for more information about AddPlot() and assigning values to the plot: https://ninjatrader.com/support/help...t8/addplot.htm
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    599 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    344 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    558 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    557 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X