Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get Day of Month

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

    How to get Day of Month

    Hi, I would like to know how to get the day of month, as I want to know when there is a change of month. Thank you

    #2
    socoso, you can look into the Month portion of the Time[0] DateTime for this task - consider for example :

    if (Time[0].Date.Month > Time[1].Date.Month || Time[0].Date.Month < Time[1].Date.Month)

    Comment


      #3
      Thanks Bertrand.
      Sorry, I'm novice as you may figure out. I´ve written this simple indicator but it doesn´t draw anything.
      protected override void OnBarUpdate()
      {
      if (Time[0].Date.Month > Time[1].Date.Month || Time[0].Date.Month < Time[1].Date.Month) Plot0.Set(1);
      else Plot0.Set(0);


      }

      Comment


        #4
        Are there any errors noted in the log tab of NT's Control Center as you apply this study?

        I suspect you're missing this check here at the start of your OnBarUpdate() -

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post

          Code:
          Time[0].Date.Month < Time[1].Date.Month
          How can I observe this case without using an intra-chart time machine ?

          Comment


            #6
            Should not be needed, as the month portion can be smaller as you observe the Dec > Jan month break, so going from 12 > 1.

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              Should not be needed, as the month portion can be smaller as you observe the Dec > Jan month break, so going from 12 > 1.
              I forgot the month ... but then couldn't we use

              Code:
              if(Time[0].Day < Time[1].Day)
              to detect a new month?

              Comment


                #8
                Originally posted by Harry View Post
                I forgot the month ... but then couldn't we use

                Code:
                if(Time[0].Day < Time[1].Day)
                to detect a new month?
                That should work equally well, methinks.

                Comment


                  #9
                  Harry,

                  Yes, that would work as well.

                  I have provided a sample script of another method of how to detect a new month.

                  This script will detect when its the first of the month thus a new month is checked.
                  Attached Files
                  Cal H.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Cal View Post
                    Harry,

                    Yes, that would work as well.

                    I have provided a sample script of another method of how to detect a new month.

                    This script will detect when its the first of the month thus a new month is checked.
                    This approach may run into problems, if the first day of the month is a Saturday.

                    Comment


                      #11
                      Harry,

                      Yes, I provided the script as an example of another way of detection. However, I can see the problem with the script when indeed the 1st could be a Saturday or even a holiday.

                      I'll keep that in mind in the future for the script.

                      Thanks
                      Cal H.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

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