Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Clarification on using MRO Condition

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

    Clarification on using MRO Condition

    Hello,

    I hope my message find you well. I would like to ask you some clarification on the use of the MRO condition.
    I understood what it does and I was able to use it correctly.
    However, I am having problems on using the values generated by it to do something.

    I created an MRO that checks for a red bar, of which I saved the doubles High and Low. Now I would like to use these variables to create further conditions, but it does not seem to work.
    I provide the code below.

    As can be seen from the picture, Ninja does not recognize the if function (Close[0] > BearBarHigh) .

    I really thank you for your hel.

    Code:
    //RED BAR MRO
    
    int bearishBarsAgo = MRO(() => _bearishPA, 1, 10);
    
    if (bearishBarsAgo > -1)
    {
    Draw.Dot(this, @"Entry Dot_1 " + Convert.ToString(CurrentBars[bearishBarsAgo]), true, 0, (Low[0] + (-10 * TickSize)), Brushes.BlueViolet);
    double BearBarLow = Low[bearishBarsAgo];
    double BearBarHigh = High[bearishBarsAgo];
    Print(Time[0] + " RedBar: " + "Low: " + BearBarLow + " High: " + BearBarHigh);
    
    if (Close[0] > BearBarHigh)
    BackBrush = Brushes.Gray;
    
    }









    #2
    Hello NorwegianCat92,

    Have you added the Close[0] price to your print to see if the close is ever greater than the BearBarHigh value? That would be a first step at addressing why that specific condition is not true. The rest of your print looks good, the time is needed so you can compare the data with specific bars.

    Comment


      #3
      Hello Jesse,

      Thank you very much for your reply.
      So I tested two instances:

      - If I put the Close[0] inside the If statement (bearishBarsAgo > -1) it returns the close corresponding to the MRO index bar.
      - If I put the Close[0] outside the If statement (bearishBarsAgo > -1) it returns the close of every bar.

      /
      Code:
      /RED BAR MRO
      
      int bearishBarsAgo = MRO(() => _bearishPA, 1, 10);
      
      if (bearishBarsAgo > -1)
      {
      Draw.Dot(this, @"Entry Dot_1 " + Convert.ToString(CurrentBars[bearishBarsAgo]), true, 0, (Low[0] + (-10 * TickSize)), Brushes.BlueViolet);
      double BearBarLow = Low[bearishBarsAgo];
      double BearBarHigh = High[bearishBarsAgo];
      Print(Time[0] + " RedBar: " + "Low: " + BearBarLow + " High: " + BearBarHigh);
      _RedBarSentiment = true;
      Print(Time[0] + "Close : " + Close[0]);
      
      }
      
      Print(Time[0] + "Close Outiside If Statement: " + Close[0]);
      The problem is that if I apply the function if (Close[0] > BearBarHigh) outside the if(bearishBarsAgo >-1), I get the error :Error on calling 'OnBarUpdate' method on bar 11: 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.

      At the moment I am using the conditions
      if (BarsInProgress != 0)
      return;

      if (CurrentBars[0] < 10)
      return;

      Thank you for the help
      Click image for larger version

Name:	Ninja1.png
Views:	77
Size:	181.2 KB
ID:	1322670

      Comment


        #4
        Hello NorwegianCat92,

        The code would need to go inside that if condition because that makes sure an instance was found. When the value is -1 that means no instance was found so at that point there is no bars ago to get a value from a series which causes an error.


        Comment


          #5
          Hello Jesse,

          Thank you for the reply.

          The problem is that if I put it inside the If Statement, I get nothing because the only close that prints out of the If statement is the close corresponding to the MRO candle.
          As you can see from the print, the value of the close is only the one within the if (bearishBarsAgo >-1), but that is the close of the MRO candle. I want to compare the current close and see if it is greater than the most recent High of the MRO candle.

          Thank you Click image for larger version

Name:	Ninja3.png
Views:	70
Size:	179.4 KB
ID:	1322685

          Code:
          int bearishBarsAgo = MRO(() => _bearishPA, 1, 10);
          
          if (bearishBarsAgo > -1)
          {
          Draw.Dot(this, @"Entry Dot_1 " + Convert.ToString(CurrentBars[bearishBarsAgo]), true, 0, (High[0] + (+10 * TickSize)), Brushes.BlueViolet);
          double BearBarLow = Low[bearishBarsAgo];
          double BearBarHigh = High[bearishBarsAgo];
          Print(Time[0] + " RedBar: " + "Low: " + BearBarLow + " High: " + BearBarHigh);
          _RedBarSentiment = true;
          Print(Time[0] + "Close : " + Close[0]);
          
          if ( CrossAbove(Close,High[bearishBarsAgo],1))
          {
          Print(Time[0] + "Price Crossed Above High MRO");
          BackBrush = Brushes.Gray;
          
          }
          
          }
          
          Print(Time[0] + "Close Outiside If Statement: " + Close[0]);

          Comment


            #6
            Hello NorwegianCat92,

            Can you show the code you are using to set _bearishPA?

            Comment


              #7
              Hello Jesse

              Yes!

              Code:
              double PriorBarRange = High[1] - Low[1];
              double HighBar1 = High[1];
              double LowBar1 = Low[1];
              
              double CurrentBarRange = High[0] - Low[0];
              double HighBar0 = High[0];
              double LowBar0 = Low[0];
              double CloseBar0 = Close[0];
              
              double CloseRangeUp = Low[0] + (PriorBarRange) * 0.75;
              double CloseRangeDown = High[1] - (PriorBarRange) * 0.75;
              
              double offset = PriorBarRange * 0.1;
              
              _bearishPA = LowBar0 <= LowBar1 - offset;
              _bearishPA &= CloseBar0 <= LowBar1 - offset;
              _bearishPA &= Close[0] < Open[0];
              Thank you for the help​

              Comment


                #8
                Hello NorwegianCat92,

                Thank you for providing that.

                Since you are doing more operations that just using the price series it looks like MRO would be the best way to do this type of action.

                In this case you will need to set the variable inside the condition, if you need to maintain a persistent value after that point you can use a variable.

                Code:
                private double BearBarLow;
                private double BearBarHigh;
                
                protected override void OnBarUpdate()
                {​
                    int bearishBarsAgo = MRO(() => _bearishPA, 1, 10);
                
                   if (bearishBarsAgo > -1)
                   {
                      Draw.Dot(this, @"Entry Dot_1 " + Convert.ToString(CurrentBars[bearishBarsAgo]), true, 0, (High[0] + (+10 * TickSize)), Brushes.BlueViolet);
                      BearBarLow = Low[bearishBarsAgo];
                      BearBarHigh = High[bearishBarsAgo];
                      Print(Time[0] + " RedBar: " + "Low: " + BearBarLow + " High: " + BearBarHigh);
                      RedBarSentiment = true;
                      Print(Time[0] + "Close : " + Close[0]);
                    }
                    if(BearBarHigh > 0)
                    {
                        // use  the BearBarLow or BearBarHigh here
                    }
                }​



                Comment


                  #9
                  Hello Jesse,

                  Thank you very much for your help. You were really nice, I solved my problem.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Today, 05:17 AM
                  0 responses
                  25 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  121 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  64 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
                  46 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X