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

Using indicator in strategy

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

    Using indicator in strategy

    Hi -

    I have a very simple strategy that runs on range bars and renko bars. I want to add a 15 minute sma to the strategy. I have added a second data series. When I try to look at the first element of the SMA indicator on the second Data Series I get the following error:

    System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index'

    When I change the primary chart to a 1 minute chart, I do not get this error and all appears to work as expected.

    Can you mix different bar types in a strategy? If so, what do I need to do?

    Find attached the strategy.

    Thanks for your help.
    Attached Files

    #2
    Hello kweiss,

    Thank you for your post.

    You can certainly mix different bar types within a strategy. However, I do not have the bar type of the secondary data series on my system - this appears to be a custom bar type in use. Can you provide an export of the strategy so it will include necessary references?

    You can export the strategy from Tools > Export > NinjaScript Add-on. Do not check the box to export as a compiled assembly or I will not be able to review the logic. Please attach the resulting .Zip file to your reply.

    Thanks in advance; I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hi Kate -


      The secondary bar type is :

      AddDataSeries(Instrument.FullName, new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 15 }, 200, SESSIONTYPEETH, null);


      A copy of the strategies .cs file was attached. I have attached an export of the strategy also.

      Thank you for your prompt help.

      Kenneth Weiss


      Attached Files

      Comment


        #4
        Hello kweiss,

        Thank you for your reply.

        The custom bars type you are calling was not included in the export - that's my mistake, I thought those would be automatically included, but I hadn't exported a script that uses one in a while. I can't tell what custom bars type it is solely from the AddDataSeries call since that refers to it by the BarsPeriodType Value rather than the actual name and these can be the same with different custom bar types as they are just specified by the programmer. Can you clarify what the actual name of the custom bars type is and whether it is one you created yourself, or is from a third party vendor. If you can supply the bartype as well, that would be helpful.

        Thanks in advance; I look forward to assisting you further.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Hi Kate -

          I am NOT using any custom bar types. I am only using two of the 14 default BarTypes that are intrinsic to NinjaTrader -- Range Bars on the chart (BarsArray[0]) and Minute bars (BarsArray[1]). Below is from NT help confirming that these are standard NinjaTrader Types.

          Please import my strategy and place it on a NQ range bar chart.

          Thank you for your continued help.

          From NinjaTrader Help:
          BarsPeriod.BarsPeriodType


          The type of bars used for the period, as well as the enumeration value under which the any of the 14 default NinjaTrader types are registered. Possible values include:
          BarsPeriodType.Tick 0
          BarsPeriodType.Volume 1
          BarsPeriodType.Range 2
          BarsPeriodType.Second 3
          BarsPeriodType.Minute 4
          BarsPeriodType.Day 5
          BarsPeriodType.Week 6
          BarsPeriodType.Month 7
          BarsPeriodType.Year 8
          BarsPeriodType.HeikenAshi 9
          BarsPeriodType.Kagi 10
          BarsPeriodType.Renko 11
          BarsPeriodType.PointAndFigure 12
          BarsPeriodType.LineBreak 13
          BarsPeriodType.Volumetric 14
          Last edited by kweiss; 03-10-2022, 02:52 PM.

          Comment


            #6
            Hello kweiss,

            Thank you for your reply.

            Ah, thank you for your clarification - that's an overload for AddDataSeries we very rarely see used and it does look like casting a custom series - sorry for the confusion.

            That being said, you are checking if CurrentBars < 10 before trying to process, but you're calculating the indicator on the secondary series, so you need to explicitly tell it you need at least 10 bars of that secondary series to process:

            protected override void OnBarUpdate()
            {
            if (CurrentBars[1] < 10)
            return;


            var e = sma[0];
            }

            I'm not seeing it have an index error when applied to a range chart after making that change.

            Please let us know if we may be of further assistance to you.
            Kate W.NinjaTrader Customer Service

            Comment


              #7
              Hi Kate -

              YES. This is the answer. Things now works.

              Thank you for Help

              Kenneth Weiss
              Last edited by kweiss; 03-10-2022, 07:38 PM.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by fx.practic, 10-15-2013, 12:53 AM
              5 responses
              5,404 views
              0 likes
              Last Post Bidder
              by Bidder
               
              Started by Shai Samuel, 07-02-2022, 02:46 PM
              4 responses
              95 views
              0 likes
              Last Post Bidder
              by Bidder
               
              Started by DJ888, Yesterday, 10:57 PM
              0 responses
              8 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by MacDad, 02-25-2024, 11:48 PM
              7 responses
              159 views
              0 likes
              Last Post loganjarosz123  
              Started by Belfortbucks, Yesterday, 09:29 PM
              0 responses
              8 views
              0 likes
              Last Post Belfortbucks  
              Working...
              X