Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw diamonds on ALL0 bars that matches the criteria, and not only the last.

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

    Draw diamonds on ALL0 bars that matches the criteria, and not only the last.

    Hello,

    What do I need to add in the code so the diamonds are drawn on all previous events? In this case, bar close outside Bollinger Band.


    public class SampleDrawRegion : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "SampleDrawRegion";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = false;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    Period = 14;
    NumStdDev = 2;
    }
    }

    protected override void OnBarUpdate()
    {
    // With the DrawRegion() method you can fill the space inbetween two DataSeries objects very easily.

    // This region fills in the space between the Upper Bollinger Band and the Middle Bollinger Band. The region extends from the first bar of the chart
    // till the last bar of the chart. It has a border color of black and is filled with blue on an opacity setting of 2. Opacity setting ranges from 0-10.
    // 0 being transparent and 10 being completely colored.
    Draw.Region(this, "Bollinger Upper Region", CurrentBar, 0, Bollinger(NumStdDev, Period).Upper, Bollinger(NumStdDev, Period).Middle, Brushes.Black, Brushes.Blue, 20);

    // This region fills the space between the Lower Bollinger Band and the Middle Bollinger Band. It has the same attributes as the previous region, except
    // the blue fill color is darker in this one. If you wish to create a region without a border you can use this color: Color.Transparent
    Draw.Region(this,"Bollinger Lower Region", CurrentBar, 0, Bollinger(NumStdDev, Period).Lower, Bollinger(NumStdDev, Period).Middle, Brushes.Black, Brushes.Blue, 50);

    // Besides filling inbetween two DataSeries objects we can also fill between a double value and a DataSeries.
    // This is demonstrated in the following code segment.

    // If the price closes above the upper bollinger band, color the price region above the bollinger band gold.
    if (Bollinger(NumStdDev, Period).Upper[0] < Close[0])
    {
    // In our string tag we use "+ CurrentBar" to ensure unique tag names for all our regions. If we did not have unique names each call
    // upon the tag would modify the existing DrawRegion() instead of coloring a new one.
    Draw.Region(this,"Upper Bollinger Broken" + CurrentBar, 1, 0, Bollinger(NumStdDev, Period).Upper, High[0], Brushes.Black, 100);
    Draw.Diamond(this, "Diamond High", true, 0, High[0] + TickSize, Brushes.Green);
    }

    // If the price closes below the lower bollinger band, color the price region below the bollinger band gold.
    else if (Bollinger(NumStdDev, Period).Lower[0] > Close[0])
    {
    Draw.Region(this,"Lower Bollinger Broken" + CurrentBar, 1, 0, Bollinger(NumStdDev, Period).Lower, Low[0], Brushes.Black,100);
    Draw.Diamond(this, "Diamond Low", true, 0, Low[0] - TickSize, Brushes.Red);
    }
    }
    Attached Files

    #2
    I found it, I need to add: + CurrentBar

    As this:
    Draw.Diamond(this, "Diamond Low" + CurrentBar, true, 0, Low[0] - TickSize, Brushes.Red);

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    647 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    369 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    108 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    572 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    573 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X