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 GwFutures1988, Today, 02:48 PM
        0 responses
        1 view
        0 likes
        Last Post GwFutures1988  
        Started by mmenigma, Today, 02:22 PM
        1 response
        3 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by frankthearm, Today, 09:08 AM
        9 responses
        35 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by NRITV, Today, 01:15 PM
        2 responses
        9 views
        0 likes
        Last Post NRITV
        by NRITV
         
        Started by maybeimnotrader, Yesterday, 05:46 PM
        5 responses
        28 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X