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 CarlTrading, 03-31-2026, 09:41 PM
          1 response
          80 views
          1 like
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          40 views
          0 likes
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          64 views
          2 likes
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          64 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          54 views
          0 likes
          Last Post CarlTrading  
          Working...
          X