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

BarsRequired error...maybe??

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

    BarsRequired error...maybe??

    Trying to call an indicator from my strategy:
    Code:
    private KeltnerEmaAtr k;
    
    protected override void OnStartUp()
    {
    	k = new KeltnerEmaAtr();
    }
    ~~~~~~
    
    protected override void OnBarUpdate()
    {
            if (CurrentBar < k.MainPeriod) // (k.MainPeriod = 20)
    		return;
    	Print (Close[0]+" = "+k.Upper[0]);
    }
    I thought testing for CurrentBar/k.MainPeriod was the correct thing to do, instead I keep getting this message:

    Code:
    **NT** Error on calling 'OnBarUpdate' method for strategy 'AutoSysTrader/d2d5700a1a99406b9073e5b5a3922b3a': Index was outside the bounds of the array.
    What am I missing here?

    #2
    Hello Funky101.

    Thank you for your note.

    Try spreading out the prints with this matter.

    Example -
    Print(Close[0]);
    Print(k.Upper[0]);

    Also, is MainPeriod a public or private variable that you are trying to get for the minimum bars value?
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Yeah, it Prints Close[0] but fails on k.Upper[0];

      MainPeriod is a public var seen below
      Code:
      [Description("Numbers of bars used for calculations")]
      [GridCategory("Parameters")]
      public int MainPeriod
      {
      	get { return mainPeriod; }
      	set { mainPeriod = Math.Max(1, value); }
      }
      Last edited by funk101; 10-17-2014, 07:55 AM. Reason: Oops, wrong var I posted before

      Comment


        #4
        By the way..

        It fails when I use the regular KeltnerChannel() too

        Comment


          #5
          Funk101,

          Can you send me your script including what you have created for the KeltnerEma?
          Cal H.NinjaTrader Customer Service

          Comment


            #6
            What address?

            Comment


              #7
              Funk101,

              Apologies, I jumped the post button too soon.

              Please send these to platformsupport [at] ninjatrader [dot] com with ATTN Cal in the subject and reference this thread in the body
              Cal H.NinjaTrader Customer Service

              Comment


                #8
                Sent. Again, this will fail with the regular KeltnerChannel() as well. It does however work with, for example, CCI()

                Comment


                  #9
                  Funk101,

                  The reason for this is because you are trying to create a new instance and not the indicator object.

                  You need to use the Indicator class with the overload parameters as such -

                  k = KeltnerEmaAtr(false, 20, 10, 2.0, false);


                  Let me know if I can be of further assistance.
                  Cal H.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks, that was the answer *without* "new"
                    Last edited by funk101; 10-17-2014, 09:32 AM.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Segwin, 05-07-2018, 02:15 PM
                    14 responses
                    1,789 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,294 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