Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 lezlebric, Today, 06:32 PM
          0 responses
          5 views
          0 likes
          Last Post lezlebric  
          Started by TheTechnician86, Today, 05:47 PM
          0 responses
          8 views
          0 likes
          Last Post TheTechnician86  
          Started by Ryan333, Today, 05:25 PM
          0 responses
          4 views
          0 likes
          Last Post Ryan333
          by Ryan333
           
          Started by hsammons87, Today, 05:21 PM
          0 responses
          6 views
          0 likes
          Last Post hsammons87  
          Started by Gmonte, 10-01-2022, 08:28 AM
          2 responses
          190 views
          0 likes
          Last Post charlesthomas  
          Working...
          X