Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 DayTradingDEMON, Today, 09:28 AM
        4 responses
        21 views
        0 likes
        Last Post DayTradingDEMON  
        Started by geddyisodin, Yesterday, 05:20 AM
        9 responses
        50 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by George21, Today, 10:07 AM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_ChristopherJ  
        Started by Stanfillirenfro, Today, 07:23 AM
        9 responses
        24 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by navyguy06, Today, 09:28 AM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X