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 Balage0922, Today, 07:38 AM
                      0 responses
                      1 view
                      0 likes
                      Last Post Balage0922  
                      Started by JoMoon2024, Today, 06:56 AM
                      0 responses
                      6 views
                      0 likes
                      Last Post JoMoon2024  
                      Started by Haiasi, 04-25-2024, 06:53 PM
                      2 responses
                      19 views
                      0 likes
                      Last Post Massinisa  
                      Started by Creamers, Today, 05:32 AM
                      0 responses
                      6 views
                      0 likes
                      Last Post Creamers  
                      Started by Segwin, 05-07-2018, 02:15 PM
                      12 responses
                      1,786 views
                      0 likes
                      Last Post Leafcutter  
                      Working...
                      X