Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get current time Hour and Minutes, onEachTick Real, Simulation and Playback

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

    Get current time Hour and Minutes, onEachTick Real, Simulation and Playback

    Hello Devs!

    I have a strategy that runs within the OnBarUpdate method and Calculate OnEachTick. I want to know how to obtain the current time each time the OnBarUpdate is executed. I know that by using DateTime.Now I can get the current time of the machine, which is perfect, but I need an equivalent for when the connection is Playback. I have tried using Time[0], but it only shows the date and time when the current candle will close.

    Any ideas on how to do this?

    #2
    Hello Quanto,

    Thank you for your post.

    Although it is not documented in the help guide, the following code is used in the BarTimer indicator to obtain the current time depending on whether it is playback or not:
    Code:
    now = (Cbi.Connection.PlaybackConnection != null ? Cbi.Connection.PlaybackConnection.Now : Core.Globals.Now);
    If the connection is Playback, the current time would be Cbi.Connection.PlaybackConnection.Now. If you are not in playback, you could use Core.Globals.Now.

    Please let us know if we may be of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    80 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    40 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    64 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    66 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    54 views
    0 likes
    Last Post CarlTrading  
    Working...
    X