Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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)
    BertrandNinjaTrader Customer Service

    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() -

        BertrandNinjaTrader Customer Service

        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.
            BertrandNinjaTrader Customer Service

            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 ghoul, Today, 06:02 PM
                      0 responses
                      7 views
                      0 likes
                      Last Post ghoul
                      by ghoul
                       
                      Started by Barry Milan, Yesterday, 10:35 PM
                      6 responses
                      18 views
                      0 likes
                      Last Post Barry Milan  
                      Started by DanielSanMartin, Yesterday, 02:37 PM
                      2 responses
                      13 views
                      0 likes
                      Last Post DanielSanMartin  
                      Started by DJ888, 04-16-2024, 06:09 PM
                      4 responses
                      13 views
                      0 likes
                      Last Post DJ888
                      by DJ888
                       
                      Started by terofs, Today, 04:18 PM
                      0 responses
                      12 views
                      0 likes
                      Last Post terofs
                      by terofs
                       
                      Working...
                      X