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

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.

        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 r68cervera, Today, 05:29 AM
            0 responses
            2 views
            0 likes
            Last Post r68cervera  
            Started by geddyisodin, Today, 05:20 AM
            0 responses
            3 views
            0 likes
            Last Post geddyisodin  
            Started by JonesJoker, 04-22-2024, 12:23 PM
            6 responses
            35 views
            0 likes
            Last Post JonesJoker  
            Started by GussJ, 03-04-2020, 03:11 PM
            12 responses
            3,239 views
            0 likes
            Last Post Leafcutter  
            Started by AveryFlynn, Today, 04:57 AM
            0 responses
            6 views
            0 likes
            Last Post AveryFlynn  
            Working...
            X