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 NullPointStrategies, Today, 05:17 AM
          0 responses
          23 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          120 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          63 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          41 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          45 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X