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
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hello cfaria,

      I just realized this is in the beta side, I will retest and rework for NT8 shortly.
      Paul H.NinjaTrader Customer Service

      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
        Paul H.NinjaTrader Customer Service

        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
            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by DayTradingDEMON, Today, 09:28 AM
            2 responses
            15 views
            0 likes
            Last Post DayTradingDEMON  
            Started by Stanfillirenfro, Today, 07:23 AM
            8 responses
            23 views
            0 likes
            Last Post Stanfillirenfro  
            Started by navyguy06, Today, 09:28 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by cmtjoancolmenero, Yesterday, 03:58 PM
            8 responses
            32 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by helpwanted, Today, 03:06 AM
            2 responses
            22 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Working...
            X