• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How can I get the current time of the broker (server) in the format "HH:mm:ss".

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

    How can I get the current time of the broker (server) in the format "HH:mm:ss".

    How can I get the current time of the broker (server) in the format "HH:mm:ss". When I get Time[0].ToString("HH:mm:ss") even using Calculate.OnEachTick, I only get hours and minutes, without seconds.

    #2
    Hello Goolden,

    Thank you for your post.

    What time frame are you running your script on, generally?

    For example, let's say I have an ES 12-19 15 minute chart, and I put this in On Bar Update:

    Print(Time[0].ToString("HH:mm:ss.FFF"));

    Assuming there's no secondary series or bars in progress checks, even if you set the script to calculate on each tick, this will just repeatedly print the closing time of the bar. This isn't the current time - Time[0] will always give you the closing time of the current bar, so even running on each tick that's not going to change.

    If you want to print what time each tick comes in you've got some options.

    System.DateTime.Now.TimeOfDay will print you the hours, minutes, seconds, and milliseconds.

    If you're interested in knowing when each tick came in, you can add a single tick data series in State == State.Configure and then print the time only when that series is being processed:

    Code:
                else if (State == State.Configure)
                {
                    AddDataSeries(BarsPeriodType.Tick,1);
                }
            }
    
            protected override void OnBarUpdate()
            {
                if(BarsInProgress ==1)
                {
                    Print(Time[0].ToString("HH:mm:ss.FFF")); // example result: 08:10:22.025; these results may vary depending on your data provider and how/if they timestamp the data.
                }
    
                Print(System.DateTime.Now.TimeOfDay); // example result: 08:10:22.1080620
            }
    Whether or not your provider timestamps the data on their end is listed in our help guide here:

    https://ninjatrader.com/support/help...y_provider.htm

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by StevenNelson, Today, 03:05 PM
    0 responses
    5 views
    0 likes
    Last Post StevenNelson  
    Started by Benjaminf, Today, 02:21 PM
    1 response
    8 views
    0 likes
    Last Post NinjaTrader_Kate  
    Started by grayfrog, 05-24-2020, 09:29 PM
    5 responses
    32 views
    0 likes
    Last Post NinjaTrader_RyanS  
    Started by chrismcdermut, Today, 01:46 PM
    1 response
    8 views
    0 likes
    Last Post NinjaTrader_Kate  
    Started by dpolyakov, Today, 01:13 PM
    3 responses
    15 views
    0 likes
    Last Post dpolyakov  
    Working...
    X