Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Session Begin and session End

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

    Session Begin and session End

    Hi guys

    I am testing the new version 7. I am migrating from 6.5 and I have met some problems that I would like to address with you this morning.


    In my old script I was using ChartControl.SessionBegin and ChartControl.SessionEnd that obviously don't work anymore.


    What is the script I should write to get the same result as before.

    I tried GetSession()...... like you mention in your email but get compiled errors


    Thanks

    Bernard

    #2
    Hi blarouche,

    Please try this:

    BarsArray[int barSeries].Session.SessionsOfDay[int dayOfWeek].BeginTime
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Josh



      Here is my old code :

      if(ToTime(Time[0]) >= ToTime(ChartControl.SessionEnd)){
      ...
      }

      Now I should write :

      if(ToTime(Time[0]) >= ToTime(BarsArray[0].Session.SessionsOfDay[3].EndTime));

      int barseries being ?
      int SessionOfDay : I put 3 but I just need to know if we are in a regular session.


      This script didn't work


      Bernard

      Comment


        #4
        blarouche,

        The concept of Session begin/end times is different in NT7. You now have actual session templates that is controlled in the Session Manager window. Before in 6.5, you only had one session setting which was determined by the chart or whatever you set it as when starting the strategy in the Strategies tab. Now, you choose the session template you want to use for the instrument and it has many start/end times depending on the days.

        barSeries refers to which BarsInProgress you are on. If you have a multi series script then you will need to define this as to which instrument you want to be checking. SessionsOfDay[] determines which actually session definition you want to look at. Please open up the Session Manager to get a feel for this. 0 corresponds to the first listed day, 1 the next, etc.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Josh

          OK I understand.
          But my code still don't work.

          I get the following error :

          The best overload method match for NinjaTrader.Indicator.Indicator.ToTime(System DateTime) has some invalid arguments)
          Argument1 : cannot convert from int to System Datetime.

          It seems that my code before was returning a DateTime and now with the new script it is returning an int..


          Bernard

          Comment


            #6
            Bernard,

            That would be correct. Before you were converting the DateTime to an int with ToTime(). Now it is already an int to begin with so you don't need to use ToTime() to further convert it.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Josh

              You're right

              It now works

              Many thanks


              Bernard

              Comment


                #8
                Josh

                Still need help on the following code :


                TimeSpan duration = ChartControl.SessionEnd - ChartControl.SessionBegin;


                I was looking for a duration TimeSpan between End and Start Time of a session.


                What would be the new code ?
                I need to return a DataTime object.


                Bernard

                Comment


                  #9
                  Bernard,

                  These do not return DateTimes. You could try to create your own DateTime by parsing the ints components into hours, minutes, seconds.

                  You could also try BarsArray[int barSeries].Session.NextBeginTime and .NextEndTime which should return DateTimes.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Josh

                    It worked with this :

                    BarsArray[int barSeries].Session.NextBeginTime and .NextEndTime





                    Thank you very much

                    Bernard

                    Comment


                      #11
                      Originally posted by NinjaTrader_Josh View Post
                      Bernard,

                      That would be correct. Before you were converting the DateTime to an int with ToTime(). Now it is already an int to begin with so you don't need to use ToTime() to further convert it.

                      Does it mean if you upgrade to 7 you will have to re-write many of home growth indicator?

                      Comment


                        #12
                        nkhoi, for some scripts this is correct - to see code breaking changes, please consult this document which we update as we move forward - http://www.ninjatrader-support2.com/...ad.php?t=21016

                        Comment


                          #13
                          SMA of Prior Sessions Daily Range for intraday

                          Hello Mr Bertrand,

                          I am hopelesly stuck with trying to code SMA of prior 7 sessions range. Line bellow does not return any value?
                          double
                          rangeB = PriorDayOHLC().PriorOpen[0]-PriorDayOHLC().PriorLow[0];

                          I have seen your sugestions on using
                          Bars.GetSessionBar as well as SampleGetHighLowbyTimeRange, but I am still confused as to implementation of SMA of prior DAILY range?
                          I know that NinjaTrader 7 supports this better. I really need your sugestions to above or perhaps help to get beta 7.

                          Thank you.

                          Gene.

                          Comment


                            #14
                            Please check your Control Center logs for any runtime errors.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Daily range calculation for intraday chart

                              Good Morning Bertrand,

                              You have not reply to my last messages. If you can please look at the code below. I took it from the sample code and tried to adapt it for Open-Low Daily range for intraday chart. It doesn't plot ???


                              if (EndHour < StartHour)
                              return;

                              if (ToTime(EndHour, EndMinute, 0) > ToTime(Time[0]))
                              return;

                              if (startDateTime.Date != Time[0].Date)
                              {
                              startDateTime =
                              new DateTime(Time[0].Year, Time[0].Month, Time[1].Day, StartHour, StartMinute, 0); //changed to Time[1].Day???
                              endDateTime =
                              new DateTime(Time[0].Year, Time[0].Month, Time[4].Day, EndHour, EndMinute, 0);//Time[12].Day
                              }

                              // Calculate the number of bars ago for the start and end bars of the specified time range
                              int startBarsAgo = GetBar(startDateTime);
                              int endBarsAgo = GetBar(endDateTime);



                              double smaLow = SMA(Low,startBarsAgo - endBarsAgo)[endBarsAgo];
                              double smaOpen = SMA(Open,startBarsAgo - endBarsAgo)[endBarsAgo];


                              double Myrange = (smaOpen-smaLow);




                              double x = Open[0] - Myrange;

                              MyNumber.Set(x);


                              Thank you for Help,

                              Ytrender

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              628 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              359 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              105 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              562 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              568 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X