Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Countif Function

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

    #16
    Hello tkaboris,

    Please be specific about the rules you are wanting.

    By bear bar you mean the Open[0] is less than the Close[0]?

    Do you mean the Close[0] of the current bar is less than the Close[1] of the previous bar?

    "to be more then 5 bars ago at least."

    The MRO doesn't have an offset. If you want to start checking from 5 bars ago, you should use a loop.

    Code:
    int barsAgo;
    
    for (int index = 5; index < CurrentBar; index++)
        if (Close[index] < Open[index] && High[index] > EMA(21)[index] && Close[index] < EMA(21)[index])
            barsAgo = index;
    
    Print("the condition was found " + barsAgo + " barsAgo);

    Further, using MRO() will not accomplish your goal above "current price was less than the EMA 10 bars ago and is greater than the EMA on the current bar".

    That said, it would likely appear as:

    Code:
    int barsAgo = MRO(() => Close[0] < Open[0] && High[0] > EMA(21)[0] && Close[0] < EMA(21)[0], 1, CurrentBar);
    
    Print("The condition was found " + barsAgo + " barsAgo");
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      HI thank you it seems this is excactly what i need.

      Strange
      I have this line and it works fine
      int rejectionAt21ShortBarsAgo = MRO(() => Close[1] > Open[1] && Close[0] < Open[0] && High[0] > EMA(21)[0] && Close[0] < EMA(21)[0], 1, CurrentBar);
      when i have lilne below, it trhows an error

      int rejectionAt21LongBarsAgo = MRO(() => Close[1] < Open[1] && Close[0] > Open[0] && Low[0] < EMA(21)[0] && Close[0] > EMA(21)[0], 1, CurrentBar);

      Parameter name: 'MRO' on bar 0 threw exception: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

      What can it be?

      Comment


        #18
        Never mind i increased CurentBar and its working.

        Comment


          #19
          Hello tkaboris,

          The issue may be with using Close[1] of 1 barAgo, when CurrentBar is 0 or 1 (from the lookBackPeriod).

          Try instead:

          Code:
          if (CurrentBar < 2)
          return;
          
          int rejectionAt21LongBarsAgo = MRO(() => Close[1] < Open[1] && Close[0] > Open[0] && Low[0] < EMA(21)[0] && Close[0] > EMA(21)[0], 1, CurrentBar - 2);
          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Mindset, 04-21-2026, 06:46 AM
          0 responses
          88 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, 04-20-2026, 05:21 PM
          0 responses
          135 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          68 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by cmoran13, 04-16-2026, 01:02 PM
          0 responses
          119 views
          0 likes
          Last Post cmoran13  
          Started by PaulMohn, 04-10-2026, 11:11 AM
          0 responses
          69 views
          0 likes
          Last Post PaulMohn  
          Working...
          X