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 mattbsea, Today, 05:44 PM
        0 responses
        3 views
        0 likes
        Last Post mattbsea  
        Started by RideMe, 04-07-2024, 04:54 PM
        6 responses
        31 views
        0 likes
        Last Post RideMe
        by RideMe
         
        Started by tkaboris, Today, 05:13 PM
        0 responses
        2 views
        0 likes
        Last Post tkaboris  
        Started by GussJ, 03-04-2020, 03:11 PM
        16 responses
        3,282 views
        0 likes
        Last Post Leafcutter  
        Started by WHICKED, Today, 12:45 PM
        2 responses
        20 views
        0 likes
        Last Post WHICKED
        by WHICKED
         
        Working...
        X