Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Check number of candles since last true condition

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

    Check number of candles since last true condition

    Is there a way to check the number of candles since last true condition. For example...

    Condition #1
    if (RSI > 80) {RSIx == true}

    Condition #2
    If (RSIx = true && No. of candles since Condition #1 > 20)


    #2
    Hello cryfgg,

    Thank you for your note.

    You could create a variable that gets updated with the CurrentBar number when condition 1 becomes true, and in the second condition check if the difference between CurrentBar and your saved bar value is greater than 20. For example:

    //instantiate variable at class level
    private int BarNumberOfRSIx;

    if ( my conditions are true )
    {
    RSIx = true;
    BarNumberOfRSIx = CurrentBar;
    }

    if (RSIx = true && (CurrentBar - BarNumberOfRSIx) > 20)
    {
    // do something
    }

    Please let us know if we may be of further assistance to you.

    Comment


      #3
      [QUOTE=NinjaTrader_Kate;n1208613]Hello cryfgg,

      Thank you for your note.

      You could create a variable that gets updated with the CurrentBar number when condition 1 becomes true, and in the second condition check if the difference between CurrentBar and your saved bar value is greater than 20. For example:

      //instantiate variable at class level
      private int BarNumberOfRSIx;

      if ( my conditions are true )
      {
      RSIx = true;
      BarNumberOfRSIx = CurrentBar;
      }

      if (RSIx = true && (CurrentBar - BarNumberOfRSIx) > 20)
      {
      // do something
      }

      Please let us know if we may be of further assistance to you.[/QUOTE


      I tried it but it didn't work. Looks like the CurrentBar syntax counts the number of bars on screen. However, i want to save the position of the bar (the bar number in a series of bars). For example, lets assume the first condition was true as of the current bar; I want the second condition to be true at least 20 bars after the first condition is true.

      Here is my code using your suggestion...
      if((Close[0] > Close[1])
      && (Close[1] > Close[2])
      && (Close[2] > Close[3])
      && (Close[3] > Close[4])
      && (Close[4] > Close[5])
      && (Close[5] < Close[6])
      && (Close[6] < Close[7])
      && (Close[7] < Close[8]) )

      {
      BullishBCD2 = true;

      BarsCounter1 = CurrentBar;
      }

      if((Close[0] < Close[1])
      && (BullishBCD2 == true)

      && (BarsCounter1 > 20) )

      {
      Draw.VerticalLine(this, @"Vertical line_1"+CurrentBar, 0, false, "greenv");
      BullishBCD2 = false;
      }

      The result of the above code is the same (no change in the output).

      Comment


        #4
        Hello cryfgg,

        Thank you for your reply.

        You haven't structured the second condition as I have in my example:

        if((Close[0] < Close[1])
        && (BullishBCD2 == true)
        && ((CurrentBar - BarsCounter1) > 20) )

        {
        Draw.VerticalLine(this, @"Vertical line_1"+CurrentBar, 0, false, "greenv");
        BullishBCD2 = false;
        }

        Please let us know if we may be of further assistance to you.

        Comment


          #5
          Originally posted by NinjaTrader_Kate View Post
          Hello cryfgg,

          Thank you for your reply.

          You haven't structured the second condition as I have in my example:

          if((Close[0] < Close[1])
          && (BullishBCD2 == true)
          && ((CurrentBar - BarsCounter1) > 20) )

          {
          Draw.VerticalLine(this, @"Vertical line_1"+CurrentBar, 0, false, "greenv");
          BullishBCD2 = false;
          }

          Please let us know if we may be of further assistance to you.

          It worked... thanks a million... have a fabulous weekend.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          634 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          364 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
          567 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          568 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X