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

"index was outside the bounds of the array"

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

    "index was outside the bounds of the array"

    Hey, an error appears in the Log saying "index was outside the bounds of the array"

    the strategy doesn't work and i dont know how to solve it, any help will be appreciated
    Thanks a lot!


    KBT_Strat_Stoch_Bands_V1.zip

    #2
    Just a quick look.

    In your OnBarUpdate() I see this code,

    Code:
    if ( CurrentBars[[B][COLOR=Red]1[/COLOR][/B]] <=  ( channelPeriods +  signalPeriods)       ) return;
    But I see no secondary data series added in your Initialize().

    Are you sure you mean to use CurrentBars[1]?

    Did you try using CurrentBars[0]?

    Comment


      #3
      Hi david, well the indicator on which the strategy is based is multitimeframe, meaning i could calculate it from a 60 minute timeframe while using the default timeframe (CurrentBars[0]) to trigger entries

      Comment


        #4
        If i use CurrentBars[0] the strategy indicator just disappears, while before it was there just no entries triggered at all and the error "index was outside the bounds of the array" on the Log tab

        Comment


          #5
          Hello kabott,

          I am also seeing what bltdavid has mentioned.

          The BarsInProgress index of CurrentBars identifies the data series that is processing.

          Your script does not add a secondary series. Thus CurrentBars[1] does not exist.

          The strategy does add an indicator to the chart, but this does not create a secondary price data series in the Strategy.

          Below is a link to the help guide on Add() which demonstrates how to add additional series to a script.


          If you are receiving an index error, this will cause your strategy to become disabled. This would indicate why the strategy does not place trades, as it is hitting an error and becoming disabled.

          Further, have you commented out all unrelated code to identify the line of code that is generating the error?
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            This is the indicator applied directly to a 20 Range chart while calculating from a 60 Minute Timeframe

            Click image for larger version

Name:	2016-10-10_132814.jpg
Views:	1
Size:	124.7 KB
ID:	880831

            and i wanted to make a strategy so i could test it

            Comment


              #7
              Hi ChelseaB, i added the new data series and now the error says "Add method only accepts positive period values but was -1"

              :/

              Comment


                #8
                Hello kabott,

                What code did you use to add the secondary series?

                Are you supplying the BarsArray[BarsInProgress index] to the indicator call?

                For example, if I were calling the SMA with a secondary series of 10 minute:

                Code:
                protected override void Initialize()
                {
                	Add(PeriodType.Minute, 10);
                }
                
                protected override void OnBarUpdate()
                {
                	Print(string.Format("{0} | SMA(BarsArray[1], 14)[0]: {1}", Time[0], SMA(BarsArray[1], 14)[0]));
                }
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi ChelseaB, same script i ised inside the indicator being called by the strategy (which is multimeframe)

                  switch(bType)
                  {
                  case KBTSinB_V2.Default:
                  Add(Instrument.FullName, BarsPeriod.Id, BarsPeriod.Value, MarketDataType.Last);
                  break;

                  case KBTSinB_V2.Minute:
                  Add(PeriodType.Minute, timeframePeriods);
                  break;

                  case KBTSinB_V2.Day:
                  Add(PeriodType.Day, timeframePeriods);
                  break;

                  case KBTSinB_V2.Week:
                  Add(PeriodType.Week, timeframePeriods);
                  break;

                  case KBTSinB_V2.Range:
                  Add(PeriodType.Range, timeframePeriods);
                  break;

                  case KBTSinB_V2.RangeNoGap:
                  Add(PeriodType.Custom2, timeframePeriods);
                  break;

                  case KBTSinB_V2.Renko:
                  Add(PeriodType.Renko, timeframePeriods);
                  break;

                  case KBTSinB_V2.HybridRenko:
                  Add(PeriodType.Final0, timeframePeriods);
                  break;




                  ill paste the complete script in a sec, i know its tedious to install indicators all the time :P

                  Comment


                    #10
                    protected override void Initialize()
                    {
                    EntryHandling = EntryHandling.UniqueEntries;
                    // CalculateOnBarClose = false;
                    ExitOnClose= false;
                    Enabled = true;


                    #region Mayor TF Selection Switcher

                    switch(bType)
                    {
                    case KBTSinB_V2.Default:
                    Add(Instrument.FullName, BarsPeriod.Id, BarsPeriod.Value, MarketDataType.Last);
                    break;

                    case KBTSinB_V2.Minute:
                    Add(PeriodType.Minute, timeframePeriods);
                    break;

                    case KBTSinB_V2.Day:
                    Add(PeriodType.Day, timeframePeriods);
                    break;

                    case KBTSinB_V2.Week:
                    Add(PeriodType.Week, timeframePeriods);
                    break;

                    case KBTSinB_V2.Range:
                    Add(PeriodType.Range, timeframePeriods);
                    break;

                    case KBTSinB_V2.RangeNoGap:
                    Add(PeriodType.Custom2, timeframePeriods);
                    break;

                    case KBTSinB_V2.Renko:
                    Add(PeriodType.Renko, timeframePeriods);
                    break;

                    case KBTSinB_V2.HybridRenko:
                    Add(PeriodType.Final0, timeframePeriods);
                    break;


                    }

                    #endregion


                    SInB = KBT_Stochastics_in_Bands_V3( adxMinimumVolatility, adxPeriod, ModeStyle.Stochastics, KBTSinB_V2.Default, channel_MidOffset_Percent, channel_Offset, channelPeriods, SelectChannelStartegy.None, macdFast, macdSlow, macdSmooth, maType, signalPeriods, signalType, stochPeriodD, stochPeriodK, stochSmooth, timeframePeriods);
                    Add( SInB);





                    }


                    protected override void OnBarUpdate()
                    {
                    EntryHandling = EntryHandling.UniqueEntries;
                    ManageOrders();



                    if ( CurrentBars[1] <= ( channelPeriods + signalPeriods) ) return;
                    {
                    if (BarsInProgress == 0 )
                    {



                    #region -- Entrys

                    // RISING

                    if ( ( SInB.SinB_ADX[0] > adxMinimumVolatility) &&
                    ( SInB.Channel_Midline[0] > SInB.Channel_Signal[0] ) &&
                    ( SInB.Avg_Fast[1] < SInB.Channel_Midline[1] || SInB.Avg_Fast[2] < SInB.Channel_Midline[2] ) &&
                    ( SInB.Avg_Fast[1] < SInB.Avg_Slow[1] && SInB.Avg_Fast[0] > SInB.Avg_Slow[0] || SInB.Avg_Fast[2] < SInB.Avg_Slow[2] && SInB.Avg_Fast[1] > SInB.Avg_Slow[1] || SInB.Avg_Fast[3] < SInB.Avg_Slow[3] && SInB.Avg_Fast[2] > SInB.Avg_Slow[2] ) &&
                    ( SInB.MicroT3Close[1] < SInB.MicroT3Open[1] && SInB.MicroT3Close[0] > SInB.MicroT3Open[0] ) && FirstTickOfBar )
                    {


                    GoLong();


                    }



                    // Falling
                    if ( ( SInB.SinB_ADX[0] > adxMinimumVolatility ) &&
                    ( SInB.Channel_Midline[0] < SInB.Channel_Signal[0] ) &&
                    ( SInB.Avg_Fast[1] > SInB.Channel_Midline[1] || SInB.Avg_Fast[2] > SInB.Channel_Midline[2] ) &&
                    ( SInB.Avg_Fast[1] > SInB.Avg_Slow[1] && SInB.Avg_Fast[0] < SInB.Avg_Slow[0] || SInB.Avg_Fast[2] > SInB.Avg_Slow[2] && SInB.Avg_Fast[1] < SInB.Avg_Slow[1] || SInB.Avg_Fast[3] > SInB.Avg_Slow[3] && SInB.Avg_Fast[2] < SInB.Avg_Slow[2] ) &&
                    ( SInB.MicroT3Close[1] > SInB.MicroT3Open[1] && SInB.MicroT3Close[0] < SInB.MicroT3Open[0] ) && FirstTickOfBar )
                    {

                    GoShort();

                    }

                    #endregion

                    Comment


                      #11
                      Hello kabott,

                      Before trying something very complicated like this, have you tried adding one additional series without a switch and using this as the input for a call to an indicator?

                      Please try simplifying your code to the bare minimum needed to test.

                      Have you tried the example I have posted in post #8?
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        You are right Chelsea, actually i was thinking about it too, im gonna write a very basic version and use that one for the strategy

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Gerik, Today, 09:40 AM
                        1 response
                        6 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by RookieTrader, Today, 09:37 AM
                        1 response
                        10 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by alifarahani, Today, 09:40 AM
                        0 responses
                        5 views
                        0 likes
                        Last Post alifarahani  
                        Started by KennyK, 05-29-2017, 02:02 AM
                        3 responses
                        1,284 views
                        0 likes
                        Last Post NinjaTrader_Clayton  
                        Started by AttiM, 02-14-2024, 05:20 PM
                        11 responses
                        186 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Working...
                        X