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

Smallest 2-Bar Range in Last 20 Bars

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

    Smallest 2-Bar Range in Last 20 Bars

    I am trying to find a way to figure out the smallest 2-bar range over the past 20 bars and plot a dot over it and/or change the color of the bar.

    Here is my code:
    __________________________________________________ ___

    double Two_Bar_High = Math.Max(High[1], High[0]); // Calculate 2-bar hi
    double Two_Bar_Low = Math.Min(Low[1], Low[0]); // Calculate 2-bar lo
    Two_Bar_Range.Set(Two_Bar_High - Two_Bar_Low); // 2-bar range
    double Smallest_Range = MIN(Two_Bar_Range, 20)[0];

    if (Two_Bar_Range[0] == Smallest_Range)
    {
    BarColorSeries[0] = Color.Black;
    BarColorSeries[1] = Color.Black;
    DrawDot("0"+CurrentBar, true, 0, High[0] + Offset, Color.Black);
    DrawDot("1"+CurrentBar, true, 1, High[1] + Offset, Color.Black);
    }


    else if (Two_Bar_Range[1] == Smallest_Range)
    {
    BarColorSeries[1] = Color.Black;
    BarColorSeries[2] = Color.Black;
    DrawDot("1a"+CurrentBar, true, 1, High[1] + Offset, Color.Black);
    DrawDot("2"+CurrentBar, true, 2, High[2] + Offset, Color.Black);
    }

    else if (Two_Bar_Range[2] == Smallest_Range)
    {
    BarColorSeries[2] = Color.Black;
    BarColorSeries[3] = Color.Black;
    DrawDot("2a"+CurrentBar, true, 2, High[2] + Offset, Color.Black);
    DrawDot("3"+CurrentBar, true, 3, High[3] + Offset, Color.Black);
    }

    ..... and so on up to [20].
    __________________________________________________ ___

    This code almost works, but not quite. It sometimes plots signals on 3 bars in a row when the condition is satisfied on back-to-back bars. It also fails to plot any signals at all for over 20 bars on some occasions. I need it to be able to "repaint" bars and signals correctly.

    Any suggestions?

    #2
    Hello,

    Please create only one thread for your inquiry. Please respond to my post in the thread at the following link: http://www.ninjatrader.com/support/f...128#post369128

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by judysamnt7, 03-13-2023, 09:11 AM
    4 responses
    53 views
    0 likes
    Last Post DynamicTest  
    Started by ScottWalsh, Today, 06:52 PM
    4 responses
    32 views
    0 likes
    Last Post ScottWalsh  
    Started by olisav57, Today, 07:39 PM
    0 responses
    5 views
    0 likes
    Last Post olisav57  
    Started by trilliantrader, Today, 03:01 PM
    2 responses
    19 views
    0 likes
    Last Post helpwanted  
    Started by cre8able, Today, 07:24 PM
    0 responses
    6 views
    0 likes
    Last Post cre8able  
    Working...
    X