Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

days of week

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

    days of week

    Hello,

    I would like to know what's the code line to isolate the days of the week.

    For example : "if we are monday, then..."

    I'm using NT7.

    Thanks for your help.

    #2
    if (DateTime.Now.DayOfWeek == DayOfWeek.Monday)
    {...}

    Regards
    Ralph

    Comment


      #3
      Thanks a lot

      Comment


        #4
        Sorry, I was not precise enough.

        I don't want "if we are monday today, then display 1 for all week" but instead "when day of (each) week is monday, then display 1 for all mondays"

        I guess it has to do with the .Now thingie.

        Sorry for the confusion. Any help appreciated.

        Comment


          #5
          What about this one:

          DateTime someDay = new DateTime(2010, 01, 01);
          if (someDay.DayOfWeek == DayOfWeek.Monday)
          {...}

          Regards
          Ralph

          Comment


            #6
            Sorry, can't make it work neither

            Here is the sample indicator I wrote to test it.

            It displays 0 for every day. It does not detect mondays

            Code:
            #region Using declarations
            using System;
            using System.ComponentModel;
            using System.Diagnostics;
            using System.Drawing;
            using System.Drawing.Drawing2D;
            using System.Xml.Serialization;
            using NinjaTrader.Cbi;
            using NinjaTrader.Data;
            using NinjaTrader.Gui.Chart;
            #endregion
            
            namespace NinjaTrader.Indicator{
                [Gui.Design.DisplayName("TEST")]
                [Description("TEST")]    
                public class SARdynamite_test : Indicator{
                    #region Variables
                    #endregion
                    protected override void Initialize()
                    {
                        AutoScale = true;
                        CalculateOnBarClose    = true;
                        Name = "TEST ";
                        Overlay = false;
                        PriceTypeSupported= false;
                        Add(new Plot(new Pen(Color.Lime,1),PlotStyle.Bar,"teest"));
                    }
                    protected override void OnBarUpdate()
                    {
                        if (CurrentBar<1) return;
                        DateTime someDay = new DateTime(2010, 01, 01);
                        if (someDay.DayOfWeek == DayOfWeek.Monday) test.Set(1);
                        else test.Set(0);
                            
                    }
                    #region Properties
                    [Browsable(false)]
                    [XmlIgnore()]
                    public DataSeries test
                    {
                        get { return Values[0]; }
                    }
                    #endregion
                }    
            }

            Comment


              #7
              I provided examples with arbitrary date-instantiations to get something to work on. I suspect in your indicator you intend to evaluate the actual bar right? If so, then you could try something like this:

              if (Time[0].DayOfWeek == DayOfWeek.Monday) test.Set(1);
              else test.Set(0);

              Regards
              Ralph

              Comment


                #8
                Sorry for the awkwardness. Works like a charm. Have a nice day.

                Comment


                  #9
                  Sorry, one last request.

                  Just how we wrote "every monday", how do we put into code : "every first day of month" ?

                  Thanks a lot.

                  Have a nice day

                  Comment


                    #10
                    It is not obvious but the following returns the day of month:

                    Time[0].Day

                    therefore the check for first day of month:

                    if (Time[0].Day == 1)

                    Regards
                    Ralph

                    Comment


                      #11
                      Thanks a bunch.

                      Comment


                        #12
                        Knock knock.
                        Some more help.

                        How to detect timeframe ?

                        i.e. write "if time frame is 5 minutes chart then"

                        Thanks a lot. Have a nice day.

                        Comment


                          #13
                          Hello,

                          You might want to use BarsPeriod:
                          DenNinjaTrader Customer Service

                          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