Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

System.DayOfWeek Problem

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

    System.DayOfWeek Problem

    Hi,
    In my indicator code have below lines:

    DateTime item3 = base.Time[1];
    int dayOfWeek = item3.DayOfWeek;
    DateTime dateTime3 = Time[0];
    int num = dateTime3.DayOfWeek;

    I got this error:
    Cannot implicitly convert type 'System.DayOfWeek' to 'int'. An explicit conversion exists (are you missing a cast?)

    Above functions not return integer?
    ow to solve that?
    Regards,

    #2
    Hello RezaFx,

    This error returns due to the fact that the DayOfWeek Enum is not an int or string.
    A proper use of DayOfWeek would be the following:
    Code:
    if(dateTime3.DayOfWeek == DayOfWeek.Monday)
    				Print("It is Monday.");
    For information on DayOfWeek please visit the following link: http://www.ninjatrader.com/support/h.../dayofweek.htm

    For a C# reference on DayOfWeek please visit the following link: http://msdn.microsoft.com/en-us/libr...(v=vs.90).aspx

    Please let me know if you have any questions.

    Comment


      #3
      Originally posted by RezaFx View Post
      Hi,
      In my indicator code have below lines:

      DateTime item3 = base.Time[1];
      int dayOfWeek = item3.DayOfWeek;
      DateTime dateTime3 = Time[0];
      int num = dateTime3.DayOfWeek;

      I got this error:
      Cannot implicitly convert type 'System.DayOfWeek' to 'int'. An explicit conversion exists (are you missing a cast?)

      Above functions not return integer?
      ow to solve that?
      Regards,
      If you insist on using an integer, you have to do an explicit cast.
      Code:
      int num = (int)dateTime3.DayOfWeek;

      Comment


        #4
        Thanks. Now it works.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        157 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        91 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        143 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        131 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        107 views
        0 likes
        Last Post CarlTrading  
        Working...
        X