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

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 Segwin, 05-07-2018, 02:15 PM
    14 responses
    1,788 views
    0 likes
    Last Post aligator  
    Started by Jimmyk, 01-26-2018, 05:19 AM
    6 responses
    837 views
    0 likes
    Last Post emuns
    by emuns
     
    Started by jxs_xrj, 01-12-2020, 09:49 AM
    6 responses
    3,293 views
    1 like
    Last Post jgualdronc  
    Started by Touch-Ups, Today, 10:36 AM
    0 responses
    12 views
    0 likes
    Last Post Touch-Ups  
    Started by geddyisodin, 04-25-2024, 05:20 AM
    11 responses
    62 views
    0 likes
    Last Post halgo_boulder  
    Working...
    X