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 rhyminkevin, Today, 04:58 PM
        4 responses
        52 views
        0 likes
        Last Post dp8282
        by dp8282
         
        Started by iceman2018, Today, 05:07 PM
        0 responses
        5 views
        0 likes
        Last Post iceman2018  
        Started by lightsun47, Today, 03:51 PM
        0 responses
        7 views
        0 likes
        Last Post lightsun47  
        Started by 00nevest, Today, 02:27 PM
        1 response
        14 views
        0 likes
        Last Post 00nevest  
        Started by futtrader, 04-21-2024, 01:50 AM
        4 responses
        50 views
        0 likes
        Last Post futtrader  
        Working...
        X