Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SessionIterator - GetTradingDay() not working as documented

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

    SessionIterator - GetTradingDay() not working as documented

    Hi,
    When using the SessionIterator to get the current exchange date using the GetTradingDay() method, gives next day's date. I am need to get the current session date of the exchange and not the local time. Am I doing something wrong?
    See code extract below;
    Code:
    if (State == State.Historical)
    			{
    				    sessionIterator = new SessionIterator(BarsArray[0]);
    			}
    protected override void OnBarUpdate()
    {
    
    string DateofDay = "\n-------------"
    				+"\n " + sessionIterator.GetTradingDay(DateTime.Now).ToString("dd MMM yyyy");
    }

    #2
    Hello kashter,

    Thanks for your post.

    Your code example does provide the current trading day.

    Please verify that your PC clock is set to the correct time zone and retest. If the results are incorrect, please specify your time zone and instrument(s) tested.

    I ran a test with your code on the NQ 09-18, I am on Mountain time and it provided the current trading day of 06-18-2018.

    Comment


      #3
      Paul,
      My PC is set to local time, AEST UTC+10. I tested the code against more than one instrument, all returning tomorrow's date.

      Comment


        #4
        Hello kashter,

        Thanks for your reply.

        With your time zone, this would be expected. Please see note 2 here: https://ninjatrader.com/support/help...ayexchange.htm

        You do have the option in NinjaTrader8 to set a different time zone for your charts. This can be done in Tools>Options>General.

        Comment


          #5
          Paul,
          Ok thanks for the clarification on the limitation of the GetTradingDay() method. I am aware of setting the timezone for the charts. But I wanted was a way to verify what day data was on the chart so as to apply some other logic to my charts. Would you be able to provide a workaround in place of the GetTradingDay() to identify the current active exchange session date? Thanks.

          Comment


            #6
            Hello kashter,

            Thanks for your reply.

            Would suggest using Bars.IsFirstBarOfSession and then getting the next trading day based on that bar.

            if (Bars.IsFirstBarOfSession)
            {
            string DateofDay = "\nFBOS Date: "+Time[0]+"\nTrading day" + sessionIterator.GetTradingDay(Time[0]).ToString("dd MMM yyyy");

            Print (DateofDay);
            }

            Comment


              #7
              Thanks Paul for the suggested code. I will give it a try and report back.

              One followup question if you may. I have data that I read off a text file that I need to plot on the chart by date. In other words the plots should only show up for the dates of the data corresponding data. I do not want the plots to traverse across multiple days. How can I achieve this once I now what the current session date is? See below for an example of the text file data;
              Date Data1 Data2
              20180615 2763.25 2769.50
              20180614 2771.50 2777.75

              Thanks.
              Last edited by kashter; 06-18-2018, 09:02 AM.

              Comment


                #8
                Hello kashter,

                Thanks for your reply.

                The example I provided will roll through the historical data and provide the trading day based on the first bar of the session. In re-reading your post I wonder if it may not be better to first test for real time data and then get the first bar of the session, here is the code to try that:

                if (State == State.Realtime)
                {
                string DateofDay = "\nFBOS Date: "+Time[Bars.BarsSinceNewTradingDay]+"\nTrading day"
                + sessionIterator.GetTradingDay(Time[Bars.BarsSinceNewTradingDay]).ToString("dd MMM yyyy");

                Print (DateofDay);
                }


                Regarding the plots, you'll need to clarify what you are meaning by plots. Are these lines to plot from one date to the next or just a dot or other marker at the specified date and time? The reason for asking is that plot methods can plot a limited type of objects whereas the Draw methods offer a variety of draw types but the use of draw methods versus plots somewhat could depend on the number of objects. Feel free to show a chart example for clarity, thanks.

                edit: corrected grammer.
                Last edited by NinjaTrader_PaulH; 06-18-2018, 09:30 AM.

                Comment


                  #9
                  Paul,
                  The plots are essentially regions (I would love to use the RegionHighlightY but I am confused as to how to use it) that depicts the unique data across each day session. I say regions because I need to plot the data across a span of +/- 2 ticks (for example in ES with data of 2763.25, the region I need is from 2762.75 to 2763.75 to be plotted). Each data set need to only show in its corresponding day, and not spill over to other days. See attached image for clarification.

                  Hope the above helps to clarify what I am after.
                  Attached Files

                  Comment


                    #10
                    Hello kashter,

                    Thanks for your reply.

                    Yes, RegionHighlight would not work here because like the horizontal line it extends both ways without end. You would need to use Draw.Rectangle: https://ninjatrader.com/support/help..._rectangle.htm

                    You would also want to use Bars.IsFirstBarOfSession to know when to begin for the current session as well as to end for the prior session as the indicator progresses through the bars drawing the rectangles.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    656 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    371 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
                    579 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X