Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Configure Time

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

    Configure Time

    My current Configure regiion is

    else if (State == State.Configure)
    {

    AddDataSeries(Data.BarsPeriodType.Minute, 1);/// Closes[1]
    AddDataSeries(Data.BarsPeriodType.Minute, 5);/// Closes[2]


    }



    }

    I need to add the following into my configure region


    {
    // Define the TimeAdd method here
    DateTime TimeAdd(DateTime dateTime, TimeSpan timeSpan)
    {
    return dateTime.Add(timeSpan);
    }
    }

    I plan then to add to onBarUpdate area


    DateTime time30minAgo = Time[1].TimeAdd(TimeSpan.FromMinutes(-30));

    any help appreciated
    DTSSTS​​

    #2
    It's not clear from this post what you are trying to do here. It looks like, so far, you are adding 1-minute and 5-minute series, and you have a method TimeAdd you want to define (which does not belong in the Configure region but outside of OnStateChange) and then in OnBarUpdate you want to calculate 30 minutes before the timestamp of the end of the previous bar (not clear which of the three data series you are referring to here - the chart one or either of the two you added).
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Thanks. let me start over if It does not need to be in the Configure area

      I need this in onBarUpdate

      DateTime time30minAgo = Time[1].TimeAdd(TimeSpan.FromMinutes(-30));

      I will be using Closes[2]

      when I add and compile my error is NO definition for TimeAdd

      So I need to define that in some area

      thanks again

      Comment


        #4
        DateTime time30minAgo = DateTime.MinValue;

        if (CurrentBars[2] >= 1) time30minAgo = Times[2][1].AddMinutes(-30);
        Bruce DeVault
        QuantKey Trading Vendor Services
        NinjaTrader Ecosystem Vendor - QuantKey

        Comment


          #5
          all in OnBarUpdate region?

          and Thanks

          Comment


            #6
            Yes, in OnBarUpdate.
            Bruce DeVault
            QuantKey Trading Vendor Services
            NinjaTrader Ecosystem Vendor - QuantKey

            Comment


              #7
              Hello DTSSTS,

              Thanks for your post.

              QuantKey_Bruce is correct. The TimeAdd method would need to be defined outside of OnStateChange() since it is a custom method.

              "I need this in onBarUpdate

              DateTime time30minAgo = Time[1].TimeAdd(TimeSpan.FromMinutes(-30));

              I will be using Closes[2]​"


              The code shared in post # 4 by QuantKey_Bruce could be placed in OnBarUpdate as they stated to accomplish your goal.
              <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


                #8
                yes thanks I have placed it there and continue to work with my code I am using something from the other indicator you helped me with BrandonH

                HighestBar(Highs[3], 78); BELOW is what I did to get the vwap to lock into the correct bar to start the calculations

                int highestBarIndex3 = HighestBar(Highs[3], 78);
                DateTime highestBarTime3 = Time[highestBarIndex3];

                double high3Price = High[highestBarIndex3];

                since my plot currently is not correct I was trying to adapt the above but the int part has me stuck - I cannot find what replaces HighestBar

                int closeBarIndex3 = whatgoeshere(Closes[3], 30); <-- looking for the CloseBar of that bar, NOT the HighestBar

                ALSO then plan to use double high3Price = High[highestBarIndex3];

                double close3Price = Close[closeBarIndex3];

                thanks again to both of you
                ​​
                Last edited by DTSSTS; 04-26-2023, 09:15 AM.

                Comment


                  #9
                  Hello DTSSTS,

                  Thanks for your notes.

                  What exactly is the value that you are trying to access in the script?

                  Are you trying to get the highest close price that occurred on the 3rd added series in your script over the last 30 bars?

                  If so, you would use the HighestBar() method and pass in "Closes[3], 30" for the arguments of HighestBar(), such as HighestBar(Closes[3], 30). This would return the highest close price from the 3rd added series in your script over the last 30 bars.

                  Note that the HighestBar() method returns the highest price value that occurred within the specified look-back period for the ISeries you pass in. In this case, the ISeries would be Highs[3] to get the highest high price or Closes[3] to get the highest close price.

                  Do you want to get the close price of the 3rd added series 30 bars ago?

                  If so, you could use Closes[3][30] to get the close price of the 3rd added series 30 bars ago.

                  HighestBar: https://ninjatrader.com/support/help...sub=HighestBar
                  Closes: https://ninjatrader.com/support/help...nt8/closes.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


                    #10
                    I want to get the bar of the Closes[3][30] purpose is to plot the vwap from 30 minutes ago forward to see vwap of Last 30 minutes only

                    to use as I did in the old HighestBar script - THIS HAS NOTHING TO DO WITH HIGHESTBAR just the Bar 30 bars ago


                    Chat GBT suggested using CurrentBar as this - THIS WOULD NOT COMPILE

                    int closeBarIndex3 = CurrentBar - 30; /// I did not see how CurrentBar could be correct as were are using dataseries Closes[3]



                    double close3Price = Closes[closeBarIndex3];// HAD TO CHANGE Closes to Close to get this to compile


                    this compiles but just looking at the plot I do not think it is correct to what we are looking for (I added the time line of code)

                    int closeBarIndex3 = CurrentBars[3] - AnchorONELookBackPeriod;/// changed CurrentBar to CurrentBars[3]

                    DateTime time30minAgo = Time[closeBarIndex3];

                    double close3Price = Close[closeBarIndex3];// changed Closes to Close​

                    Comment


                      #11
                      Hello DTSSTS,

                      Thanks for your notes.

                      To get the bar index of the 3rd added series 30 bars prior to the current bar, you could use (CurrentBars[3] - 30). For example, if the current bar of the third added series is 1050, (CurrentBars[3] - 30) would return 1020 (1050 - 30 = 1020). The below code would print the bar index of the third added series 30 bars prior to the current bar.

                      Print("CurrentBars[3] - 30: " + (CurrentBars[3] - 30));

                      Review this help guide page about CurrentBars: https://ninjatrader.com/support/help...urrentbars.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


                        #12
                        int closeBarIndex3 = CurrentBars[3] - 30;

                        DateTime time30minAgo = Time[closeBarIndex3];

                        double close3Price = Close[closeBarIndex3];// changed Closes to Close​


                        YES THAT is pretty much what I have and I added the Print (which I had checked overnight to confirm)

                        So prints so Bar number and every min the bar number Print changes - so confirmed correct

                        But my DateTime above is NOT locking to that bar (which using something similar did lock to the bar in my HIghestBar Indicator)

                        How can I Print the Bar number that the time is locked to so I can confirm they are the same or NOT

                        Thanks​

                        Comment


                          #13
                          int closeBarIndex3 = CurrentBars[3] - AnchorONELookBackPeriod;// this is set to 30
                          DateTime time30minAgo = Time[closeBarIndex3];

                          double close3Price = Close[closeBarIndex3];

                          Print("CurrentBars[3] - 5: " + (CurrentBars[3] - 5));
                          Print("CurrentBars[3] - 30: " + (CurrentBars[3] - 30));

                          Print("time30minAgo : " + time30minAgo);
                          Print("Time Index Bar: " + Time[closeBarIndex3]);

                          Print("Double close3Price: " + Close[closeBarIndex3]);

                          Results

                          CurrentBars[3] - 5: 19998
                          CurrentBars[3] - 30: 19973
                          time30minAgo : 4/5/2023 6:31:00 PM
                          Time Index Bar: 4/5/2023 6:31:00 PM
                          Double close3Price: 13061.5​

                          so I AM NOT LOCKING INTO THE TIME this is locking to begin point of the start of the charts 20 days of data​​
                          so this is NOT working correctly -- DateTime time30minAgo = Time[closeBarIndex3];

                          Comment


                            #14
                            int closeBarIndex3 = CurrentBars[3] - AnchorONELookBackPeriod;// ie set to 30
                            DateTime time30minAgo = Times[3][1].AddMinutes(-AnchorONELookBackPeriod);// ie set to 30

                            double close3Price = Close[closeBarIndex3];

                            Print("CurrentBars[3] - 5: " + (CurrentBars[3] - 5));
                            Print("CurrentBars[3] - 30: " + (CurrentBars[3] - 30));
                            Print("closeBarIndex3: " + closeBarIndex3);//int closeBarIndex3 = CurrentBars[3] - AnchorONELookBackPeriod; ie // ie set to 30

                            Print("time30minAgo : " + time30minAgo);


                            Print("Double close3Price: " + Close[closeBarIndex3]);

                            Results

                            CurrentBars[3] - 5: 20015
                            CurrentBars[3] - 30: 19990
                            closeBarIndex3: 19990 << ---- closeBarIndex3 matches bar number of 30 bars ago
                            time30minAgo : 4/26/2023 12:55:00 PM << --- Time is 30 minutes ago
                            Double close3Price: 13061.5

                            So now Bars are correct , time is correct

                            so issue is double close3Price = Close[closeBarIndex3];
                            THIS IS NOT CORRECT PRICE Double close3Price: 13061.5 FROM THE PRINT which is suppose to be 30 bars ago at 4/26/2023 12:55:00 PM ​​

                            Comment


                              #15
                              Hello DTSSTS,

                              Thanks for your notes.

                              closeBar3Index in your script is getting a barIndex value of 19990. Note that this is not a barsAgo value.

                              This means that by calling Close[closeBarIndex3]; you are accessing the close price of the primary series 19990 bars back from the current bar on the chart.

                              Close[barsAgo] uses a bars ago value to get the close price specified by the barsAgo value you supply. It does not use a barIndex value. A barIndex and a barsAgo are not the same things.

                              A barIndex value is the specific bar number on a chart.

                              A barsAgo value is the number of bars back from the current processing bar.

                              For example, say the current bar on the chart is bar 1000. Passing a barsAgo value of 30 to Close[barsAgo] (Close[30]) means that you are accessing the close value 30 bars from the current bar, which would be the close price of bar 970.

                              970 would be the barIndex number of that specific bar, not the barsAgo value.

                              If you want to get the Close price 30 bars ago on the primary series, you would use Close[30].

                              To get the Close price 30 bars ago on the third added series in the script, you would use Closes[3][30].

                              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.

                              Close: https://ninjatrader.com/support/help.../nt8/close.htm
                              Closes: https://ninjatrader.com/support/help...nt8/closes.htm
                              Last edited by NinjaTrader_BrandonH; 04-26-2023, 12:05 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

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              647 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