Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Time based strategy

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

    Time based strategy

    For strategies that are time based, is there anything that should be done in the code to account for day light savings time changes or time zones?

    #2
    Hello jg123,

    Thank you for your post.

    NinjaTrader will calculate data based on your PC clock settings, so there is no need to adjust for Daylight Savings Time in your code.

    Comment


      #3
      Great thank you. That is very good to know.

      It seems like there still may be benefit to account for that in the code as various countries adjust their times on different weeks. For example, an indicator or strategy that looks to take advantage of the London opening time would be ineffective for people living in America during the 2 week discrepancy in changes.

      Is there a way of taking care of this in the code?

      Comment


        #4
        Hello jg123,

        Thank you for your response.

        Unfortunately, it would not be possible to change the session template within the code to adjust for the difference in two time zones. Your PC time and the session templates time zone should properly convert when being displayed on the chart. Are you running into an instance where this is not occurring? Are you using any custom session templates?

        Comment


          #5
          At this point I am not using any templates.

          My main thought is that I live in Europe and next week I will be flying to America for a couple of weeks. America has already done its time change to Daylight Savings and England has not - but it will while I am there.

          While I am there, the 08:00 UK time bar will be equivalent to the 03:00 bar on my computer and chart - but after UK time change occurs, it will be equivalent to my 02:00 computer and chart time. Very soon I will be writing an indicator that will create a box around the times that I need to be paying attention to and I expect that this will influence its ability to work correctly.

          This is the discrepancy that I am trying to work out if possible.

          Comment


            #6
            Originally posted by jg123 View Post
            At this point I am not using any templates.

            My main thought is that I live in Europe and next week I will be flying to America for a couple of weeks. America has already done its time change to Daylight Savings and England has not - but it will while I am there.

            While I am there, the 08:00 UK time bar will be equivalent to the 03:00 bar on my computer and chart - but after UK time change occurs, it will be equivalent to my 02:00 computer and chart time. Very soon I will be writing an indicator that will create a box around the times that I need to be paying attention to and I expect that this will influence its ability to work correctly.

            This is the discrepancy that I am trying to work out if possible.
            Wouldn't leaving your PC in your local time zone solve all the issues?

            Comment


              #7
              Yes, sledge. That would be no problem for me to just leave my computer to my home timezone.

              Comment


                #8
                Hello jg123,

                Thank you for your response.

                As sledge suggested you can leave the computer on the time zone it has always been on. However, if you want to change the time zone you could incorporate user defined variables in your indicator that will allow you to specify the times for the begin and end Ys for the rectangles.

                Comment


                  #9
                  Thanks Patrick

                  That sounds very interesting.

                  Can you give an example of what kind of user defined variables to accomplish this?

                  Comment


                    #10
                    Hello jg123,

                    Thank you for your response.

                    The following is an example of user definable ints that allow us to check within a certain time frame on our charts:
                    Code:
                            #region Variables
                    		private int beginTime = 83000;
                    		private int endTime = 170000;
                            #endregion
                    
                    
                            protected override void Initialize()
                            {
                    			
                            }
                    
                            protected override void OnBarUpdate()
                            {
                    			if(ToTime(Time[0]) >= beginTime && ToTime(Time[0]) <= endTime)
                    			{
                    				// do something
                    			}
                            }
                    
                            #region Properties
                    		[Description("Begin Time")]
                    		[GridCategory("Parameters")]
                    		public int BeginTime
                    		{
                    			get { return beginTime; }
                    			set { beginTime = Math.Max(1, value); }
                    		}
                    		[Description("End Time")]
                    		[GridCategory("Parameters")]
                    		public int EndTime
                    		{
                    			get { return endTime; }
                    			set { endTime = Math.Max(1, value); }
                    		}
                            #endregion

                    Comment

                    Latest Posts

                    Collapse

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