Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Mro

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

    Mro

    Good afternoon, I am using the MRO function.

    protected override void OnBarUpdate()
    {
    // Prints the high price of the most recent up bar over the last 10 bars (current bar + look back period's 9 bars before that)
    int barsAgo = MRO(() => Close[0] > Open[0], 1, 9);
    if (barsAgo > -1)
    Print("The bar high was " + High[barsAgo]);

    In this example, instead of the last 10 bars, which the 9 represents, how can I code for Yesterdays Bar through 10 bars ago? Another words I do not want to include the current bar in the look back period.

    I tried:

    int barsAgo = MRO(() => Close[0] > Open[0], 1, (CurrentBar - 1) - 9);

    and

    int barsAgo = MRO(() => Close[0] > Open[0], 1, 1 - 9);


    this did not seem to work.

    Thanks as always for your help.

    Ryan

    #2
    Hello Tonkingrf1551,

    The MRO works based on a lookback period and not a fixed start and end point so using MRO for this purpose would not be possible. You would need to make a for loop if you wanted to do something for a specific range of bars. The loop would need to loop backward meaning it would start at an index of 10 meaning 10 bars ago from now and then you would loop counting up until you found the occurrence of what you were looking for. For example 10, 11, 12 etc until you reach the index for yesterdays bar. Based on what the loop iterator is when the condition is true would determine the found BarsAgo.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    45 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    21 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    31 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    50 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Working...
    X