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 usazencort, Today, 01:16 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post usazencort  
                    Started by kaywai, 09-01-2023, 08:44 PM
                    5 responses
                    603 views
                    0 likes
                    Last Post NinjaTrader_Jason  
                    Started by xiinteractive, 04-09-2024, 08:08 AM
                    6 responses
                    22 views
                    0 likes
                    Last Post xiinteractive  
                    Started by Pattontje, Yesterday, 02:10 PM
                    2 responses
                    20 views
                    0 likes
                    Last Post Pattontje  
                    Started by flybuzz, 04-21-2024, 04:07 PM
                    17 responses
                    230 views
                    0 likes
                    Last Post TradingLoss  
                    Working...
                    X