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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    559 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    546 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X