Announcement

Collapse
No announcement yet.

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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    132 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    74 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    117 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    113 views
    1 like
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    89 views
    0 likes
    Last Post CarlTrading  
    Working...
    X