Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Want to check if the computer clock time is less than a specific time

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

    Want to check if the computer clock time is less than a specific time

    I have the following code:

    if (DateTime.Now.TimeOfDay < ToTime(10, 00, 00))
    {
    Print("Less than");
    }


    and Im getting the following error
    "Operator '<' cannot be applied to operands of type 'System.TimeSpan' and 'int'"

    I thought ToTime would be of type TimeSpane too?

    Whats the correct syntax?

    Thanks

    #2
    Hello achautrans,

    Thank you for your reply.

    ToTime will give you an integer value representing a time. You want to use a TimeSpan:

    if(DateTime.Now.TimeOfDay < new TimeSpan(10, 00, 00))
    {
    //do something
    }

    I would generally advise using the Time series rather than the PC clock time as that will be backtestable.

    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 GussJ, 03-04-2020, 03:11 PM
    15 responses
    3,271 views
    0 likes
    Last Post xiinteractive  
    Started by Tim-c, Today, 02:10 PM
    1 response
    8 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by Taddypole, Today, 02:47 PM
    0 responses
    2 views
    0 likes
    Last Post Taddypole  
    Started by chbruno, 04-24-2024, 04:10 PM
    4 responses
    51 views
    0 likes
    Last Post chbruno
    by chbruno
     
    Started by TraderG23, 12-08-2023, 07:56 AM
    10 responses
    403 views
    1 like
    Last Post beobast
    by beobast
     
    Working...
    X