• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MRO() - Most Recent Occurrence

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

    MRO() - Most Recent Occurrence

    Helloo!

    I've been trying to implement the Most Recent Occurrence function in my strategy as documented here;

    https://ninjatrader.com/support/help...urence_mro.htm

    In this simple example I'm trying to draw a line between two swing highs;

    Code:
    protected override void OnBarUpdate()
    {
    
    if (BarsInProgress != 0) 
    return;
    
    if (CurrentBars[0] < 1)
    return;
    
    int first_high_barsAgo = MRO(() => Swing(Close, 3).SwingHigh[0] != Swing(Close, 3).SwingHigh[1], 1, 99);
    int second_high_barsAgo = MRO(() => Swing(Close, 3).SwingHigh[0] != Swing(Close, 3).SwingHigh[1], 2, 99);
    
    if (first_high_barsAgo > -1 && second_high_barsAgo > -1)
    Draw.Line(this, @"v3 Line_1"+CurrentBar, false, second_high_barsAgo, High[second_high_barsAgo], first_high_barsAgo, High[first_high_barsAgo], Brushes.Plum, DashStyleHelper.Solid, 2);
    		
    }
    I can't seem to get it right, it's not working. Any idea why?

    Thanks
    MT

    #2
    Hello mntemel,

    Thanks for your post.

    I copied and tested your code, it seems to work here, please see the attached example.

    Can you clarify what specifically is not working for you or what the conditions are that are not working?
    Attached Files
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul,

      Thank you for your reply.

      I applied the strategy to a new chart and it worked. The only difference between two charts is; one has "Tick Replay" ticked, and the other not. So, when tick replay option is selected in the chart this MRO() function is not working. Is there a way around this issue?

      Thanks,
      MT

      Comment


        #4
        Hello mntemel,

        Thanks for your reply.

        I tested with tick replay enabled and there was no issue (see attached).

        Is it possible that you do not have tick data for that instrument?

        Do you see any errors in the "log" tab of the control center when the strategy is applied to a tick replay enabled chart?
        Attached Files
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hi Paul,

          Thanks for the prompt reply, so this was the message in log;

          Strategy 'test3': Error on calling 'OnBarUpdate' method on bar 1: condition Parameter name: 'MRO' on bar 1 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.
          I have increased the number of bars to start condition to 10 bars and that fixed the issue.

          Code:
          if (CurrentBars[0] < 10)
          return;
          Many thanks for your support, you guys are doing an amazing job here!
          MT

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by tonynt, Today, 02:48 AM
          0 responses
          5 views
          0 likes
          Last Post tonynt
          by tonynt
           
          Started by cls71, Today, 02:11 AM
          2 responses
          10 views
          0 likes
          Last Post NinjaTrader_ChrisSch  
          Started by RB104, Today, 01:52 AM
          0 responses
          4 views
          0 likes
          Last Post RB104
          by RB104
           
          Started by reks13, Today, 01:52 AM
          0 responses
          5 views
          0 likes
          Last Post reks13
          by reks13
           
          Started by raffu, Today, 01:35 AM
          1 response
          12 views
          0 likes
          Last Post raffu
          by raffu
           
          Working...
          X