I tried copying the Ninja MACD into a new code window then copying and pasting the original coloring where I set up the conditions, but nothing prints on the chart but it did compile.
The colors I picked are just temporary to see it worked.
I am attaching a screenshot at the very end of how I did it on tradestation. Its a nice visual telling at a glance all you need--the signal line is the red line.
#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.Indicator; using NinjaTrader.Gui.Chart; using NinjaTrader.Strategy; #endregion // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Indicator { /// <summary> /// MACD current bar color depends on length compared to prior histogram bar /// </summary> [Description("MACD current bar color depends on length compared to prior histogram bar")] public class MACDhistogramBarRecolor : Indicator { #region Variables private int fast = 8; private int slow = 18; private int smooth = 9; private DataSeries fastEma; private DataSeries slowEma; #endregion /// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { Add(new Plot(Color.Green, "Macd")); Add(new Plot(Color.DarkViolet, "Avg")); Add(new Plot(new Pen(Color.Navy, 2), PlotStyle.Bar, "Diff")); Add(new Line(Color.Blue, 0, "Zero line")); fastEma = new DataSeries(this); slowEma = new DataSeries(this); } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (CurrentBar == 0) { fastEma.Set(Input[0]); slowEma.Set(Input[0]); Value.Set(0); Avg.Set(0); Diff.Set(0); } else { fastEma.Set((2.0 / (1 + Fast)) * Input[0] + (1 - (2.0 / (1 + Fast))) * fastEma[1]); slowEma.Set((2.0 / (1 + Slow)) * Input[0] + (1 - (2.0 / (1 + Slow))) * slowEma[1]); double macd = fastEma[0] - slowEma[0]; double macdAvg = (2.0 / (1 + Smooth)) * macd + (1 - (2.0 / (1 + Smooth))) * Avg[1]; Value.Set(macd); Avg.Set(macdAvg); Diff.Set(macd - macdAvg); // Condition set 1 if ( MACD(8, 18, 9)[0] > MACD(8, 18, 9)[1]) Add(new Plot(new Pen(Color.Aqua, 2), PlotStyle.Bar, "MACD")); { } // Condition set 2 if ( MACD(8, 18, 9)[0] < MACD(8, 18, 9)[1]) Add(new Plot(new Pen(Color.Navy, 2), PlotStyle.Bar, "MACD")); //Condition set 3 if (MACD(8, 18, 9)[0]>0) Add(new Plot(new Pen(Color.DarkCyan, 2), PlotStyle.Bar, "MACD")); //Condition set4 if (MACD(8, 18, 9)[0]<0) Add(new Plot(new Pen(Color.Silver, 2), PlotStyle.Bar, "MACD")); } { } } #region Properties /// <summary> /// </summary> [Browsable(false)] [XmlIgnore()] public DataSeries Avg { get { return Values[1]; } } /// <summary> /// </summary> [Browsable(false)] [XmlIgnore()] public DataSeries Default { get { return Values[0]; } } /// <summary> /// </summary> [Browsable(false)] [XmlIgnore()] public DataSeries Diff { get { return Values[2]; } } /// <summary> /// </summary> [Description("Number of bars for fast EMA")] [Category("Parameters")] public int Fast { get { return fast; } set { fast = Math.Max(1, value); } } /// <summary> /// </summary> [Description("Number of bars for slow EMA")] [Category("Parameters")] public int Slow { get { return slow; } set { slow = Math.Max(1, value); } } /// <summary> /// </summary> [Description("Number of bars for smoothing")] [Category("Parameters")] public int Smooth { get { return smooth; } set { smooth = 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 MACDhistogramBarRecolor[] cacheMACDhistogramBarRecolor = null; private static MACDhistogramBarRecolor checkMACDhistogramBarRecolor = new MACDhistogramBarRecolor(); /// <summary> /// MACD current bar color depends on length compared to prior histogram bar /// </summary> /// <returns></returns> public MACDhistogramBarRecolor MACDhistogramBarRecolor(int fast, int slow, int smooth) { return MACDhistogramBarRecolor(Input, fast, slow, smooth); } /// <summary> /// MACD current bar color depends on length compared to prior histogram bar /// </summary> /// <returns></returns> public MACDhistogramBarRecolor MACDhistogramBarRecolor(Data.IDataSeries input, int fast, int slow, int smooth) { checkMACDhistogramBarRecolor.Fast = fast; fast = checkMACDhistogramBarRecolor.Fast; checkMACDhistogramBarRecolor.Slow = slow; slow = checkMACDhistogramBarRecolor.Slow; checkMACDhistogramBarRecolor.Smooth = smooth; smooth = checkMACDhistogramBarRecolor.Smooth; if (cacheMACDhistogramBarRecolor != null) for (int idx = 0; idx < cacheMACDhistogramBarRecolor.Length; idx++) if (cacheMACDhistogramBarRecolor[idx].Fast == fast && cacheMACDhistogramBarRecolor[idx].Slow == slow && cacheMACDhistogramBarRecolor[idx].Smooth == smooth && cacheMACDhistogramBarRecolor[idx].EqualsInput(input)) return cacheMACDhistogramBarRecolor[idx]; MACDhistogramBarRecolor indicator = new MACDhistogramBarRecolor(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; indicator.Input = input; indicator.Fast = fast; indicator.Slow = slow; indicator.Smooth = smooth; indicator.SetUp(); MACDhistogramBarRecolor[] tmp = new MACDhistogramBarRecolor[cacheMACDhistogramBarRecolor == null ? 1 : cacheMACDhistogramBarRecolor.Length + 1]; if (cacheMACDhistogramBarRecolor != null) cacheMACDhistogramBarRecolor.CopyTo(tmp, 0); tmp[tmp.Length - 1] = indicator; cacheMACDhistogramBarRecolor = tmp; Indicators.Add(indicator); 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> /// MACD current bar color depends on length compared to prior histogram bar /// </summary> /// <returns></returns> [Gui.Design.WizardCondition("Indicator")] public Indicator.MACDhistogramBarRecolor MACDhistogramBarRecolor(int fast, int slow, int smooth) { return _indicator.MACDhistogramBarRecolor(Input, fast, slow, smooth); } /// <summary> /// MACD current bar color depends on length compared to prior histogram bar /// </summary> /// <returns></returns> public Indicator.MACDhistogramBarRecolor MACDhistogramBarRecolor(Data.IDataSeries input, int fast, int slow, int smooth) { return _indicator.MACDhistogramBarRecolor(input, fast, slow, smooth); } } } // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { public partial class Strategy : StrategyBase { /// <summary> /// MACD current bar color depends on length compared to prior histogram bar /// </summary> /// <returns></returns> [Gui.Design.WizardCondition("Indicator")] public Indicator.MACDhistogramBarRecolor MACDhistogramBarRecolor(int fast, int slow, int smooth) { return _indicator.MACDhistogramBarRecolor(Input, fast, slow, smooth); } /// <summary> /// MACD current bar color depends on length compared to prior histogram bar /// </summary> /// <returns></returns> public Indicator.MACDhistogramBarRecolor MACDhistogramBarRecolor(Data.IDataSeries input, int fast, int slow, int smooth) { 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.MACDhistogramBarRecolor(input, fast, slow, smooth); } } } #endregion
Comment