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
}
}

Comment