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 helpwanted, Today, 03:06 AM
    1 response
    7 views
    0 likes
    Last Post sarafuenonly123  
    Started by Brevo, Today, 01:45 AM
    0 responses
    7 views
    0 likes
    Last Post Brevo
    by Brevo
     
    Started by aussugardefender, Today, 01:07 AM
    0 responses
    5 views
    0 likes
    Last Post aussugardefender  
    Started by pvincent, 06-23-2022, 12:53 PM
    14 responses
    242 views
    0 likes
    Last Post Nyman
    by Nyman
     
    Started by TraderG23, 12-08-2023, 07:56 AM
    9 responses
    385 views
    1 like
    Last Post Gavini
    by Gavini
     
    Working...
    X