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 SharkTankValue, Today, 03:19 AM
    0 responses
    2 views
    0 likes
    Last Post SharkTankValue  
    Started by Sheridan, Yesterday, 11:06 AM
    1 response
    26 views
    0 likes
    Last Post NinjaTrader_Jason  
    Started by JasmneGardne, Today, 01:07 AM
    0 responses
    22 views
    0 likes
    Last Post JasmneGardne  
    Started by ttodua, 01-28-2018, 04:24 PM
    6 responses
    975 views
    0 likes
    Last Post Heart
    by Heart
     
    Started by jeronymite, Yesterday, 10:22 PM
    0 responses
    31 views
    0 likes
    Last Post jeronymite  
    Working...
    X