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

  • mntemel
    replied
    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

    Leave a comment:


  • NinjaTrader_PaulH
    replied
    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

    Leave a comment:


  • mntemel
    replied
    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

    Leave a comment:


  • NinjaTrader_PaulH
    replied
    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

    Leave a comment:


  • mntemel
    started a topic MRO() - Most Recent Occurrence

    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

Latest Posts

Collapse

Topics Statistics Last Post
Started by AaronKoRn, Today, 09:49 PM
0 responses
6 views
0 likes
Last Post AaronKoRn  
Started by carnitron, Today, 08:42 PM
0 responses
9 views
0 likes
Last Post carnitron  
Started by strategist007, Today, 07:51 PM
0 responses
10 views
0 likes
Last Post strategist007  
Started by StockTrader88, 03-06-2021, 08:58 AM
44 responses
3,976 views
3 likes
Last Post jhudas88  
Started by rbeckmann05, Today, 06:48 PM
0 responses
9 views
0 likes
Last Post rbeckmann05  
Working...
X