Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtest time vs strategy code time

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

    Backtest time vs strategy code time

    Forgive me is this has been covered before. Let's say I have a script such as SampleGetHighLowByTimeRange_NT8 which defines specific times in the code. I assume these times are specific to the local time of the users computer? Yet if you run this strategy in a backtest, you are able to select a different time zone for the strategy to run.

    So if my Local time is UTC +2. And I run my backtest with a UTC-5 setting to test on the ES. The times in my code are off by 7 hours compared to the backtest time. Right?

    So if I only want to submit trades at a specific time, I have to do so in my code to offset the 7 hours. ie, If I want to trade @ 08:30 exchange time, in my code this time is actually 15:30 locally.

    This seems to become problematic when it comes to daylight saving hours. The exchange time zone changes clocks on Sun, Mar 10, 2024 & Sun, Nov 3, 2024. Whereas my local timezone changes on Sun, Mar 31, 2024 & Sun, Oct 27, 2024​. So this would mess up the 7 hour offset when these event occur.

    Am I understanding this correctly? The solution would be to set my local clock to the same timezone as the exchange or use code to convert my UTC+2 time to UTC-5 or whatever time I want to run my backtest on?

    #2
    Hello several,

    The times you use in code are not related to the PC time, those times will relate to the bar times.

    The timezone you set in the control center options menu is used to offset the chart times based on the timezone you set, the PC clock time is not used at all in relation to NinjaScript.

    Comment


      #3
      Thanks. I understand but the question still remains. If the setting in control centre as the same as my PC, then the question is the same is it not?

      In order to have coded times in strategies match the time of the instrument/backtest time, then you have to change the time setting in control centre to make it match the same time as the backtest/instrument time?

      But this doesn't seem like a possible solution if you're running strategies on multiply instruments and each instrument runs in a different timezone.

      If I'm running a strategy on ES, I can set the time in control centre to be the same as the ES time zone. (UTC-5) but now the whole app is in UTC-5, and all the times coded into my strategies are relative to this time right?

      I want it to be relative to the instrument time, whatever instrument I'm running the strategy on.

      Comment


        #4
        Hello several,

        The time of the bar is already converted to your local time zone.
        In backtest, the historical data is also in your local time zone.

        If you want to submit orders from 15:30 to 19:00 in your local time zone, this is what should be compared in the conditions.

        if (ToTime(Time[0]) >= 153000 && ToTime(Time[0]) < 190000)


        "If I'm running a strategy on ES, I can set the time in control centre to be the same as the ES time zone. (UTC-5) but now the whole app is in UTC-5, and all the times coded into my strategies are relative to this time right?"

        This is correct, if the local time zone in the Control Center is set to the EDT time zone, then the whole application including the bar times will be in EDT (for all exchanges even those that are not in eastern time such as the CME).
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I think I'm confusing myself. So the back test converts the instruments trading hours to my time zone? How does it account for daylight saving?

          What I don't understand is, how would I submit an order exactly at market open time every single day for the last 10 years? I know exactly the market opens at 09:30 ET but this time isn't always in sync with my time zone.

          Currently this is 15:30 for me, but on October 27th it changes to 14:30 as my clocks go back 1 hour. And then don't the US clocks change on November 3rd? How does the strategy take all this into account historically?

          Comment


            #6
            Hello several,

            To submit an order at the open time you will need to view what that time is in the chart. For example if an instruments open time is 8 am and you see that the time was 8am in the chart that is the time you would use in NinjaScript. You need to use the times you see on the chart for any conditions you make. You can completely ignore your PC clock times and focus only on the chart times when using NinjaScript.

            Comment


              #7
              I understand, the problem is the time zone offset between my time and the exchange time is not consistent.

              For example, for 99% of the year the open time for me is 15:30, but for 1% of the year it's 14:30. So if I write a backtest to submit an order everyday at 15,30,00 my time, then for 99% of the days the order will be submitted at 09:30 exchange time. But for 1% of days it will be actually submitted at 10:30 exchange time.

              I guess it just seems to be the simplest solution to set NT time to the same time as the exchange, or else I would have to write code to deal with the above.
              Last edited by several; 10-29-2024, 05:06 AM.

              Comment


                #8
                Hello several,

                The platform handles those offsets to display the chart, that will not be relevant to your scripts. If the time you want to use is 15:30 on the chart that is the time you would use in NinjaScript. Your code needs to match the times you see on the chart, not your PC clock time or offsets based on that time.

                Comment


                  #9
                  Hello, Please see screenshot of backtest result from a 5 minute chart. Note the vertical lines are the EOD session break.

                  The script is set enterLong @ 23:00 and exitLong @ 00:15. This would submit an order immediately at open after the session break, and then exit 15 minutes later.

                  As you can see the Exit of the order on the right occurs 1 hour later than the ones on the left relative to the underlying. So from a backtest perspective this is not desired as the chart time has changed from one day to the other. This is my whole question, it's that the app/or my code only works when the offset between the chart tme and the exchange time is 100% consistently the same, but it's not.
                  Attached Files
                  Last edited by several; 10-29-2024, 09:24 AM.

                  Comment


                    #10
                    Hello several,

                    From the image I can't tell what series is being used or how the logic you made executed when run to be able to say why the entries and exits happened that way. You can use a Print to evaluate how the script ran in that use can and make any adjustments needed to your time based conditions to match how you wanted it to work surrounding the chart times.

                    Comment


                      #11
                      I'm not sure we are understanding each other.

                      The script has zero conditions. It just enter/exits at those times, and the chart is the ES. It works exactly as it should. I'm just showing it to you to illustrate the point I'm trying to make.

                      If I write in my script to submit an order at 23:00 every single day. For 99% of the year this order will be submitted at the opening of the session @ 17:00 CT. However, there are a handful of days which this order will submit 1 hour later after opening. This is due to the fact that the timezone of my chart does not have a consistent offset with the timezone of the ES exchange for a few days because the clocks are modified differently. I believe the CT clocks change this upcomming weekend, my clocks changed last weekend.

                      This is why the order in the screenshot is different. I'm simply seeking to understand how to deal with this in relation to NT strategies because if I write a backtest to submit at order at open(or at another specific time), clearly I cannot simply write 1 time.
                      Last edited by several; 10-29-2024, 09:55 AM.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by NullPointStrategies, Today, 05:17 AM
                      0 responses
                      25 views
                      0 likes
                      Last Post NullPointStrategies  
                      Started by argusthome, 03-08-2026, 10:06 AM
                      0 responses
                      121 views
                      0 likes
                      Last Post argusthome  
                      Started by NabilKhattabi, 03-06-2026, 11:18 AM
                      0 responses
                      64 views
                      0 likes
                      Last Post NabilKhattabi  
                      Started by Deep42, 03-06-2026, 12:28 AM
                      0 responses
                      41 views
                      0 likes
                      Last Post Deep42
                      by Deep42
                       
                      Started by TheRealMorford, 03-05-2026, 06:15 PM
                      0 responses
                      46 views
                      0 likes
                      Last Post TheRealMorford  
                      Working...
                      X