Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MRO function

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

    MRO function

    I am trying to use MRO (Most recent occurrence) function for one of the indicators and for some reason do not get any value back.

    The code looks like below under OnBarUpdate() method. The indicator is to trade ES and I am trying to chart to the value of 'risk1' as defined in the formula below. But for some reason when I chart this indicator, I get no values.

    I have 'risk' and 'risk1' defined as DataSeries and also added in Initialize area.

    {
    if ((SMA(34)[0] > DEMA(500)[0]))
    {
    risk.Set(High[0] - (DEMA(500)[0] - 8 * TickSize));
    }

    int barsAgo = MRO(delegate {return (CrossAbove(SMA(34),DEMA(500),0));}, 1, 500);
    if (barsAgo > -1)
    risk1.Set(risk[barsAgo]);
    Value.Set(risk1[0]);
    }

    I am not sure why the code is not working. I do not get any error while compiling either.

    Can someone help please? I appreciate any assistance or direction you can provide.

    #2
    Hello,

    Are you receiving any errors on the Log tab of the Control Center? If so what do these errors report?
    MatthewNinjaTrader Product Management

    Comment


      #3
      It reads:
      Error on calling 'OnBarUpdate' method for indicator 'MyCustomIndicator' on bar 1: 'MRO' on bar 0 threw exception: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
      I am not sure what could be solution here?

      Comment


        #4
        Hello,

        Thanks for letting us know.

        Please add the following code to your script to resolve this.



        Let me know if I can be of further assistance.
        BrettNinjaTrader Product Management

        Comment


          #5
          So added the following statement to the script and still get the same error message without any result. At this poing I am wondering I am adding it in the right part of the script.

          if (CurrentBar < 1)
          return;


          {
          if ((SMA(34)[0] > DEMA(500)[0]))
          {
          risk.Set(High[0] - (DEMA(500)[0] - 8 * TickSize));
          }

          int barsAgo = MRO(delegate {return (CrossAbove(SMA(34),DEMA(500),0));}, 1, 500);
          if (barsAgo > -1)
          risk1.Set(risk[barsAgo]);
          Value.Set(risk1[0]);
          }

          Once again very much appreciate your help here.

          Comment


            #6
            Hello pandyav,

            Your MRO lookback is 500, as well as calculations used in indicators. You will need a large ramp up time for this script, so may want to work something like this into your script:

            if (CurrentBar < 500) return;

            You should also make sure that MaximumBarsLookBack setting is set to Infinite. This can be set in code or when you apply the script to a chart.
            Last edited by NinjaTrader_RyanM1; 10-17-2011, 09:43 AM.
            Ryan M.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            574 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            333 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            553 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            551 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X