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() - 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
    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 sidlercom80, 10-28-2023, 08:49 AM
          168 responses
          2,262 views
          0 likes
          Last Post sidlercom80  
          Started by Barry Milan, Yesterday, 10:35 PM
          3 responses
          10 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by WeyldFalcon, 12-10-2020, 06:48 PM
          14 responses
          1,429 views
          0 likes
          Last Post Handclap0241  
          Started by DJ888, 04-16-2024, 06:09 PM
          2 responses
          9 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          41 views
          0 likes
          Last Post jeronymite  
          Working...
          X