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

Intrabar time

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

    Intrabar time

    Hi,

    Is there any way to find out intrabar time natively?

    E.g., a minute bar 13:01:00 opens at 13:00:00 and closes at 13:00:59.

    Assume there are 5 intra bar ticks in between, occurring at 13:00:10/20/30/40/50

    I would like to find out the time of each tick for both realtime and replay modes.

    P.S. There is a way to calc that for real-time mode by using local time but I would prefer to have a solution that works a) for Replay mode too b) that is more or less native, i.e. involving minimum of code

    Thanks!

    #2
    Originally posted by alex.nt View Post
    Hi,

    Is there any way to find out intrabar time natively?

    E.g., a minute bar 13:01:00 opens at 13:00:00 and closes at 13:00:59.

    Assume there are 5 intra bar ticks in between, occurring at 13:00:10/20/30/40/50

    I would like to find out the time of each tick for both realtime and replay modes.

    P.S. There is a way to calc that for real-time mode by using local time but I would prefer to have a solution that works a) for Replay mode too b) that is more or less native, i.e. involving minimum of code

    Thanks!
    This will create a property called Now, which you can query.
    Code:
    [FONT=Courier New]
    [/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]private[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] DateTime Now
    {
    [/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]get[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] 
    { 
    DateTime now = (Bars.MarketData.Connection.Options.Provider == Cbi.Provider.Replay ? Bars.MarketData.Connection.Now : DateTime.Now); 
    [/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] (now.Millisecond > [/FONT][FONT=Courier New][COLOR=#800080][FONT=Courier New][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New])
    now = Cbi.Globals.MinDate.AddSeconds(([/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]long[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New]) System.Math.Floor(now.Subtract(Cbi.Globals.MinDate).TotalSeconds));
    [/FONT][FONT=Courier New][COLOR=#0000ff][FONT=Courier New][COLOR=#0000ff]return[/COLOR][/FONT][/COLOR][/FONT][FONT=Courier New] now;
    }
    }
    [/FONT]

    Comment


      #3
      Good one, thanks!

      Could you please explain the point behind removing milliseconds?

      Comment


        #4
        Originally posted by alex.nt View Post
        Good one, thanks!

        Could you please explain the point behind removing milliseconds?
        By using the Math.Floor() function, we force the granularity to the same as the barData.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by llanqui, Today, 03:53 AM
        0 responses
        5 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Started by burtoninlondon, Today, 12:38 AM
        0 responses
        10 views
        0 likes
        Last Post burtoninlondon  
        Started by AaronKoRn, Yesterday, 09:49 PM
        0 responses
        15 views
        0 likes
        Last Post AaronKoRn  
        Started by carnitron, Yesterday, 08:42 PM
        0 responses
        11 views
        0 likes
        Last Post carnitron  
        Started by strategist007, Yesterday, 07:51 PM
        0 responses
        14 views
        0 likes
        Last Post strategist007  
        Working...
        X