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 rjbtrade1, 11-30-2023, 04:38 PM
    2 responses
    75 views
    0 likes
    Last Post DavidHP
    by DavidHP
     
    Started by Stanfillirenfro, Today, 07:23 AM
    3 responses
    12 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by FitSpressoHonest, Today, 09:14 AM
    0 responses
    1 view
    0 likes
    Last Post FitSpressoHonest  
    Started by Davide999, 05-18-2023, 03:55 AM
    4 responses
    557 views
    1 like
    Last Post kcwasher  
    Started by rexsole, Today, 08:39 AM
    2 responses
    8 views
    0 likes
    Last Post NinjaTrader_Erick  
    Working...
    X