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 pibrew, Today, 06:37 AM
        0 responses
        0 views
        0 likes
        Last Post pibrew
        by pibrew
         
        Started by rbeckmann05, Yesterday, 06:48 PM
        1 response
        12 views
        0 likes
        Last Post bltdavid  
        Started by llanqui, Today, 03:53 AM
        0 responses
        6 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Started by burtoninlondon, Today, 12:38 AM
        0 responses
        11 views
        0 likes
        Last Post burtoninlondon  
        Started by AaronKoRn, Yesterday, 09:49 PM
        0 responses
        15 views
        0 likes
        Last Post AaronKoRn  
        Working...
        X