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 lucasmelo152, 06-28-2021, 12:51 PM
        8 responses
        2,123 views
        0 likes
        Last Post Ymcapital  
        Started by Creamers, 04-27-2024, 05:32 AM
        11 responses
        68 views
        0 likes
        Last Post Creamers  
        Started by NM_eFe, 04-30-2024, 06:14 AM
        5 responses
        30 views
        0 likes
        Last Post NM_eFe
        by NM_eFe
         
        Started by Jonker, 04-27-2024, 01:19 PM
        2 responses
        20 views
        0 likes
        Last Post Jonker
        by Jonker
         
        Started by Max Baxter, 03-07-2019, 09:20 PM
        8 responses
        266 views
        0 likes
        Last Post Ymcapital  
        Working...
        X