Can someone help me with the code. This is a SuperTrend indicator. The problem is that the DownTrend line does not appear. See where the error is in the code? Thank you
namespace NinjaTrader.NinjaScript.Indicators.LICO_indicators
{
public class LicoSuperTrend : Indicator
{
private Series<bool> Trend;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "LicoSuperTrend";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = false;
DrawVerticalGridLines = false;
PaintPriceMarkers = false;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
Period = 10;
Multiplier = 2;
AddPlot( new Stroke(Brushes.Lime, 2), PlotStyle.Line, "UpTrend");
AddPlot( new Stroke(Brushes.Red, 2), PlotStyle.Line, "DownTrend");
}
else if (State == State.Configure)
{
Trend = new Series<bool>(this);
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < Period)
return;
double bandUpper = Median[0] + Multiplier * ATR(Period)[0];
double bandLower = Median[0] - Multiplier * ATR(Period)[0];
if (Close[0] > DownTrend[1])
Trend[0] = true;
else if (Close[0] < UpTrend[1])
Trend[0] = false;
else
Trend[0] = Trend[1];
if (Trend[0] == true && Trend[1] == false)
{
UpTrend[0] = bandLower;
UpTrend[1] = DownTrend[1];
}
else if (Trend[0] == false && Trend[1] == true)
{
DownTrend[0] = bandUpper;
DownTrend[1] = UpTrend[1];
}
else if (Trend[0] == true)
UpTrend[0] = bandLower > UpTrend[1] ? bandLower : UpTrend[1];
else
DownTrend[0] = bandUpper < DownTrend[1] ? bandUpper : DownTrend[1];
}

Comment