Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator not showing on any chart

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

    Indicator not showing on any chart

    Hello I have create an indicator with the following code but It is not showing on any charts. Can you please help me
    #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 PE : Indicator
    {
    private Series<double> lnC;
    private Series<double> ProdlnC;
    private Series<double> SMAln;
    private Series<double> SUMln;
    private Series<double> RMS;
    private double last;
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "PE";
    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 = 14;
    AddPlot(Brushes.Orange, "EntropyP");
    }
    else if (State == State.DataLoaded)
    {
    lnC= new Series<double>(this);
    ProdlnC= new Series<double>(this);
    SMAln= new Series<double>(this);
    SUMln=new Series<double>(this);
    RMS = new Series<double>(this);
    }
    }

    protected override void OnBarUpdate()
    {

    if(CurrentBar<=Period+1)
    {
    lnC[0] = Math.Log(Close[0]/Close[1]);
    ProdlnC[0]= lnC[0]*lnC[0];
    last=0;
    Value[0]=last;
    }
    else
    {
    lnC[0] = Math.Log(Close[0]/Close[1]);
    ProdlnC[0]= lnC[0]*lnC[0];
    SMAln[0]= SMA(lnC,Period)[0];
    SUMln[0]= SUM(ProdlnC,Period)[0];
    RMS[0]= Math.Sqrt(SUMln[0]/Period);
    last=(((SMAln[0]/RMS[0])+1)/2)*100;//Add your custom indicator logic here.
    Value[0]=last;
    }
    }

    #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> EntropyP
    {
    get { return Values[0]; }
    }
    #endregion

    }
    }

    #region NinjaScript generated code. Neither change nor remove.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private PE[] cachePE;
    public PE PE(int period)
    {
    return PE(Input, period);
    }

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

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

    public Indicators.PE PE(ISeries<double> input , int period)
    {
    return indicator.PE(input, period);
    }
    }
    }

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

    public Indicators.PE PE(ISeries<double> input , int period)
    {
    return indicator.PE(input, period);
    }
    }
    }

    #endregion

    #2
    Hello mkachmar,

    Thank you for your note.

    First, I've moved this to the Indicator Development forum as it fits better in this section.

    Secondly I see the following error when the indicator is applied:

    Indicator 'PE': Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

    So, you're hitting an indexing error here. Most likely it's on line 70:

    if(CurrentBar<=Period+1)
    {
    lnC[0] = Math.Log(Close[0]/Close[1]);
    ProdlnC[0]= lnC[0]*lnC[0];
    last=0;
    Value[0]=last;
    }

    You're not checking if there's at least 1 bar to look back at the close of prior to that, so you'd hit an indexing error on the very first bar on the chart.

    I'd suggest adding this before that section:

    if(CurrentBar < 1)
    return;

    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Hi, Thank you for your message. I've tried your suggestion but still not working.

      Comment


        #4
        Hello mkachmar,

        Thank you for your reply.

        Could you provide your current code so we can see the changes you've made?

        Thanks in advance; I look forward to assisting you further.

        Comment


          #5
          #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 PE : Indicator
          {
          private Series<double> lnC;
          private Series<double> ProdlnC;
          private Series<double> SMAln;
          private Series<double> SUMln;
          private Series<double> RMS;
          private double last;
          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Description = @"Enter the description for your new custom Indicator here.";
          Name = "PE";
          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 = 14;
          AddPlot(Brushes.Orange, "EntropyP");
          }
          else if (State == State.DataLoaded)
          {
          lnC= new Series<double>(this);
          ProdlnC= new Series<double>(this);
          SMAln= new Series<double>(this);
          SUMln=new Series<double>(this);
          RMS = new Series<double>(this);
          }
          }

          protected override void OnBarUpdate()
          {
          lnC[0] = Math.Log(Close[0]/Close[1]);
          if(CurrentBar<1)

          return;

          if(CurrentBar>=Period+1)
          {
          lnC[0] = Math.Log(Close[0]/Close[1]);
          ProdlnC[0]= lnC[0]*lnC[0];
          SMAln[0]= SMA(lnC,Period)[0];
          SUMln[0]= SUM(ProdlnC,Period)[0];
          RMS[0]= Math.Sqrt(SUMln[0]/Period);
          last=(((SMAln[0]/RMS[0])+1)/2)*100;//Add your custom indicator logic here.
          Value[0]=SUM(lnC,Period)[0];
          }
          else
          {
          lnC[0] = Math.Log(Close[0]/Close[1]);
          ProdlnC[0]= lnC[0]*lnC[0];
          last=0;
          EntropyP[0]=0;
          }

          }

          #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> EntropyP
          {
          get { return Values[0]; }
          }
          #endregion

          }
          }

          #region NinjaScript generated code. Neither change nor remove.

          namespace NinjaTrader.NinjaScript.Indicators
          {
          public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
          {
          private PE[] cachePE;
          public PE PE(int period)
          {
          return PE(Input, period);
          }

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

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

          public Indicators.PE PE(ISeries<double> input , int period)
          {
          return indicator.PE(input, period);
          }
          }
          }

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

          public Indicators.PE PE(ISeries<double> input , int period)
          {
          return indicator.PE(input, period);
          }
          }
          }

          #endregion

          Comment


            #6
            Hello mkachmar,

            Thank you for your reply.

            I note you are still trying to access the close of 1 bar ago before checking you have 1 bar to look back on, which would continue to cause an indexing error:

            lnC[0] = Math.Log(Close[0]/Close[1]);
            if(CurrentBar<1)

            return;

            These statements would need to switch in order:

            if(CurrentBar<1)
            return;
            lnC[0] = Math.Log(Close[0]/Close[1]);

            The CurrentBars check needs to be the first thing in OnBarUpdate to avoid this.

            Please let us know if we may be of further assistance to you.

            Comment


              #7
              I try this and It is actualy working thank you for your help
              #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 PE : Indicator
              {
              private Series<double> lnC;
              private Series<double> ProdlnC;

              protected override void OnStateChange()
              {
              if (State == State.SetDefaults)
              {
              Description = @"Enter the description for your new custom Indicator here.";
              Name = "PE";
              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 = 14;
              AddPlot(Brushes.Orange, "EntropyP");
              }
              else if (State == State.DataLoaded)
              {
              lnC= new Series<double>(this);
              ProdlnC= new Series<double>(this);

              }
              }

              protected override void OnBarUpdate()
              {
              if(CurrentBar<1)
              return;

              if(CurrentBar>=Period+1)
              {
              lnC[0] = Math.Log(Close[0]/Close[1]);
              ProdlnC[0]= lnC[0]*lnC[0];
              Value[0]= (((((SUM(lnC,Period)[0])/Period)/(Math.Sqrt((SUM(ProdlnC,Period)[0])/Period)))+1)/2)*100;
              }
              else
              {
              lnC[0] = Math.Log(Close[0]/Close[1]);
              ProdlnC[0]= lnC[0]*lnC[0];
              Value[0]=0;
              }

              }

              #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> EntropyP
              {
              get { return Values[0]; }
              }
              #endregion

              }
              }

              #region NinjaScript generated code. Neither change nor remove.

              namespace NinjaTrader.NinjaScript.Indicators
              {
              public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
              {
              private PE[] cachePE;
              public PE PE(int period)
              {
              return PE(Input, period);
              }

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

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

              public Indicators.PE PE(ISeries<double> input , int period)
              {
              return indicator.PE(input, period);
              }
              }
              }

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

              public Indicators.PE PE(ISeries<double> input , int period)
              {
              return indicator.PE(input, period);
              }
              }
              }

              #endregion

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              608 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              355 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