Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Donchian Channel Breakout

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

    Donchian Channel Breakout

    I want to code the breakout and breakdown of the Donchian Channel. I want a dot placed at the high of the bar that breaks the upper donchian channel and dot placed at the low of the bar that breaks the lower donchian channel.

    I have use the Ninja Script Editor to write the code but I do not know how to apply the donchian channel upper and lower lines to the code.

    Below is the code that I used also a chart of what I have so far.

    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    #endregion

    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    /// <summary>
    /// Plots the break out and breakdown of any instrument.
    /// </summary>
    [Description("Plots the break out and breakdown of any instrument.")]
    public class NopayneDonchian : Indicator
    {
    #region Variables
    // Wizard generated variables
    private int period = 20; // Default setting for Period
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Dot, "Breakout"));
    Add(new Plot(Color.FromKnownColor(KnownColor.DarkViolet), PlotStyle.Dot, "Breakdown"));
    Overlay = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    Breakout.Set(High[0]);
    Breakdown.Set(Low[0]);
    }

    #region Properties
    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries Breakout
    {
    get { return Values[0]; }
    }

    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries Breakdown
    {
    get { return Values[1]; }
    }

    [Description("Number of bars used")]
    [GridCategory("Parameters")]
    public int Period
    {
    get { return period; }
    set { period = Math.Max(1, value); }
    }
    #endregion
    }
    }

    #region NinjaScript generated code. Neither change nor remove.
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    public partial class Indicator : IndicatorBase
    {
    private NopayneDonchian[] cacheNopayneDonchian = null;

    private static NopayneDonchian checkNopayneDonchian = new NopayneDonchian();

    /// <summary>
    /// Plots the break out and breakdown of any instrument.
    /// </summary>
    /// <returns></returns>
    public NopayneDonchian NopayneDonchian(int period)
    {
    return NopayneDonchian(Input, period);
    }

    /// <summary>
    /// Plots the break out and breakdown of any instrument.
    /// </summary>
    /// <returns></returns>
    public NopayneDonchian NopayneDonchian(Data.IDataSeries input, int period)
    {
    if (cacheNopayneDonchian != null)
    for (int idx = 0; idx < cacheNopayneDonchian.Length; idx++)
    if (cacheNopayneDonchian[idx].Period == period && cacheNopayneDonchian[idx].EqualsInput(input))
    return cacheNopayneDonchian[idx];

    lock (checkNopayneDonchian)
    {
    checkNopayneDonchian.Period = period;
    period = checkNopayneDonchian.Period;

    if (cacheNopayneDonchian != null)
    for (int idx = 0; idx < cacheNopayneDonchian.Length; idx++)
    if (cacheNopayneDonchian[idx].Period == period && cacheNopayneDonchian[idx].EqualsInput(input))
    return cacheNopayneDonchian[idx];

    NopayneDonchian indicator = new NopayneDonchian();
    indicator.BarsRequired = BarsRequired;
    indicator.CalculateOnBarClose = CalculateOnBarClose;
    #if NT7
    indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
    indicator.MaximumBarsLookBack = MaximumBarsLookBack;
    #endif
    indicator.Input = input;
    indicator.Period = period;
    Indicators.Add(indicator);
    indicator.SetUp();

    NopayneDonchian[] tmp = new NopayneDonchian[cacheNopayneDonchian == null ? 1 : cacheNopayneDonchian.Length + 1];
    if (cacheNopayneDonchian != null)
    cacheNopayneDonchian.CopyTo(tmp, 0);
    tmp[tmp.Length - 1] = indicator;
    cacheNopayneDonchian = tmp;
    return indicator;
    }
    }
    }
    }

    // This namespace holds all market analyzer column definitions and is required. Do not change it.
    namespace NinjaTrader.MarketAnalyzer
    {
    public partial class Column : ColumnBase
    {
    /// <summary>
    /// Plots the break out and breakdown of any instrument.
    /// </summary>
    /// <returns></returns>
    [Gui.Design.WizardCondition("Indicator")]
    public Indicator.NopayneDonchian NopayneDonchian(int period)
    {
    return _indicator.NopayneDonchian(Input, period);
    }

    /// <summary>
    /// Plots the break out and breakdown of any instrument.
    /// </summary>
    /// <returns></returns>
    public Indicator.NopayneDonchian NopayneDonchian(Data.IDataSeries input, int period)
    {
    return _indicator.NopayneDonchian(input, period);
    }
    }
    }

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    public partial class Strategy : StrategyBase
    {
    /// <summary>
    /// Plots the break out and breakdown of any instrument.
    /// </summary>
    /// <returns></returns>
    [Gui.Design.WizardCondition("Indicator")]
    public Indicator.NopayneDonchian NopayneDonchian(int period)
    {
    return _indicator.NopayneDonchian(Input, period);
    }

    /// <summary>
    /// Plots the break out and breakdown of any instrument.
    /// </summary>
    /// <returns></returns>
    public Indicator.NopayneDonchian NopayneDonchian(Data.IDataSeries input, int period)
    {
    if (InInitialize && input == null)
    throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

    return _indicator.NopayneDonchian(input, period);
    }
    }
    }
    #endregion
    Attached Files

    #2
    ap29680, if I'm interpreting your code right, you could do something like this:
    Code:
    if (High[0] > Breakout[0])
       DrawDot("up dot" + CurrentBar, false, 0, High[0], Color.Green);
    AustinNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    576 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    334 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
    553 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    551 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X