I have zero programming skills. However, I have attempted to alter the standard NT7 CCI indicator such that it plots Lime when rising and green when falling. This is my first attempt at programming and I simply tried to copy the sequence of code from another indicator that changes plot style based on rising and falling values.
I post the code below in full and also attach the indicator file
The compiler is telling me I have issues in the #region properties lines of code
I'd really appreciate some assistance.
Bondi9999
------------------------------------------------------------------------------------------------------
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// The Commodity Channel Index (CCIColor) measures the variation of a security's price from its statistical mean. High values show that prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.
/// </summary>
[Description("The Commodity Channel Index (CCIColor) measures the variation of a security's price from its statistical mean. High values show that prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.")]
public class CCIColor : Indicator
{
#region Variables
private int period = 14;
#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.Lime, "CCIRising"));
Add(new Plot(Color.DarkRed, "CCIFalling"));
Add(new Line(Color.DarkGray, 200, "Level 2"));
Add(new Line(Color.DarkGray, 100, "Level 1"));
Add(new Line(Color.DarkGray, 0, "Zero line"));
Add(new Line(Color.DarkGray, -100, "Level -1"));
Add(new Line(Color.DarkGray, -200, "Level -2"));
}
/// <summary>
/// Calculates the indicator value(s) at the current index.
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar == 0)
Value.Set(0);
else
{
double mean = 0;
for (int idx = Math.Min(CurrentBar, Period - 1); idx >= 0; idx--)
mean += Math.Abs(Typical[idx] - SMA(Typical, Period)[0]);
Value.Set((Typical[0] - SMA(Typical, Period)[0]) / (mean == 0 ? 1 : (0.015 * (mean / Math.Min(Period, CurrentBar + 1)))));
}
if(CCIColor[1] < CCIColor[0])
{
CCIRising[1] = CCIColor[1];
CCIRising.Set(CCIColor[0]);
}
else
CCIFalling[1] = CCIColor[1];
CCIFalling.Set(CCIColor[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 CCIFalling
{
get { return Value [1]; }
}
[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 CCIRising
{
get { return Values[0]; }
}
[Description("Numbers of bars used for calculations")]
[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 CCIColor[] cacheCCIColor = null;
private static CCIColor checkCCIColor = new CCIColor();
/// <summary>
/// The Commodity Channel Index (CCIColor) measures the variation of a security's price from its statistical mean. High values show that prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.
/// </summary>
/// <returns></returns>
public CCIColor CCIColor(int period)
{
return CCIColor(Input, period);
}
/// <summary>
/// The Commodity Channel Index (CCIColor) measures the variation of a security's price from its statistical mean. High values show that prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.
/// </summary>
/// <returns></returns>
public CCIColor CCIColor(Data.IDataSeries input, int period)
{
if (cacheCCIColor != null)
for (int idx = 0; idx < cacheCCIColor.Length; idx++)
if (cacheCCIColor[idx].Period == period && cacheCCIColor[idx].EqualsInput(input))
return cacheCCIColor[idx];
lock (checkCCIColor)
{
checkCCIColor.Period = period;
period = checkCCIColor.Period;
if (cacheCCIColor != null)
for (int idx = 0; idx < cacheCCIColor.Length; idx++)
if (cacheCCIColor[idx].Period == period && cacheCCIColor[idx].EqualsInput(input))
return cacheCCIColor[idx];
CCIColor indicator = new CCIColor();
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();
CCIColor[] tmp = new CCIColor[cacheCCIColor == null ? 1 : cacheCCIColor.Length + 1];
if (cacheCCIColor != null)
cacheCCIColor.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheCCIColor = 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>
/// The Commodity Channel Index (CCIColor) measures the variation of a security's price from its statistical mean. High values show that prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.CCIColor CCIColor(int period)
{
return _indicator.CCIColor(Input, period);
}
/// <summary>
/// The Commodity Channel Index (CCIColor) measures the variation of a security's price from its statistical mean. High values show that prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.
/// </summary>
/// <returns></returns>
public Indicator.CCIColor CCIColor(Data.IDataSeries input, int period)
{
return _indicator.CCIColor(input, period);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// The Commodity Channel Index (CCIColor) measures the variation of a security's price from its statistical mean. High values show that prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.CCIColor CCIColor(int period)
{
return _indicator.CCIColor(Input, period);
}
/// <summary>
/// The Commodity Channel Index (CCIColor) measures the variation of a security's price from its statistical mean. High values show that prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.
/// </summary>
/// <returns></returns>
public Indicator.CCIColor CCIColor(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.CCIColor(input, period);
}
}
}
#endregion
Comment