Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Counting Bars after Boolean true

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

    Counting Bars after Boolean true

    Hello i want to count X bars after a bool is set true:

    if
    (Indicator[0] == 3);
    {
    IndicatorLong = true;
    }

    if
    (IndicatorLong == true && ;
    {
    NewBarCounter++;
    }

    if
    (IndicatorLong= true && NewBarCounter>= 5);
    {
    IndicatorLong= false;
    NewBarCounter= 0;
    }

    I dont know how to implment that the counter is increment by 1 after every new bar.

    Can someone help here?

    Thanks

    #2
    Hello Lopat,

    What you posted should essentially do that but I do see some errors in the way you made your conditions. In C# you never use the semi colon on an if statement, your if condition should always be formatted like this:

    Code:
    if(someCondition)
    {
    
    }
    You currently have
    Code:
     if(someCondition);
    Which prevents the logic below the if condition from happening when the condition is true.

    Your condition should look like this:
    Code:
    if(Indicator[0] == 3)
    {
         IndicatorLong = true;
    }​

    You may also need to change the Indicator[0] == 3 to Indicator[0] >= 3, checking if two double type numbers are exactly equal in C# is not possible.

    Another item here would be to add prints so that you can output how your logic is working when you run the script. That will help to make sure its doing what you had expected.

    Comment


      #3
      Hi thanks! I change the code.

      does this part increment by 1 after each bar?

      if
      (IndicatorLong == true)
      {
      NewBarCounter++;
      }​

      or do I need to add that the counter increment after each new bar? And when yes. How do I do it?

      Comment


        #4
        Hello Lopat,

        Assuming that you are using OnBarClose processing yes. Once IndicatorLong is true that condition will be true. In C# you can increment a variable by using the ++ operator. Using ++ is the same as NewBarCounter = NewBarCounter + 1;

        Comment


          #5
          Thanks a lot. It is working now like I want it. Thanks for the quick response

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          50 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          126 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          69 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X