Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indexing and type int

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

    Indexing and type int

    I have created a multi-series script that calls on an indicator.
    Filter is the CrossAbove Threshold
    Lookback is the bars looking back.
    Index 0 is my primary dataseries
    Index 1 is a 1-second data series.

    CrossAbove(BIDASKSpread().Plot0, Filter, Lookback[1][0])

    I would like to use the lookback period on the 1-second dataseries, and I can't get this to compile correctly. Is this possible?

    #2
    Hi Baseheadz,

    Lookback input there is only looking for an integer. There is not indexing available for this.

    CrossAbove and CrossBelow must take a data series for the first input. The second input can be a double value, so that would be the only place where you could apply indexing.

    If you want the cross above condition to apply to a specific series, then you can check within a BarsInProgress filter.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Ok, I understand. But I can not find any documentation on how to nest the BarsInProgress into a condition set:
      This is my actual condition set below. "Cutoff" and "Filter" are both doubles. Lookback is an int.
      Thanks in advance for all of your incredible help!

      if (CrossAbove(Close, EMA(LengthMA), 1)
      && Close[0] > Close[1]

      // How do I properly nest the BarsInProgress filter here???*********************

      && CrossAbove(BIDASKSpread().Plot0, Filter, Lookback)
      && MAX(BIDASKSpread().Plot0, Lookback)[0] <= Cutoff)

      {
      EnterLongLimit(DefaultQuantity, Close[0], "");
      }

      Comment


        #4
        BarsInProgress does not have a nesting concept. It's used to define the series context of updates.

        If you want to check the condition within updates for the secondary series, use:

        if(BarsInProgress == 1)
        {
        Print("Primary series close is " + Closes[0][0]);
        Print("Primary series SMA is " + SMA(Closes[0], 14)[0]);
        }

        From within there: If you need to check values from the primary series, you need things like Closes[0][0] for a double, Closes[0] for a series. Also BarsArray[0], Highs[0], etc, can be used.

        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Is it ok to do it like this? For example, let's say that I wanted my code to work on a 1-Minute ES dataseries. So I could create a primary dataseries, which in this case could be the 1-Second ES bars. Then could I use (BarsInProgress == 1) for the code below? In this way, I would not to change too much of my code? Will this work?


          {
          Add(PeriodType.Second, 1);
          }


          protected override void OnBarUpdate()
          {
          if (BarsInProgress == 1)
          {

          if (CrossAbove(Close, EMA(LengthMA), 1)
          && Close[0] > Close[1]
          && CrossAbove(BIDASKSpread().Plot0, Filter, Lookback)
          && MAX(BIDASKSpread().Plot0, Lookback)[0] <= Cutoff)

          {
          EnterLongLimit(DefaultQuantity, Close[0], "");
          }
          }
          }

          Comment


            #6
            the issue is that the BidAskSpread indicator is using 1-second bars.

            I noticed that my strategy works fine if my data is set to 1-second bars. But when my primary bars are set to 1-minute, the strategy is missing trades based on the BidAskSpread indicator

            Comment


              #7
              It really depends what you're going for. The primary series is the one the script is applied to. This is BIP = 0. The first added series (the secondary series), is BIP = 1. If you want to check conditions on the secondary series, you can use a bip == 1 filter.
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                Ok, I've changed my code to allow for the BIP == 1 Filter.

                I now get some compiling CS1518 errors in the #region properties.

                Here is an example of one of the errors with the line "public int LengthMA"

                Below is the code:

                [Description("Length of MA")]
                [GridCategory("Parameters")]
                public int LengthMA
                {
                get { return lengthMA; }
                set { lengthMA = Math.Max(1, value); }
                }

                Comment


                  #9
                  and is my syntax ok for the code that I showed with the BIP == 1? I can't find any examples of how to do this and I've searched the forums. Thanks in advance!

                  Comment


                    #10
                    For multiseries examples you can look at the existing ones under tools > edit NinjaScript > Strategy.
                    This page on multi time frame and instrument also provides links to BarsInProgress usage.

                    If you get an error for the properties region, please see this page below. Yours looks OK except you may be missing declaring lengthMA in the variables region.
                    Ryan M.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    648 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    369 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    108 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    572 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    573 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X