Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Pesky old Index was outside the bounds of the array.

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

    Pesky old Index was outside the bounds of the array.

    This is the indicator getting the error.

    Code:
            protected override void OnBarUpdate()
            {
    		if (Historical)return;
    		if (CurrentBar <1)return;
               	PricePlot.Set(Input[0] - Trend()[0]);
            }
    This is the Trend Indicator.

    Code:
            protected override void OnBarUpdate()
            {
    		if (CurrentBar <1)return;
     		StudyBar = GetBar(Time[1].AddMinutes(-30));
               	TrendLine.Set(SMA(StudyBar)[1]);
            }
    I have tried replacing both indexes with [1], no joy...

    #2
    Hello Sleeping Troll,

    That's not the results I'm seeing with this. Make sure to recompile both indicators and reapply them to a chart. If you can provide any more details on how this is used, we can help track down what might be different on your setup. Let us know the settings used in the Initialize() block.

    The if (Historical) return; statement will mean this is only run on live data.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hey, thought I had found something...
      The error is being returned on Bar 10560, I changed this:

      Code:
       
      protected override void OnBarUpdate()
      {
      if (CurrentBar <1)return;
      StudyBar = GetBar(Time[1].AddMinutes(-30));
      TrendLine.Set(SMA(StudyBar)[1]);
      }
      To this:

      I am using Trend in a Strategy and all is fine,
      I am using TrendLevel to Plot a representaion of price "normalized" to Trend.

      Code:
       
      protected override void OnBarUpdate()
      {
      if (Historical)return;
      if (CurrentBar <1)return;
      StudyBar = GetBar(Time[1].AddMinutes(-30));
      TrendLine.Set(SMA(StudyBar)[1]);
      }

      Same result...

      Here is the Initialize:

      Trend:
      Code:
       
       
      protected override void Initialize()
      {
      Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "TrendLine"));
      CalculateOnBarClose = true;
      Overlay = true;
      PriceTypeSupported = false;
      }
      TrendLevel:

      Code:
       
      protected override void Initialize()
      {
      Add(new Plot(Color.FromKnownColor(KnownColor.Black), PlotStyle.Line, "PricePlot"));
      CalculateOnBarClose = true;
      Overlay = false;
      PriceTypeSupported = false;
      }
      Last edited by Sleeping Troll; 04-21-2010, 05:45 PM.

      Comment


        #4
        Hello SleepingTroll,

        We've not been able to reproduce this using the snippets you're providing. Can you package up these two files (File > Utilities > Export NinjaScript) and mail to [email protected]

        Please include details such as instrument, interval, data provider as well as the context that you're using this. You mention that Trend is used in a strategy. Where are you using TrendLevel?
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          I have eliminated several problems by rereading help on SessionBar(), but I still have this problem...
          This is my Indicator "Trend".

          Code:
           
          #region Using declarations
          using System;
          using System.ComponentModel;
          using System.Diagnostics;
          using System.Drawing;
          using System.Drawing.Drawing2D;
          using System.Xml.Serialization;
          using NinjaTrader.Cbi;
          using NinjaTrader.Data;
          using NinjaTrader.Gui.Chart;
          #endregion
          // This namespace holds all indicators and is required. Do not change it.
          namespace NinjaTrader.Indicator
          {
          /// <summary>
          /// Enter the description of your new custom indicator here
          /// </summary>
          [Description("Enter the description of your new custom indicator here")]
          public class Trend : Indicator
          {
          #region Variables
          private int StudyBar;
          #endregion
          /// <summary>
          /// This method is used to configure the indicator and is called once before any bar data is loaded.
          /// </summary>
          protected override void Initialize()
          {
          Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "TrendLine"));
          CalculateOnBarClose = false;
          Overlay = true;
          PriceTypeSupported = false;
          }
          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()
          {
          if(Historical)return;
          StudyBar = GetBar(Time[0].AddMinutes(-30));
          TrendLine.Set(SMA(StudyBar)[1]);
          }
          #region Properties
          [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
          [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
          public DataSeries TrendLine
          {
          get { return Values[0]; }
          }
          #endregion
          }
          }
          #region NinjaScript generated code. Neither change nor remove.
          // This namespace holds all indicators and is required. Do not change it.
          namespace NinjaTrader.Indicator
          {
          public partial class Indicator : IndicatorBase
          {
          private Trend[] cacheTrend = null;
          private static Trend checkTrend = new Trend();
          /// <summary>
          /// Enter the description of your new custom indicator here
          /// </summary>
          /// <returns></returns>
          public Trend Trend()
          {
          return Trend(Input);
          }
          /// <summary>
          /// Enter the description of your new custom indicator here
          /// </summary>
          /// <returns></returns>
          public Trend Trend(Data.IDataSeries input)
          {
          if (cacheTrend != null)
          for (int idx = 0; idx < cacheTrend.Length; idx++)
          if (cacheTrend[idx].EqualsInput(input))
          return cacheTrend[idx];
          Trend indicator = new Trend();
          indicator.BarsRequired = BarsRequired;
          indicator.CalculateOnBarClose = CalculateOnBarClose;
          indicator.Input = input;
          indicator.SetUp();
          Trend[] tmp = new Trend[cacheTrend == null ? 1 : cacheTrend.Length + 1];
          if (cacheTrend != null)
          cacheTrend.CopyTo(tmp, 0);
          tmp[tmp.Length - 1] = indicator;
          cacheTrend = tmp;
          Indicators.Add(indicator);
          return indicator;
          }
          }
          }
          // This namespace holds all market analyzer column definitions and is required. Do not change it.
          namespace NinjaTrader.MarketAnalyzer
          {
          public partial class Column : ColumnBase
          {
          /// <summary>
          /// Enter the description of your new custom indicator here
          /// </summary>
          /// <returns></returns>
          [Gui.Design.WizardCondition("Indicator")]
          public Indicator.Trend Trend()
          {
          return _indicator.Trend(Input);
          }
          /// <summary>
          /// Enter the description of your new custom indicator here
          /// </summary>
          /// <returns></returns>
          public Indicator.Trend Trend(Data.IDataSeries input)
          {
          return _indicator.Trend(input);
          }
          }
          }
          // This namespace holds all strategies and is required. Do not change it.
          namespace NinjaTrader.Strategy
          {
          public partial class Strategy : StrategyBase
          {
          /// <summary>
          /// Enter the description of your new custom indicator here
          /// </summary>
          /// <returns></returns>
          [Gui.Design.WizardCondition("Indicator")]
          public Indicator.Trend Trend()
          {
          return _indicator.Trend(Input);
          }
          /// <summary>
          /// Enter the description of your new custom indicator here
          /// </summary>
          /// <returns></returns>
          public Indicator.Trend Trend(Data.IDataSeries input)
          {
          if (InInitialize && input == null)
          throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
          return _indicator.Trend(input);
          }
          }
          }
          #endregion
          It works fine.
          This is my Indicator TrendLevel.
          Code:
           
           
          #region Using declarations
          using System;
          using System.ComponentModel;
          using System.Diagnostics;
          using System.Drawing;
          using System.Drawing.Drawing2D;
          using System.Xml.Serialization;
          using NinjaTrader.Cbi;
          using NinjaTrader.Data;
          using NinjaTrader.Gui.Chart;
          #endregion
          // This namespace holds all indicators and is required. Do not change it.
          namespace NinjaTrader.Indicator
          {
          /// <summary>
          /// This indicator plots prices as an offset from the trend.
          /// </summary>
          [Description("This indicator plots prices as an offset from the trend.")]
          public class TrendLevel : Indicator
          {
          #region Variables
          private int StudyBar;
          #endregion
          /// <summary>
          /// This method is used to configure the indicator and is called once before any bar data is loaded.
          /// </summary>
          protected override void Initialize()
          {
          Add(new Plot(Color.FromKnownColor(KnownColor.Black), PlotStyle.Line, "PricePlot"));
          CalculateOnBarClose = false;
          Overlay = false;
          PriceTypeSupported = false;
          }
          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()
          {
          if (Historical);
          Print(Input[0] - Trend().TrendLine[0]);
          PricePlot.Set(Input[0] - Trend().TrendLine[0]);
          }
          #region Properties
          [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
          [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
          public DataSeries Trendline
          {
          get { return Values[0]; }
          }
          [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
          [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
          public DataSeries PricePlot
          {
          get { return Values[1]; }
          }
          #endregion
          }
          }
          #region NinjaScript generated code. Neither change nor remove.
          // This namespace holds all indicators and is required. Do not change it.
          namespace NinjaTrader.Indicator
          {
          public partial class Indicator : IndicatorBase
          {
          private TrendLevel[] cacheTrendLevel = null;
          private static TrendLevel checkTrendLevel = new TrendLevel();
          /// <summary>
          /// This indicator plots prices as an offset from the trend.
          /// </summary>
          /// <returns></returns>
          public TrendLevel TrendLevel()
          {
          return TrendLevel(Input);
          }
          /// <summary>
          /// This indicator plots prices as an offset from the trend.
          /// </summary>
          /// <returns></returns>
          public TrendLevel TrendLevel(Data.IDataSeries input)
          {
          if (cacheTrendLevel != null)
          for (int idx = 0; idx < cacheTrendLevel.Length; idx++)
          if (cacheTrendLevel[idx].EqualsInput(input))
          return cacheTrendLevel[idx];
          TrendLevel indicator = new TrendLevel();
          indicator.BarsRequired = BarsRequired;
          indicator.CalculateOnBarClose = CalculateOnBarClose;
          indicator.Input = input;
          indicator.SetUp();
          TrendLevel[] tmp = new TrendLevel[cacheTrendLevel == null ? 1 : cacheTrendLevel.Length + 1];
          if (cacheTrendLevel != null)
          cacheTrendLevel.CopyTo(tmp, 0);
          tmp[tmp.Length - 1] = indicator;
          cacheTrendLevel = tmp;
          Indicators.Add(indicator);
          return indicator;
          }
          }
          }
          // This namespace holds all market analyzer column definitions and is required. Do not change it.
          namespace NinjaTrader.MarketAnalyzer
          {
          public partial class Column : ColumnBase
          {
          /// <summary>
          /// This indicator plots prices as an offset from the trend.
          /// </summary>
          /// <returns></returns>
          [Gui.Design.WizardCondition("Indicator")]
          public Indicator.TrendLevel TrendLevel()
          {
          return _indicator.TrendLevel(Input);
          }
          /// <summary>
          /// This indicator plots prices as an offset from the trend.
          /// </summary>
          /// <returns></returns>
          public Indicator.TrendLevel TrendLevel(Data.IDataSeries input)
          {
          return _indicator.TrendLevel(input);
          }
          }
          }
          // This namespace holds all strategies and is required. Do not change it.
          namespace NinjaTrader.Strategy
          {
          public partial class Strategy : StrategyBase
          {
          /// <summary>
          /// This indicator plots prices as an offset from the trend.
          /// </summary>
          /// <returns></returns>
          [Gui.Design.WizardCondition("Indicator")]
          public Indicator.TrendLevel TrendLevel()
          {
          return _indicator.TrendLevel(Input);
          }
          /// <summary>
          /// This indicator plots prices as an offset from the trend.
          /// </summary>
          /// <returns></returns>
          public Indicator.TrendLevel TrendLevel(Data.IDataSeries input)
          {
          if (InInitialize && input == null)
          throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
          return _indicator.TrendLevel(input);
          }
          }
          }
          #endregion
          It generates the error "index was outside the bounds of the array, can you see anything amiss?

          Comment


            #6
            protected override void OnBarUpdate()
            {
            if (Historical);

            That statement doesn't look right. Should be:
            if (Historical)
            return;
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Yes, that was incorrect, however it did not correct problem.

              Comment


                #8
                I'll be happy to look at this further if you mail the files and include the details requested in post #4.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Any luck with files yet?

                  Comment


                    #10
                    Sleeping Troll, we are happy to take a look, however can you please send us complete files in as requested by Ryan? Thanks in advance.

                    Comment


                      #11
                      Did that yesterday...

                      Comment


                        #12
                        I had replied to the @yahoo account you used to send the files.

                        The files you sent were incomplete - It did not contain TrendLevel

                        There were also several additional files that were not necessary and as a result I couldn't import the .zip file. Based on your thread, the two files we're intersted in are Trend and TrendLevel. Please package up a NinjaScript file containing just these two.
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          Will resend, TrendLevel is just an indicator that proviudes a visual representation of the data that the strategy is working with, Trend is where the strategy gets it's data. Better yet , here is the code:

                          Code:
                           
                          #region Using declarations
                          using System;
                          using System.ComponentModel;
                          using System.Diagnostics;
                          using System.Drawing;
                          using System.Drawing.Drawing2D;
                          using System.Xml.Serialization;
                          using NinjaTrader.Cbi;
                          using NinjaTrader.Data;
                          using NinjaTrader.Gui.Chart;
                          #endregion
                          // This namespace holds all indicators and is required. Do not change it.
                          namespace NinjaTrader.Indicator
                          {
                          /// <summary>
                          /// This indicator plots prices as an offset from the trend.
                          /// </summary>
                          [Description("This indicator plots prices as an offset from the trend.")]
                          public class TrendLevel : Indicator
                          {
                          #region Variables
                          private int StudyBar;
                          #endregion
                          /// <summary>
                          /// This method is used to configure the indicator and is called once before any bar data is loaded.
                          /// </summary>
                          protected override void Initialize()
                          {
                          Add(new Plot(Color.FromKnownColor(KnownColor.Black), PlotStyle.Line, "PricePlot"));
                          CalculateOnBarClose = false;
                          Overlay = false;
                          PriceTypeSupported = false;
                          }
                          /// <summary>
                          /// Called on each bar update event (incoming tick)
                          /// </summary>
                          protected override void OnBarUpdate()
                          {
                          if(CurrentBar < 1)return;
                          PricePlot.Set(Input[0] - Trend()[1]);
                          }
                          #region Properties
                          [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                          [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                          public DataSeries Trendline
                          {
                          get { return Values[0]; }
                          }
                          [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                          [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                          public DataSeries PricePlot
                          {
                          get { return Values[1]; }
                          }
                          #endregion
                          }
                          }
                          #region NinjaScript generated code. Neither change nor remove.
                          // This namespace holds all indicators and is required. Do not change it.
                          namespace NinjaTrader.Indicator
                          {
                          public partial class Indicator : IndicatorBase
                          {
                          private TrendLevel[] cacheTrendLevel = null;
                          private static TrendLevel checkTrendLevel = new TrendLevel();
                          /// <summary>
                          /// This indicator plots prices as an offset from the trend.
                          /// </summary>
                          /// <returns></returns>
                          public TrendLevel TrendLevel()
                          {
                          return TrendLevel(Input);
                          }
                          /// <summary>
                          /// This indicator plots prices as an offset from the trend.
                          /// </summary>
                          /// <returns></returns>
                          public TrendLevel TrendLevel(Data.IDataSeries input)
                          {
                          if (cacheTrendLevel != null)
                          for (int idx = 0; idx < cacheTrendLevel.Length; idx++)
                          if (cacheTrendLevel[idx].EqualsInput(input))
                          return cacheTrendLevel[idx];
                          TrendLevel indicator = new TrendLevel();
                          indicator.BarsRequired = BarsRequired;
                          indicator.CalculateOnBarClose = CalculateOnBarClose;
                          indicator.Input = input;
                          indicator.SetUp();
                          TrendLevel[] tmp = new TrendLevel[cacheTrendLevel == null ? 1 : cacheTrendLevel.Length + 1];
                          if (cacheTrendLevel != null)
                          cacheTrendLevel.CopyTo(tmp, 0);
                          tmp[tmp.Length - 1] = indicator;
                          cacheTrendLevel = tmp;
                          Indicators.Add(indicator);
                          return indicator;
                          }
                          }
                          }
                          // This namespace holds all market analyzer column definitions and is required. Do not change it.
                          namespace NinjaTrader.MarketAnalyzer
                          {
                          public partial class Column : ColumnBase
                          {
                          /// <summary>
                          /// This indicator plots prices as an offset from the trend.
                          /// </summary>
                          /// <returns></returns>
                          [Gui.Design.WizardCondition("Indicator")]
                          public Indicator.TrendLevel TrendLevel()
                          {
                          return _indicator.TrendLevel(Input);
                          }
                          /// <summary>
                          /// This indicator plots prices as an offset from the trend.
                          /// </summary>
                          /// <returns></returns>
                          public Indicator.TrendLevel TrendLevel(Data.IDataSeries input)
                          {
                          return _indicator.TrendLevel(input);
                          }
                          }
                          }
                          // This namespace holds all strategies and is required. Do not change it.
                          namespace NinjaTrader.Strategy
                          {
                          public partial class Strategy : StrategyBase
                          {
                          /// <summary>
                          /// This indicator plots prices as an offset from the trend.
                          /// </summary>
                          /// <returns></returns>
                          [Gui.Design.WizardCondition("Indicator")]
                          public Indicator.TrendLevel TrendLevel()
                          {
                          return _indicator.TrendLevel(Input);
                          }
                          /// <summary>
                          /// This indicator plots prices as an offset from the trend.
                          /// </summary>
                          /// <returns></returns>
                          public Indicator.TrendLevel TrendLevel(Data.IDataSeries input)
                          {
                          if (InInitialize && input == null)
                          throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
                          return _indicator.TrendLevel(input);
                          }
                          }
                          }
                          #endregion

                          Comment


                            #14
                            OK, will send just those...

                            Comment


                              #15
                              Hey, I found it! I had some spurious code in my properties section of TrendLevel.

                              Thx for your efforts all.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              656 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              371 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              109 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              574 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              579 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X