Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Start of New Trading Session

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

    Start of New Trading Session

    Hello,
    I'm trying to have an indicator that calculates from time based bars to run on a renko chart.
    I am looking for the indicator to start calculating after a certain number of bars elapse on the Time based chart then plot on the renko chart.
    Everything plots and functions correctly except at the initial start of the trading session. It doesn't seem to be able to count the number of time elapsed bars or something.
    I've tried a few variations of the code below. Am I not understanding something here or using the functions incorrectly?

    if ((Bars.BarsSinceNewTradingDay >= MinBars && CurrentBars[iDataSeries] >= MinBars )

    && (Lows[iDataSeries][0] > Highs[iDataSeries][2]))​

    Thank you for any help with this issue.
    Happy Holidays!
    Regards,
    James

    #2
    Hello James,

    Are you trying to count the number of bars for a secondary series?

    Perhaps you were wanting BarsArray[iDataSeries].BarsSinceNewTradingDay?
    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Chelsea,
      Thank you very much. Yes, I was trying that but had it reversed. I believe this will get everything to work correctly.
      Thank you again, and have a safe and fun New Year!
      Regards,
      James

      Comment


        #4
        Good morning Chelsea,
        I thought I had it all figured out.
        It didn't function like I had thought. I added the Array but it is still not counting from the start of the RTH trading day. Here is what I have (see below). If you have any ideas I would be very thankful.
        Regards,
        James

        if ((BarsArray[iDataSeries].BarsSinceNewTradingDay >= MinBars )

        && (Lows[iDataSeries][0] > Highs[iDataSeries][2]) && (IntradaySession == true))

        Comment


          #5
          The interesting thing is that if I reload the script after the RTH open it seems to work but if the RTH open starts it doesn't.

          Comment


            #6
            Hello laoshr,

            If you have data series using different trading hours, OnBarUpdate() will not update until all series are in session.

            From the Desktop SDK:
            "If your NinjaScript object is using AddDataSeries() allowing to specify a tradingHoursName, please keep in mind that: An indicator / strategy with multiple DataSeries of the same instrument will only process realtime OnBarUpdate() calls when a tick occurs in session of the trading hour template of all added series. Any ticks not processed will be queued and processed as a tick comes in for all subsequent DataSeries."
            Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


            Once all series are in session, any queued bar updates will be processed.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thank you Chelsea for the information.
              I’ve seen a lot of indicators use a time statement. Do you think that would be better here when trying to have something plot from another data series?

              Comment


                #8
                Hello laoshr,

                Plots will only update with the primary series.

                Below is a link to an example that plots values from a different time frame on the chart.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks again Chelsea. I will review the information and see what I can come up with.
                  Regards,
                  James

                  Comment


                    #10
                    Good morning,
                    I've been trying everything I can to get it to count the secondary series (5min bars) on the renko chart. Here is what I thought would work but it did not. Any help would be greatly appreciated.

                    if ((BarsArray[iDataSeries].BarsSinceNewTradingDay >= MinBars )
                    && (Lows[iDataSeries][0] >= Highs[iDataSeries][2] + MinimumGapSize*TickSize)
                    && (IntradaySession == true)
                    && (currentTime >= SessionStartTime && currentTime <= SessionEndTime))

                    Thank you for your time.
                    Regards,
                    James​

                    Comment


                      #11
                      Hello James,

                      What value is unexpected?

                      Add debugging prints to understand why the branching command is not evaluating as true.

                      Print the time of the bar and all values compared in the conditions with labels for each value and comparison operator.

                      Below is a link to a support article on adding debugging prints to understand behavior and includes sample code.


                      Save the output to a text file (right-click the output window > select Save as) and attach the text file to your next post.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Chelsea,
                        I have a question. I've tried to figure out how to reference the Time of the close after 2 bars of BarsArray[iDataSeries] and then make sure that bars close is after a start of the RTH session (9:30 AM EST). Could you help with understanding this?
                        Thank you again for your time.
                        Regards,
                        James

                        Comment


                          #13
                          Hello James,

                          BarsArray[int index] is a Bars object collection of all price series, including primary series and all price series added with AddDataSeries() type methods.
                          This is indexed by the order price series are added with AddDataSeries(), BarsInProgress is the index of the series updating OnBarUpdate().
                          The primary series (chart bars) are index 0. BarsArray[0] is the Bars object of the primary series.
                          The first added series with AddDataSeries() is index 1, BarsArray[1]. The second added series is index 2, BarsArray[2].

                          Closes is a Series<double> collection of price series of all price series, but specifically the close price of the bar for each price series.
                          This is indexed by the price series index, and then barsAgo index.
                          Closes[price series index][int barsAgo]

                          Closes[0] is a Series<double> object, the entire close series of the primary bars.
                          Closes[0][0] is a double, the most recently updated bar close price of the primary bars.
                          Closes[1][0] would be the most recently updated close price of the added price series with the first call of AddDataSeries().
                          Closes[2][1] would be the previous updated close of the second price series added with AddDataSeries().

                          Times[1] is a Series<Time> object, the entire time series of the second bar series (first series added with AddDataSeries()).
                          Times[1][0] is a DateTime object, the date and time of the most recently updated bar of second bar series (first series added with AddDataSeries()).

                          See the following article on how Series work.



                          Use BarsArray[price series index].BarsSinceNewTradingDay to get the number of bars from the start of a session.
                          Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


                          Times[1][BarsArray[1].BarsSinceNewTradingDay] would be the time of the first bar of the current session of the second series (first series added with AddDataSeries()).


                          A SessionIterator can be used to retrieve the open time of a session.
                          Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.

                          Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.



                          ""the Time of the close after 2 bars of BarsArray[iDataSeries]"

                          After a bar closes for a specific series, you want to want to set a trigger that will trigger an action after two more bars have closed?

                          Assuming you want the second series (first series added with AddDataSeries()):

                          private bool setTrigger;
                          private int counter;

                          In OnBarUpdate():

                          if (CurrentBars[1] < 1 || BarsInProgress != 1)
                          return;

                          if (setTrigger == false)
                          {
                          setTrigger = true;
                          counter = 0;
                          }
                          else if (counter < 2)
                          {
                          counter++;
                          }
                          else
                          {
                          // trigger action
                          Print("Time of bar two bars after trigger bar: " + Times[1][0].ToString());
                          setTrigger = false;
                          }


                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Chelsea,
                            Thank you for all the information. I think I got it to work as needed. I have a question. I noticed this morning when I loaded the chart that the UI time input was stripped out and set back to the default. I'm not sure why this would happen. Have you seen this? And if so, is there something I need to ensure it saves with the template and workspace?
                            Thank you again for your time.
                            Regards,
                            James

                            Comment


                              #15
                              Hello James,

                              Have you property serialized the TimeSpan input?
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              557 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              324 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              545 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              547 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X