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

Daylight savings time Arizona

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

    Daylight savings time Arizona

    I am back testing a strategy using minute bars and IQFeed data source from Arizona back testing for 2 years.

    Can I set my offset for date time to 3 hours since that is the current difference between Arizona and EST or do I need to adjust my strategy to change the offset between 2 and 3 on the second Sunday of March and the first Sunday of November?

    Thanks,
    Erik

    #2
    Erik, I'm not sure I follow - are you looking to see your charts in EST instead or why do you consider such options?

    Thanks
    BertrandNinjaTrader Customer Service

    Comment


      #3
      My strategy uses minute bars. Example:

      Determine if OnBarUpdate is firing for a standard hours bar could be written like this:

      Code:
      [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (ToTime(Time[0]) >= 63000 && ToTime(Time[0]) < 125000) {[/SIZE]
      [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]//when day light saving time changes something like this:[/COLOR][/SIZE]
      [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (ToTime(Time[0]) >= 73000 && ToTime(Time[0]) < 135000) {[/SIZE]
      [/COLOR][/SIZE][/COLOR][/SIZE]
      or you could use a function like this so it is not hard coded and you can change it when you start the strategy depending on if it is fall back or spring ahead:
      Code:
      [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] timeOffset = 2;[/SIZE]
      [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]public[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] TimeOffset {[/SIZE]
      [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]get[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] { [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] timeOffset; }[/SIZE]
      [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]set[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] { timeOffset = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]value[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]; }[/SIZE]
      [SIZE=2]}[/SIZE]
      [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]private [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]DateTime[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] GetEastStdTime([/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]DateTime[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] time) {[/SIZE]
      [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] time.AddHours(timeOffset);[/SIZE]
      [SIZE=2]}[/SIZE]
      [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]protected [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]override [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] OnBarUpdate() {[/SIZE]
      [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]try[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] {[/SIZE]
      [SIZE=2]Print([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Format([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Converted {0} {1} to {2}."[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], Time[0].ToShortTimeString(), Time[0].Kind, GetEastStdTime(Time[0]).ToShortTimeString()));[/SIZE]
      [SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]//now you can always use this:[/COLOR][/SIZE]
      [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (ToTime(Time[0]) > 93000 && ToTime(Time[0]) < 155000)[/SIZE]
      [SIZE=2]}[/SIZE]
      [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]catch[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Exception[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ex) {[/SIZE]
      [SIZE=2]Print(ex.ToString());[/SIZE]
      [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]throw[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
      [SIZE=2]}[/SIZE]
      [SIZE=2]}[/SIZE]
      when back testing if I go back a couple years will I need a new method that changes the offset on the second Sunday of March and the first Sunday of November from a 2 to a 3 to make sure I am not looking at pre and/or post data bars?


      Thanks,
      Erik

      Comment


        #4
        Hi Erik, thanks - yes, you would need to apply your custom methods to ensure the correct timestamp is accessed in this case.
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by inanazsocial, Today, 01:15 AM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Jason  
        Started by rocketman7, Today, 02:12 AM
        0 responses
        10 views
        0 likes
        Last Post rocketman7  
        Started by dustydbayer, Today, 01:59 AM
        0 responses
        1 view
        0 likes
        Last Post dustydbayer  
        Started by trilliantrader, 04-18-2024, 08:16 AM
        5 responses
        23 views
        0 likes
        Last Post trilliantrader  
        Started by Davidtowleii, Today, 12:15 AM
        0 responses
        3 views
        0 likes
        Last Post Davidtowleii  
        Working...
        X