Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Configure Time

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

    #16
    Note that Closes[int barSeriesIndex][int barsAgo] lets you specify what barSeriesIndex you want to access the close price of and the barsAgo value of that secondary added series.

    int closeBarIndex3 = CurrentBars[3] - AnchorONELookBackPeriod;

    so I thought that was what I was doing below

    double close3Price = Close[closeBarIndex3]

    that needs to be double close3Price = Closes[closeBarIndex3][AnchorONELookBackPeriod] /// ie set to 30

    if so creates an error in the LOG, it does compile

    or does this just mean Closes[int barSeriesIndex][int barsAgo] Closes[3][30]

    I THINK THIS WILL MEAN THAT MY OTHER INDICATOR IS INCORRECT AS WELL
    Last edited by DTSSTS; 04-26-2023, 12:50 PM.

    Comment


      #17
      Hello DTSSTS,

      Thanks for your note.

      int closeBarIndex3 = CurrentBars[3] - AnchorONELookBackPeriod;

      If "AnchorONELookBackPeriod" is set to 30, this will calculate what the barIndex value is for the third secondary series 30 bars back from the current bar. This is a barIndex value, NOT a barsAgo value.

      For example, let's say the CurrentBar of the third added series is bar 1000. This code above would return a value of 970. 970 is the barIndex value of that specific bar. You could think of a barIndex value as a bar number for that specific bar.

      If you pass that variable which returns a value of 970 into Close[barsAgo], this would be equivalent to calling Close[970], which means you would get the Close price 970 bars back from the current bar since Close[barsAgo] takes a barsAgo argument, NOT at barIndex argument. You can think of barsAgo as the number of bars you want to look back.

      Since you want to look back 30 bars to get the Close price, you would need to call Close[30]. 30 would be the barsAgo parameter being passed in which means you would get the Close price 30 bars back from the current bar.

      ​" close3Price = Closes[closeBarIndex3][AnchorONELookBackPeriod] /// ie set to 30"

      This would be incorrect. Using the example above, say the "closebarIndex3" is returning a value of 970 (the bar index value of that bar) and "AnchorONELookBackPeriod" is set to 30 . This would be equivalent to calling Closes[970][30] and there are not 970 additional data series added to your script.

      "or does this just mean Closes[int barSeriesIndex][int barsAgo] Closes[3][30]"

      That is correct. You would use Closes[3][30] as stated in post # 15.

      Let's look at this using an example. Closes[int barSeriesIndex][int barsAgo] lets you specify what barSeriesIndex you want to access the close price of and the barsAgo value of that added series.

      A barSeriesIndex is the added series you want to access. Since you want to access the Close price of the third added series in your script, the barSeriesIndex would be 3 (referencing the third added series in your script).

      So you could call Closes[3][AnchorONELookBackPeriod] to get the Close price of the third added series 30 bar ago since AnchorONELookBackPeriod is set to 30. Or, you could call Closes[3][30].
      Last edited by NinjaTrader_BrandonH; 04-26-2023, 01:15 PM.
      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

      Comment


        #18
        If "AnchorONELookBackPeriod" is set to 30, this will calculate what the barIndex value is for the third secondary series 30 bars back from the current bar. This is a barIndex value, NOT a barsAgo value. YES EXACTLY

        int closeBarIndex3 = CurrentBars[3] - AnchorONELookBackPeriod;​ <<--- i THOUGHT THIS WAS IDENTIFYING MY barindex

        BUT I NEED A : barSeriesIndex CORRECT? (WHICH I DO NOT HAVE ON THE INDICATOR JUST FINISH - or not finish now)

        this i get Closes[3][AnchorONELookBackPeriod] and I get this int closeBarIndex3 = CurrentBars[3] - AnchorONELookBackPeriod;​​ is my barindex

        BUT I NEED barSeriesIndex (SO ALL THE OTHER INFO IS JUST A CLUTTER OF UNNEEDED data

        so I have to tell the code that I need to use the barSeriesIndex 3 How do I do that?

        Thanks

        ​I think I might have became more lost
        Last edited by DTSSTS; 04-26-2023, 01:44 PM.

        Comment


          #19
          Hello DTSSTS,

          Thanks for your notes.

          "int closeBarIndex3 = CurrentBars[3] - AnchorONELookBackPeriod;​ <<--- i THOUGHT THIS WAS IDENTIFYING MY barindex"

          This is identifying the barIndex value. The barSeriesIndex is the index of the data series you want to reference. This is different than a barIndex.

          The difference is the barIndex references a specific bar number and a barSeriesIndex is the index number of the data series you want to reference.

          The primary series the script is running on will have the barSeriesIndex value of 0. The first AddDataSeries() call in the script will have a barSeriesIndex of 1. The second AddDataSeries() call in the script will have a barSeriesIndex of 2. The third AddDataSeries() call in the script will have a barSeriesIndex of 3, and so on.

          If you want to get the Close price 30 bars ago on the third added data series in the script, you need to supply a barSeriesIndex of 3 and a barsAgo of 30.

          Closes[3][30] or Closes[3][AnchorONELookBackPeriod]



          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment


            #20
            Closes[3][30] ok I thought were talking about something I never saw before. I have been using Closes[3][30] for 4 years, just never had anyone say the is the barSeriesIndex

            so the barindex is what I need. but my calculations are not starting with the correct bar number in this case. all my prints describe what I expect to see. but the calculation I do not believe is starting on the barindex or bar number

            My prints

            Closes3 BAR 1: 12958

            CurrentBars[3] - 5: 20210
            CurrentBars[3] - 30: 20185
            closeBarIndex3: 20185 << correct bar number
            time30minAgo : 4/26/2023 4:10:00 PM << correct bar time
            Double close3Price: 12958 << correct bar price


            maybe i am just getting started incorrectly with my if statement

            in the prior indicator you helped me with we started with

            if (HighestBar(Highs[3], AnchorONELookBackPeriod) == 0);
            and Chelse sugggested startlogic

            this time I started with

            if ((Closes[3][AnchorONELookBackPeriod]) == 0); // << ------- is this my issue



            {
            startLogicH1 = true;

            }


            if (startLogicH1 == true)

            Thanks again​
            Last edited by DTSSTS; 04-26-2023, 02:46 PM.

            Comment


              #21
              Hello DTSSTS,

              Thanks for your note.

              Yes, I mentioned barSeriesIndex because that is what is stated in the Syntax section of the Closes help guide page linked below.

              Closes[int barSeriesIndex][int barsAgo]

              ​Closes: https://ninjatrader.com/support/help...nt8/closes.htm

              There is nothing specific that I could adivse on as to why your script is not behaving as expected. Ultimately, if your script is not behaving as you are expecting it to, you would need to further debug your script to see exactly how all of your custom logic is evaluating to see what logic needs to be modified to accomplish your overall goal.

              Below is a link to a forum post that demonstrates how to use prints to understand behavior.
              https://ninjatrader.com/support/foru...121#post791121
              <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

              Comment


                #22
                example from prev indicator reference the HighestBar
                double high3Price = High[highestBarIndex3];

                example from this indicator for where if Used Close instead of High I do not think close is correct and Closes does not compile, do you have a suggestion

                double close3Price = Close[closeBarIndex3];

                thanks

                Comment


                  #23
                  Hello DTSSTS,

                  Thanks for your notes.

                  To get the High price and the Close price you must use a barsAgo value. This is stated in the Syntax section of the High[] and Close[] help guide pages.

                  Close[int barsAgo]

                  High[int barsAgo]


                  See the help guide documentation below.
                  High: https://ninjatrader.com/support/helpGuides/nt8/high.htm
                  Close: https://ninjatrader.com/support/help.../nt8/close.htm

                  From the code you shared it seems like you are passing in a barIndex value. You need to use a barsAgo value instead. For example, to get the Close price 30 bars ago, you would pass in 30 as the barsAgo argument (Close[30]).

                  This also applies to High[barsAgo]. If you want to get the High price 78 bars ago, you need to use High[78].

                  Since your closeBarIndex3 variable holds a barIndex value of say 20185 seen in post # 20 and not a value of 30, you should not use closeBarIndex3 in Close[barsAgo].

                  To get the Close price of the 3rd added series 30 bars ago in your script, you need to use Closes[3][30]. The 3 references the third added data series in your script and the 30 represents the lookback period of 30 bars back from the current bar.

                  See the help guide pages below.

                  Closes: https://ninjatrader.com/support/help...nt8/closes.htm
                  Highs: https://ninjatrader.com/support/help.../nt8/highs.htm
                  <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  650 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  370 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  109 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  574 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  577 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X