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 Mindset, 04-21-2026, 06:46 AM
          0 responses
          52 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, 04-20-2026, 05:21 PM
          0 responses
          71 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          38 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by cmoran13, 04-16-2026, 01:02 PM
          0 responses
          99 views
          0 likes
          Last Post cmoran13  
          Started by PaulMohn, 04-10-2026, 11:11 AM
          0 responses
          60 views
          0 likes
          Last Post PaulMohn  
          Working...
          X