Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Day of week variable

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

    Day of week variable

    Hi Guys,

    I have got a copy of C# 2010 for dummies and am making an effort to do this myself. But I am short of time so am asking for some help to improve a strategy. I want to define a day of the week from a variable entry. I have set a variable int as zdaynot ( day not to trade ) numbered 1 to 6 and am trying to convert it to a string zdow
    that has been set as a default of "na". But I am unsure on my if statement and conversion of the string.

    Thanks Raef


    && (Zdaynot == 1)
    {Zdow =
    "Monday"};
    && (Zdaynot ==
    2)
    {Zdow =
    "Tuesday"};
    && (Zdaynot ==
    3)
    {Zdow =
    "Wednesday"};
    && (Zdaynot ==
    4)
    {Zdow =
    "Thursday"};
    && (Zdaynot ==
    5)
    {Zdow =
    "Friday"};
    && (Zdaynot ==
    6)
    {Zdow =
    "Saturday"};

    Time[
    0].DayOfWeek.ToString != (Zdow);

    #2
    I don't think this is valid:

    {Zdow = "Monday"};

    I think you need something like:

    {Zdow = new String ("Monday")};


    I haven't tested this out. But I think it is your issue.
    I can't find any examples of assignment like that.



    This might help some more:

    A few weeks ago, I discovered that strings in C# are defined as reference types and not value types. Initially I was confused about this, but then after some reading, I suddenly understood why it is

    Comment


      #3
      thanks that looks better I will view those sites as well.


      Thanks

      Comment


        #4
        At first glance that seems correct except for your cast to string.
        Time[0].DayOfWeek.ToString != (Zdow);


        That should be
        Code:
        Time[0].DayOfWeek.ToString[B][COLOR=Red]()[/COLOR][/B] != (Zdow);


        (notice the brackets, in red).

        Comment


          #5
          DayOfWeek in ninja help also has some information that could help you to shortcut


          DayOfWeek



          Definition
          The day of the week of the current bar accessed through the Time property.

          Property Value
          A DayOfWeek type such as:
          DayOfWeek.Monday
          DayOfWeek.Tuesday
          DayOfWeek.Wednesday
          DayOfWeek.Thursday
          DayOfWeek.Friday
          DayOfWeek.Saturday
          DayOfWeek.Sunday

          Syntax
          Time[int barsAgo].DayOfWeek


          Examples

          protected override void OnBarUpdate()
          {
          // If it's Monday, do not trade.
          if (Time[0].DayOfWeek == DayOfWeek.Monday)
          return;
          }




          Originally posted by raefon72 View Post
          Hi Guys,

          I have got a copy of C# 2010 for dummies and am making an effort to do this myself. But I am short of time so am asking for some help to improve a strategy. I want to define a day of the week from a variable entry. I have set a variable int as zdaynot ( day not to trade ) numbered 1 to 6 and am trying to convert it to a string zdow
          that has been set as a default of "na". But I am unsure on my if statement and conversion of the string.

          Thanks Raef


          && (Zdaynot == 1)
          {Zdow =
          "Monday"};
          && (Zdaynot ==
          2)
          {Zdow =
          "Tuesday"};
          && (Zdaynot ==
          3)
          {Zdow =
          "Wednesday"};
          && (Zdaynot ==
          4)
          {Zdow =
          "Thursday"};
          && (Zdaynot ==
          5)
          {Zdow =
          "Friday"};
          && (Zdaynot ==
          6)
          {Zdow =
          "Saturday"};

          c
          .ToString != (Zdow);

          Comment


            #6
            I may have used an incorrect string or somthing I am unsure where I have gone wrong. I had to delete and start from the beginning because the compiler stopped me from working on other stuff.

            Thanks Raef

            // Condition set 1
            if (Notrade1 == 1)
            {
            string DayA = new String("Monday");
            }
            if (Notrade1 == 2)
            {
            string DayA = new String("Tuesday");
            }

            if (CrossAbove(EMA(Emafast), EMA(Emaslow), 1)
            && Time[
            0].DayOfWeek.ToString() != (DayA))
            {
            EnterLong(DefaultQuantity,
            "");
            }

            {
            EnterLong(DefaultQuantity,
            "");
            }
            Last edited by raefon72; 01-02-2012, 03:52 PM.

            Comment


              #7
              I tried this also

              if (CrossAbove(EMA(Emafast), EMA(Emaslow), 1)
              && Time[
              0].DayOfWeek == DayOfWeek.ToString != (DayA)

              Comment


                #8
                Got a final result for variable Day of week.

                I have cut the parts out of the script I believe its all here.
                Full strategy here http://www.raefontrading.com/strateg...-day-strategy/

                Code:
                 
                private string dayOWstring = "Monday"; // Set day of week.
                private bool dayOWon = false; // Have DayOW filter off by default.
                private int dayOW = 1; // Sets a variable for Day of week 1 is Monday
                 
                 
                protected override void OnBarUpdate()
                 
                {
                if (dayOW == 1){dayOWstring = "Monday";}
                if (dayOW == 2){dayOWstring = "Tuesday";}
                if (dayOW == 3){dayOWstring = "Wednesday";}
                if (dayOW == 4){dayOWstring = "Thursday";}
                if (dayOW == 5){dayOWstring = "Friday";}
                if (dayOW == 6){dayOWstring = "Saturday";}
                if (dayOW == 7){dayOWstring = "Sunday";}
                if (dayOW > 7){dayOWstring = "Sunday";}
                 
                 
                if(dayOWon == true
                && Time[0].DayOfWeek.ToString() == (dayOWstring)
                )
                {
                 
                }
                }
                 
                [Description("")]
                [GridCategory("Parameters")]
                public int DayOW
                {
                get { return dayOW; }
                set { dayOW = Math.Max(1, value); }
                }
                [Description("")]
                [GridCategory("Parameters")]
                public bool DayOWon
                {
                get { return dayOWon; }
                set { dayOWon = value; }
                }
                Last edited by raefon72; 04-15-2012, 07:49 PM.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                647 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                369 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                108 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                572 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                573 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X