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

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 RubenCazorla, 08-30-2022, 06:36 AM
        3 responses
        77 views
        0 likes
        Last Post PaulMohn  
        Started by f.saeidi, Yesterday, 12:14 PM
        9 responses
        23 views
        0 likes
        Last Post f.saeidi  
        Started by Tim-c, Today, 03:54 AM
        0 responses
        3 views
        0 likes
        Last Post Tim-c
        by Tim-c
         
        Started by FrancisMorro, Today, 03:24 AM
        0 responses
        5 views
        0 likes
        Last Post FrancisMorro  
        Started by Segwin, 05-07-2018, 02:15 PM
        10 responses
        1,772 views
        0 likes
        Last Post Leafcutter  
        Working...
        X