Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NBarsUp and NBarsDown

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

    NBarsUp and NBarsDown

    I'm learning about these methods and I've been getting some incorrect values.

    I'm trying to loop through a reasonable lookback (in this case 20) to print out the consecutive number of bars that have closed either up or down, but the values that are printing are incorrect.

    What am I doing wrong?

    Code:
    for(int i = 2; i <= lookback; i++)
    {
         double nBarsUpValue = NBarsUp(i, true, false, false)[0];
         double nBarsDownValue = NBarsDown(i, true, false, false)[0];
    
         if(nBarsUpValue == 1)
         {
              consecutiveUpBars = i;
         }
         if(nBarsDownValue == 1)
         {
              consecutiveDownBars = i;
         }
    }
    Edit:
    It looks like the values that I'm printing may be correct and that the issue is in getting it to plot correctly so I'm attaching the whole code.
    Attached Files
    Last edited by WalterSkinner; 08-03-2021, 04:00 PM.

    #2
    "Corrected" the assignment of Value[1] and Value [0].

    You can see in the screenshot that the correct value is printed (red arrows).

    There's something I'm just not seeing in the code. I'm also new to making histograms so I feel like this is just something simple that I'm just unaware of.

    Edit:
    After looking at the MACD code because it has a histo, I commented out line 94, because the MACD code doesn't use "Value[] = " for anything aside from Value[0]. I suppose this worked, but as far as why I have no idea.
    Attached Files
    Last edited by WalterSkinner; 08-04-2021, 08:23 AM.

    Comment


      #3
      Hi Walter, thanks for posting.

      This does not look correct to me:

      Code:
      upRotations[0] = consecutiveUpBars;
      downRotations[0] = consecutiveDownBars;
      
      Value[0] = upRotations[0];
      Value[1] = -downRotations[0];
      this translates to:

      Code:
      upRotations[0] = consecutiveUpBars;
      downRotations[0] = consecutiveDownBars;
      
      upRotations[0] = upRotations[0];
      upRotations[1] = -downRotations[0];
      I commented out
      Value[0] = upRotations[0];
      Value[1] = -downRotations[0];[/CODE]

      and the plots are correct this way.

      Kind regards,
      -ChrisL

      Comment


        #4
        Originally posted by NinjaTrader_ChrisL View Post
        Hi Walter, thanks for posting.

        This does not look correct to me:

        Code:
        upRotations[0] = consecutiveUpBars;
        downRotations[0] = consecutiveDownBars;
        
        Value[0] = upRotations[0];
        Value[1] = -downRotations[0];
        this translates to:

        Code:
        upRotations[0] = consecutiveUpBars;
        downRotations[0] = consecutiveDownBars;
        
        upRotations[0] = upRotations[0];
        upRotations[1] = -downRotations[0];
        I commented out
        Value[0] = upRotations[0];
        Value[1] = -downRotations[0];[/CODE]

        and the plots are correct this way.

        Kind regards,
        -ChrisL
        Any idea why the colors are showing up the opposite to what I'm trying to paint them? Trying to get blue on up and red on down. 0804b.zip
        Attached Files
        Last edited by WalterSkinner; 08-04-2021, 09:24 AM.

        Comment


          #5
          Hi Walter, thanks for your reply.

          The public propertys are switched around:

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> upRotations
          {
          get { return Values[1]; } //returns DownRotations, the second added plot.
          }

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> downRotations //returns UpRotations, the first added plot
          {
          get { return Values[0]; }
          }

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          605 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          351 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          105 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          560 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          561 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X