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;



    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

    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

        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 NullPointStrategies, Today, 05:17 AM
          0 responses
          50 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          126 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          69 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 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