Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Month of Date?

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

    Month of Date?

    I want a formula that compares the month of today with the month of yesterday or compares the month of the actual frame with the month of the previous frame.

    I wrote the code like that but it didn't work:
    if(Time[0].Date.Month==Time[1].Date.Month)

    #2
    Hello cfaria,

    Thanks for your post and welcome to the forums!

    The code sample you provided is comparing the month of the current bar to the previous bar. I tested using daily bars and your code is true when the bars are of the same month. Are you wanting to instead detect when they are not the same? In that case you would change the operator to != (not equals) . For example:

    if(Time[0].Date.Month != Time[1].Date.Month)
    {
    DrawDot ("Test"+CurrentBar, true, 0, High[0]+ 30 *TickSize, Color.Blue); // show on new month
    }
    (See attached for blue dot example on daily bars)
    Attached Files

    Comment


      #3
      Hello cfaria,

      I just realized this is in the beta side, I will retest and rework for NT8 shortly.

      Comment


        #4
        Hello cfaria,

        Just to confirm, in Ninjatrader 8 the code I posted, converted to Ninjatrader 8, will perform at as the NT7 code I posted.

        if (Time[0].Date.Month != Time[1].Date.Month)
        {
        Draw.Dot (this, "test"+CurrentBar, true, 0, High[0]+30*TickSize, Brushes.Blue);
        }
        Attached Files

        Comment


          #5
          Originally posted by NinjaTrader_Paul View Post
          Hello cfaria,

          Just to confirm, in Ninjatrader 8 the code I posted, converted to Ninjatrader 8, will perform at as the NT7 code I posted.

          if (Time[0].Date.Month != Time[1].Date.Month)
          {
          Draw.Dot (this, "test"+CurrentBar, true, 0, High[0]+30*TickSize, Brushes.Blue);
          }
          Thanks for your reply.

          According to your answer the problem isn't in the month comparison, so it should be inside the IF statement.
          I want that the lines (PER1 and PER2) I've drawn before the IF goes up and down if the month is the same. But, when I include the IF statement all the lines disappear including the IND1 line!!!

          Here is the code:

          protected override void OnBarUpdate()
          {
          // Use this method for calculating your indicator values. Assign a value to each
          // plot below by replacing 'Close[0]' with your own formula.
          IND1.Set(High[0]);
          PER1.Set(IND1[0]);
          PER2.Set(IND1[0]);

          if(Time[0].Date.Month==Time[1].Date.Month && Volume[0] > 0){
          PER1[0]=PER1[1] * 1+(par/100000);
          PER2[0]=PER2[1] * 1-(par/100000);
          }
          }
          Last edited by cfaria; 09-27-2016, 11:43 AM.

          Comment


            #6
            Hello cfaria,

            Thanks for your reply.

            Please check the "Log" tab of the NinjaTrader control center for any run time errors related to the indicator.

            If that is all of your code then most likely you will need a currentbar check to make sure you have enough bars loaded before trying to access them. In your case this line: PER1[0]=PER1[1] will cause the indexing error because on the first bar loaded (0) there is no 1 bar.

            To work around this you would add this statement right after OnBarUpdate() {
            if (CurrentBar < 1 ) return;

            Reference: http://ninjatrader.com/support/helpG...currentbar.htm

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            656 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            371 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            109 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            574 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            579 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X