Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Check for NBarsUp Event in the last 7 bars

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

    Check for NBarsUp Event in the last 7 bars

    Hi,

    how can I monitor if there was an NBarsUp Event during the last 7 bars?

    I tried this, but it doesn't work:

    for (int i = 0; i < 7; i++)
    {
    double value = NBarsUp(3, true, true, true)[i];

    if (value == 1)
    {
    BackColor = Color.Green;
    }
    }

    P.S.: Interestingly, if I change it to "for (int i = 0; i > -7; i--)", it gives a green background for the 7 bars leading up to the NBarsUp Event. So, looking into the future works, but the ordinary use doesn't? What am I missing?

    #2
    Any log errors you would see as the indicator refuses to work for you?

    Comment


      #3
      I'm using it on a chart with plenty of historical data. The NBarsUp indicator works - have a look at the picture I attached.

      Let me try to explain it simpler:

      This (as expected) produces a green background for the bar with the green NBarsUp indicator:

      if (NBarsUp(3, true, true, true)[0] == 1)
      BackColor = Color.Green;

      If I change the [int bars ago] from [0] to [-1] (thus looking into the future, I guess), it produces a green background one bar to the left of the green NBarsUp indicator.

      If I change the [int bars ago] from [0] to [1], I expect it to produce a green background one bar to the right of the green NBarsUp indicator. Instead, I get no green background at all (as seen in the attached picture).

      This last case is the problem I don't understand.

      I don't know about log errors. How do I check that?

      Of course, I am also open to a different solution to check for an NBarsUp event during the last 7 bars.
      Attached Files

      Comment


        #4
        The issue is not historical data loaded, but accessing a non available historical data series point at the start of the chart, hence you need the check at the start of the OnBarUpdate() as outlined in the tip link I posted - the log errors can be checked in the right most tab of the Control Center.

        Comment


          #5
          Now I see what you mean - important lesson.

          Thank you - problem solved.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          577 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          334 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          553 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          551 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X