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 drnoggin, Today, 12:19 PM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by synthhokie, Today, 12:00 PM
        1 response
        16 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by moneyexe, Today, 11:22 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by stevec1824, Today, 11:00 AM
        2 responses
        8 views
        0 likes
        Last Post stevec1824  
        Started by sofortune, Today, 10:05 AM
        2 responses
        14 views
        0 likes
        Last Post sofortune  
        Working...
        X