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

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.

    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by junkone, 04-21-2024, 07:17 AM
    10 responses
    148 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by tsantospinto, 04-12-2024, 07:04 PM
    6 responses
    99 views
    0 likes
    Last Post tsantospinto  
    Started by rocketman7, Today, 02:12 AM
    5 responses
    26 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by ZenCortexReal, Today, 08:54 AM
    0 responses
    1 view
    0 likes
    Last Post ZenCortexReal  
    Started by ZenCortexReal, Today, 08:52 AM
    0 responses
    0 views
    0 likes
    Last Post ZenCortexReal  
    Working...
    X