Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator not showing output, including AddLine

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

    Indicator not showing output, including AddLine

    Apologies for the code below, I couldn't figure out how to make it an attachment. My question is how do I get the indicator working? The code shows no errors but when I open it on a chart I get nothing but a blank box. Any help is appreciated.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class StrengthTrend : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"";
    Name = "Strength Trend";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    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 = 55;
    AddPlot(Brushes.Green, "UpLine");
    AddPlot(Brushes.Red, "DownLine");
    AddPlot(Brushes.Orange, "Difference");
    AddLine(Brushes.DarkGray, 0, "ZeroLine");
    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBar == 0)
    {
    UpLine[0] = 0;
    DownLine[0] = 0;
    }

    double up = 0;
    double down = 0;
    for(int i = 0; i < Period; i++)
    {
    if(Close[i] > Open[i])
    {
    up = up + (Close[i] - Open[i])/(High[i] - Low[i]);
    }
    if(Close[i] < Open[i])
    {
    down = down + (Close[i] - Open[i])/(High[i] - Low[i]);
    }
    }
    UpLine[0] = up;
    DownLine[0] = down;
    Difference[0] = up + down;
    }

    region Properties
    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="Period", Order=1, GroupName="Parameters")]
    public int Period
    { get; set; }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> UpLine
    {
    get { return Values[0]; }
    }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> DownLine
    {
    get { return Values[1]; }
    }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> Difference
    {
    get { return Values[2]; }
    }

    #endregion

    }
    }​

    #2
    Try this : 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

    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class AddPlots : Indicator

    {

    protected override void OnStateChange()
    {
    if(State == State.SetDefaults)
    {
    Name = "AddPlots";
    // Add two plots
    AddPlot(Brushes.Blue, "Upper");
    AddPlot(Brushes.Orange, "Lower");
    }
    }

    protected override void OnBarUpdate()
    {
    // Sets values to our two plots
    Upper[0] = SMA(High, 20)[0];
    Lower[0] = SMA(Low, 20)[0];

    // Color the Upper plot based on plot value conditions
    if (IsRising(Upper))
    PlotBrushes[0][0] = Brushes.Blue;
    else if (IsFalling(Upper))
    PlotBrushes[0][0] = Brushes.Red;
    else
    PlotBrushes[0][0] = Brushes.Yellow;

    // Color the Lower plot based on plot value conditions
    if (IsRising(Lower))
    PlotBrushes[1][0] = Brushes.Blue;
    else if (IsFalling(Lower))
    PlotBrushes[1][0] = Brushes.Red;
    else
    PlotBrushes[1][0] = Brushes.Yellow;
    }

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

    public Series<double> Lower
    {
    get { return Values[1]; }
    }
    }
    }

    region NinjaScript generated code. Neither change nor remove.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private AdPlots[] cacheAdPlots;
    public AdPlots AdPlots()
    {
    return AdPlots(Input);
    }

    public AdPlots AdPlots(ISeries<double> input)
    {
    if (cacheAdPlots != null)
    for (int idx = 0; idx < cacheAdPlots.Length; idx++)
    if (cacheAdPlots[idx] != null && cacheAdPlots[idx].EqualsInput(input))
    return cacheAdPlots[idx];
    return CacheIndicator<AdPlots>(new AdPlots(), input, ref cacheAdPlots);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.AdPlots AdPlots()
    {
    return indicator.AdPlots(Input);
    }

    public Indicators.AdPlots AdPlots(ISeries<double> input )
    {
    return indicator.AdPlots(input);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.AdPlots AdPlots()
    {
    return indicator.AdPlots(Input);
    }

    public Indicators.AdPlots AdPlots(ISeries<double> input )
    {
    return indicator.AdPlots(input);
    }
    }
    }

    #endregion

    Comment


      #3
      Hello KDTrade,

      Thanks for your post.

      When testing the code you shared, I see an error message in the Log tab of the Control Center indicating "Object reference is not set to an instance of an object". The error is advising that something you are accessing has not been created at the time you are accessing it.

      To determine what the source of the error is you will need to debug your indicator. This is typically done with print statements added to your code to send a print output to the New>Ninjascript Output window. As you do not know where the error is, you would add a print statement every few lines of code and then observe the output window when you apply the strategy. The last print statement value shown in the output window would indicate the error occurs after that print statement, you can then add further print statements to zero in on the offending code.

      Here is a link to our tips on debugging: https://ninjatrader.com/support/help...script_cod.htm

      Let me know if I may further assist.​
      <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
      670 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      379 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      111 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      575 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      582 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X