Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How can I detect if a bar is on the first day of a month or year?

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

    How can I detect if a bar is on the first day of a month or year?

    I am trying to program an indicator that draws a vertical line on the first day of a month, or of a year.

    I am trying the following code:

    if (Time[0].Date.Day < Time[1].Date.Day)
    {
    DrawVerticalLine("VL" + CurrentBar, 0, Color.Gray,DashStyle.Dot,1);
    }

    In other words, I am trying to detect if the current bar's "Day" value is less than the previous bar's "Day" value, which should only happen if the previous bar occurred in the last month and the current bar occurred in the new month. However, the code does not draw anything. Is there something I am doing wrong?

    #2
    Originally posted by JS999 View Post
    I am trying to program an indicator that draws a vertical line on the first day of a month, or of a year.

    I am trying the following code:

    if (Time[0].Date.Day < Time[1].Date.Day)
    {
    DrawVerticalLine("VL" + CurrentBar, 0, Color.Gray,DashStyle.Dot,1);
    }

    In other words, I am trying to detect if the current bar's "Day" value is less than the previous bar's "Day" value, which should only happen if the previous bar occurred in the last month and the current bar occurred in the new month. However, the code does not draw anything. Is there something I am doing wrong?
    Is there any information in your log?

    You may need to escape the first bar with:

    Code:
    if (CurrentBar < 1) return;
    at the top of your OnBarUpdate() method.

    Comment


      #3
      Thanks, that was exactly the problem!

      Comment


        #4
        Hello koganam,
        It worked! but, "how the hell" did you or someone else work that out?

        If the answer is a short one that you can point me to, then that would be appreciated.
        Otherwise, I will add it to my list of "tricks" and thank forum members in helping the new guys.

        As an "oldhiker", I do not have time to learn to code NT to the nth degree, just enough time (I hope) to be able to code my own indicators, which are progressing quite well, even if I am a bit slow.

        The other simple, 'one liner' that solved one of my problems was as follows;-
        DrawOnPricePanel = false;

        Once again, thank you for your prompt help and I wish you a Happy New Year, along with good health and prosperity.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        566 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        330 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        547 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        548 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X