Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

the last day of week and the last week of month

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

    the last day of week and the last week of month

    hi,
    chart is setting daily bar

    i want to know the last day of week trading and the last week of month trading

    (i don't want to use AddSeries(weekly..) AddSeries(monthy..,,)

    how i code it?
    Last edited by esignal; 09-26-2017, 07:43 AM.

    #2
    Hello esignal,

    Thanks for opening the thread.

    You can get the expiration month for an Instrument using the Expiry property. The DateTime object returned can then be used to calculate when your last week of trading for that month is.

    As for detecting the last day of a trading week, you can access the TradingHours property of a Bars object to see detail on the Trading Hours Sessions so you can observe when the last day of the last session (last day of trading trading week) is.

    Instrument.Expiry - https://ninjatrader.com/support/help...-us/expiry.htm

    TradingHours.Sessions - https://ninjatrader.com/support/help...s_sessions.htm

    Please let me know if I can be of further assistance.

    Comment


      #3
      i print this code in my indicator


      for (int i=0;i<5;i++)
      {
      Print("begin " + i + " " +Bars.TradingHours.Sessions[i].BeginDay);
      Print("end " + i + " "+Bars.TradingHours.Sessions[i].EndDay);

      }
      Output:


      but i don't understand the output...Begin and End is the same

      can you help me how i code Bars.TradingHours.Sessions to find last day of week? i don't understand..

      thank
      Last edited by esignal; 09-26-2017, 12:29 PM.

      Comment


        #4
        Originally posted by esignal View Post
        hi,
        chart is setting daily bar

        i want to know the last day of week trading and the last week of month trading

        (i don't want to use AddSeries(weekly..) AddSeries(monthy..,,)

        how i code it?
        Is finding the last trading day of the week not just checking if it is a Friday?

        To find if a day is in the last week of the month, you just need to check if the month of the date is different from the month of the date 7 days hence.

        Code:
        if (Time[0].Month != Time[0].AddDays(7).Month)
        {
        //this is the last week of the month
        }
        Be sure that the Calculate property is correctly set for whatever it is that you want to do.

        Comment


          #5
          you say : Is finding the last trading day of the week not just checking if it is a Friday?

          It's ok but if friday is Holiday it is not correct

          should I use the default setting of holidays and since can be incorrect I'd rather use other
          Last edited by esignal; 09-26-2017, 02:13 PM.

          Comment


            #6
            Hello esignal,

            You can use TradingHours.Sessions.Count-1 to get the index for the last Trading Session (trading day.)

            Code:
            Print("LastSesh " + (TradingHours.Sessions.Count-1) + " " + Bars.TradingHours.Sessions[TradingHours.Sessions.Count -1].EndDay);
            LastSesh 4 Friday
            For detecting trading holidays in particular, I would suggest to access the Holidays property from TradingHours and checking the DateTime objects in the Holidays collection. Example code to print each holiday in the collection can be found in the Help Guide.

            TradingHours.Holidays - https://ninjatrader.com/support/help...s/holidays.htm

            If there is any thing else I can do to assist, please let me know.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by charlesugo_1, 05-26-2026, 05:03 PM
            0 responses
            73 views
            0 likes
            Last Post charlesugo_1  
            Started by DannyP96, 05-18-2026, 02:38 PM
            1 response
            152 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 05-11-2026, 05:56 AM
            0 responses
            162 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 05-10-2026, 08:12 PM
            0 responses
            100 views
            0 likes
            Last Post CarlTrading  
            Started by Hwop38, 05-04-2026, 07:02 PM
            0 responses
            288 views
            0 likes
            Last Post Hwop38
            by Hwop38
             
            Working...
            X