Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Error: Index was outside the bounds of the array

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

    Error: Index was outside the bounds of the array

    Hello all, new to programming, so please excuse any dumb questions ...

    I have put together an oscillator which compiled and is running just fine. On this oscillator, I have added 2 sets of lines, 1 set to mark the overbought/oversold areas, the other set to mark warning lines. The only issue I've seen so far is that indicator goes blank if I change the boolean (to show/hide overbought/oversold lines) to false from the indicators popup screen. I have another boolean that is setup the exact same way (toggles show/hide the warning lines) but it does not give any issues if I set it to false.

    the output window says
    Code:
    Failed to call method 'Initialize' for indicator '': Index was outside the bounds of the array.
    I have 2 sets of plots, set 1 is overbought and oversold plots, set 2 is bullish warning and bearish warning plots. They are set up as plots and not lines.

    Here is the code I use for that in the initialize section

    Code:
                if (ShowOBLines==true)
                {
                Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "BullsExtended"));
                Plots[10].Pen.DashStyle = DashStyle.Dash;
                Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "BearsExtended"));
                Plots[11].Pen.DashStyle = DashStyle.Dash;
                }
                
                if (ShowWarningLines==true)
                {
                Add(new Plot(Color.FromKnownColor(KnownColor.Black), PlotStyle.Line, "BullsWarning"));
                Plots[12].Pen.DashStyle = DashStyle.Dash;
                Add(new Plot(Color.FromKnownColor(KnownColor.Black), PlotStyle.Line, "BearsWarning"));
                Plots[13].Pen.DashStyle = DashStyle.Dash;
                }
    then in the OnBarUpdate section, this is what I have coded

    Code:
                if (ShowOBLines==true)
                {
                    BullsExtended.Set(OverBought);
                    BearsExtended.Set(OverSold);
                }
                
                if (ShowWarningLines==true)
                {
                    BullsWarning.Set(BullWarning);
                    BearsWarning.Set(BearWarning);
                }
    and finally, in the Properties section, this is what I have

    Code:
            [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 BullsExtended
            {
                get { return Values[10]; }
            }
            
            [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 BearsExtended
            {
                get { return Values[11]; }
            }
            
                    [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 BullsWarning
            {
                get { return Values[12]; }
            }
            
            [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 BearsWarning
            {
                get { return Values[13]; }
            }
    when ShowOBLines is set to false, the indicator goes blank, but ShowWarningLines works just fine when toggled true/false. My guess is that setting ShowOBLines to false messes up the array of dataseries as the BullsExtended and BearsExtended dataseries are not at the end of the array, but I do not understand enough to know what to do about it.

    any ideas? Thank you!

    #2
    gubbar924, correct - the issue very likely comes from changing the Values array needed with that conditional entry. I would leave all plots eventually needed defined and then just set values conditionally. That will have visually the same effect for you, as the Plot definitions in Initialize() will just define how those set values are displayed.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi Bertrand, thanks for the tip, but I'm entirely sure I follow what you meant. Is there a way to dynamically change the look/feel of a plot?

      I tried this as well, but the lines did not disappear


      Code:
                  if (ShowOBLines==true)
                      {
                      Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "BullsExtended"));
                      Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "BearsExtended"));
                      }
                  else
                      {
                      Add(new Plot(Color.FromKnownColor(KnownColor.Transparent), PlotStyle.Line, "BullsExtended"));
                      Add(new Plot(Color.FromKnownColor(KnownColor.Transparent), PlotStyle.Line, "BearsExtended"));
                      }
                      
                      Plots[10].Pen.DashStyle = DashStyle.Dash;
                      Plots[11].Pen.DashStyle = DashStyle.Dash;
                  
                  if (ShowWarningLines==true)
                      {
                      Add(new Plot(Color.FromKnownColor(KnownColor.Black), PlotStyle.Line, "BullsWarning"));
                      Add(new Plot(Color.FromKnownColor(KnownColor.Black), PlotStyle.Line, "BearsWarning"));
                      }
                  else
                      {
                      Add(new Plot(Color.FromKnownColor(KnownColor.Transparent), PlotStyle.Line, "BullsWarning"));
                      Add(new Plot(Color.FromKnownColor(KnownColor.Transparent), PlotStyle.Line, "BearsWarning"));
                      }
                  
                  Plots[12].Pen.DashStyle = DashStyle.Dash;
                  Plots[13].Pen.DashStyle = DashStyle.Dash;
      in hindsight I see how that would not change anything
      do you have any suggestions as to how I can dynamically change the visibility of these plots?

      Comment


        #4
        gubbar924, I would make the conditional logic then to change the colors to OnStartUp instead. Just define all your plots with the default color for example in Initialize() and then change later.

        Code:
        protected override void OnStartUp()
        {
        
           if (your condition)
              Plots[x].Pen.Color = Color.Transparent;
        
        }
        BertrandNinjaTrader Customer Service

        Comment


          #5
          so thats how its done, thank you!
          Last edited by gubbar924; 08-23-2014, 01:34 PM.

          Comment


            #6
            got it working now, thank you for your help!

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Segwin, 05-07-2018, 02:15 PM
            14 responses
            1,788 views
            0 likes
            Last Post aligator  
            Started by Jimmyk, 01-26-2018, 05:19 AM
            6 responses
            837 views
            0 likes
            Last Post emuns
            by emuns
             
            Started by jxs_xrj, 01-12-2020, 09:49 AM
            6 responses
            3,293 views
            1 like
            Last Post jgualdronc  
            Started by Touch-Ups, Today, 10:36 AM
            0 responses
            13 views
            0 likes
            Last Post Touch-Ups  
            Started by geddyisodin, 04-25-2024, 05:20 AM
            11 responses
            63 views
            0 likes
            Last Post halgo_boulder  
            Working...
            X