The idea is to create an indicator with the characteristics of two Donchian channels within the same indicator and to color certain spaces.
Before moving on to the color stage, I try to make the two channel segments coexist.
The code does not show me any errors, however it no longer works in ninjatrader.
Could this come from the second section of the Addplot?
// // Copyright (C) 2023, NinjaTrader LLC <www.ninjatrader.com>. // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release. // #region Using declarations using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using NinjaTrader.Gui.SuperDom; using NinjaTrader.Data; using NinjaTrader.NinjaScript; using NinjaTrader.Core.FloatingPoint; using NinjaTrader.NinjaScript.DrawingTools; #endregion // This namespace holds indicators in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.Indicators { /// <summary> /// Donchian Channel. The Donchian Channel indicator was created by Richard Donchian. /// It uses the highest high and the lowest low of a period of time to plot the channel. /// </summary> [HR][/HR] public class CanalDC : Indicator { private MAX max; private MIN min; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionDonchianChannel; Name = "CanalDC"; IsOverlay = true; IsSuspendedWhileInactive = true; PeriodH = 50; PeriodB = 20; AddPlot(Brushes.Goldenrod, NinjaTrader.Custom.Resource.DonchianChannelMean); AddPlot(Brushes.DodgerBlue, NinjaTrader.Custom.Resource.NinjaScriptIndicatorUpper); AddPlot(Brushes.DodgerBlue, NinjaTrader.Custom.Resource.NinjaScriptIndicatorLower); [COLOR=#e74c3c] AddPlot(Brushes.Goldenrod, NinjaTrader.Custom.Resource.DonchianChannelMean); AddPlot(Brushes.DodgerBlue, NinjaTrader.Custom.Resource.NinjaScriptIndicatorUpper); AddPlot(Brushes.DodgerBlue, NinjaTrader.Custom.Resource.NinjaScriptIndicatorLower);[/COLOR] } else if (State == State.DataLoaded) { max = MAX(High, [COLOR=#e74c3c]PeriodH[/COLOR]); min = MIN(Low, [COLOR=#e74c3c]PeriodH[/COLOR]); max = MAX(High, [COLOR=#27ae60]PeriodB[/COLOR]); min = MIN(Low, [COLOR=#27ae60]PeriodB[/COLOR]); } } protected override void OnBarUpdate() { double max0 = max[0]; double min0 = min[0]; Value[0] = (max0 + min0) / 2; Upper[0] = max0; Lower[0] = min0; double max1 = max[0]; double min1 = min[0]; Value[0] = (max1 + min1) / 2; Upper[0] = max1; Lower[0] = min1; } #region Properties [Browsable(false)] [XmlIgnore()] public Series<double> Lower { get { return Values[2]; } } [Browsable(false)] [XmlIgnore()] public Series<double> Mean { get { return Values[0]; } } [Range(1, int.MaxValue), NinjaScriptProperty] [Display(ResourceType = typeof(Custom.Resource), Name = "[COLOR=#27ae60]PeriodH[/COLOR]", GroupName = "NinjaScriptParameters", Order = 0)] public int [COLOR=#27ae60]PeriodH[/COLOR] { get; set; } [Browsable(false)] [XmlIgnore()] public Series<double> Upper { get { return Values[1]; } } #endregion #region Properties [Browsable(false)] [XmlIgnore()] public Series<double> Lower2 { get { return Values[2]; } } [Browsable(false)] [XmlIgnore()] public Series<double> Mean2 { get { return Values[0]; } } [Range(1, int.MaxValue), NinjaScriptProperty] [Display(ResourceType = typeof(Custom.Resource), Name = "[COLOR=#27ae60]PeriodB[/COLOR]", GroupName = "NinjaScriptParameters", Order = 0)] public int [COLOR=#27ae60]PeriodB[/COLOR] { get; set; } [Browsable(false)] [XmlIgnore()] public Series<double> Upper2 { get { return Values[1]; } } #endregion } } #region NinjaScript generated code. Neither change nor remove. namespace NinjaTrader.NinjaScript.Indicators { public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase { private CanalDC[] cacheCanalDC; public CanalDC CanalDC(int [COLOR=#27ae60]periodH[/COLOR], int [COLOR=#27ae60]periodB[/COLOR]) { return CanalDC(Input, periodH, periodB); } public CanalDC CanalDC(ISeries<double> input, int periodH, int periodB) { if (cacheCanalDC != null) for (int idx = 0; idx < cacheCanalDC.Length; idx++) if (cacheCanalDC[idx] != null && cacheCanalDC[idx].PeriodH == periodH && cacheCanalDC[idx].PeriodB == periodB && cacheCanalDC[idx].EqualsInput(input)) return cacheCanalDC[idx]; return CacheIndicator<CanalDC>(new CanalDC(){ PeriodH = periodH, PeriodB = periodB }, input, ref cacheCanalDC); } } } namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns { public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase { public Indicators.CanalDC CanalDC(int periodH, int periodB) { return indicator.CanalDC(Input, periodH, periodB); } public Indicators.CanalDC CanalDC(ISeries<double> input , int periodH, int periodB) { return indicator.CanalDC(input, periodH, periodB); } } } namespace NinjaTrader.NinjaScript.Strategies { public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase { public Indicators.CanalDC CanalDC(int periodH, int periodB) { return indicator.CanalDC(Input, periodH, periodB); } public Indicators.CanalDC CanalDC(ISeries<double> input , int periodH, int periodB) { return indicator.CanalDC(input, periodH, periodB); } } } #endregion
Comment