Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Count Number of Bars

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

    Count Number of Bars

    Hi,

    I would like to count the number of bars since Trend[1] != Trend[2]. So essentially it's at the point where the trend direction changes. Is below how I would be able to do this or am I completely off?

    int TrendCounter = 0;

    OnBarUpdate()

    if (Trend[1] != Trend[2])
    {
    TrendCounter = 0;
    }
    else
    TrendCounter += _________;
    }

    #2
    Hello AgriTrdr,

    Yes, this would be the general idea.

    Below is a link to a forum post that discusses incrementing an integer as a counter.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      So in the attached post, is:

      Counter++;

      adding the bars or what is it adding?

      Comment


        #4
        Hello AgriTrdr,

        Using '++' means to increment by one. This means add one to the existing value.

        Below is a link to the Microsoft documentation on arithmetic operators.
        Learn about C# operators that perform multiplication, division, remainder, addition, and subtraction operations with numeric types.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you! That worked.

          Is there a way to take the current TrendCounter value and compare it to the previous TrendCounter value of the prior before resets to 0?

          Comment


            #6
            Hello AgriTrdr,

            You could assign it to another variable.

            private double myVariable;

            myVariable = TrendCounter[0];


            }
            else​ {

            TrendCounter += _________;

            Print("myVariable: " + myVariable + " | TrendCounter: " + TrendCounter);

            }
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by CarlTrading, 05-11-2026, 05:56 AM
            0 responses
            52 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 05-10-2026, 08:12 PM
            0 responses
            29 views
            0 likes
            Last Post CarlTrading  
            Started by Hwop38, 05-04-2026, 07:02 PM
            0 responses
            194 views
            0 likes
            Last Post Hwop38
            by Hwop38
             
            Started by CaptainJack, 04-24-2026, 11:07 PM
            0 responses
            355 views
            0 likes
            Last Post CaptainJack  
            Started by Mindset, 04-21-2026, 06:46 AM
            0 responses
            274 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Working...
            X