All I am trying to do is to color the FisherTransform a different color if it is going up or down.
Here is my attempt, I don't know why this doesn't work. Please help.
Here is the error I am getting:
Indicator 'MFFTCCI': Error on calling 'OnCalculateMinMax' method on bar -1: Value cannot be null.
Parameter name: brush
// This namespace holds indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
/// <summary>
/// The Commodity Channel Index (MFFTCCI) 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>
public class MFFTCCI : Indicator
{
private Brush downColor;
private Brush upColor;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionCCI;
Name = "MFFTCCI";
IsSuspendedWhileInactive = true;
Calculate = Calculate.OnEachTick;
// BarsRequiredToPlot = 50; // Do not plot until this bar on the chart
CCIPeriod = 6;
FTPeriod = 10;
// downColor = Brushes.Red;
// upColor = Brushes.Green;
AddPlot(Brushes.Blue, "CCI");
AddPlot(Brushes.Magenta, "FT");
AddLine(Brushes.DarkGray, 200, "Level 2");
AddLine(Brushes.DarkGray, 100, "Level 1");
AddLine(Brushes.Black, 0, "Zero line");
AddLine(Brushes.DarkGray, -100, "Level -1");
AddLine(Brushes.DarkGray, -200, "Level -2");
}
else if (State == State.Configure)
{
Plots[0].Width = 1; // CCI
Plots[1].Width = 2; // FT
// setup for color coding the plot if it is going up or down
Brush downColor = Plots[1].Brush.Clone();
Brush upColor = Plots[1].Brush.Clone();
downColor = Brushes.Red;
upColor = Brushes.Green;
}
}
protected override void OnBarUpdate()
{
// if (CurrentBar <= BarsRequiredToPlot)
// {
// Value[0] = 0;
// FT[0] = 0;
// }
// else
{
// calc CCI
Value[0] = CCI(CCIPeriod)[0];
// calc FT
FT[0] = FisherTransform (FTPeriod)[0] * 20;
if (IsRising (FT))
{
Plots[1].Brush = upColor;
} else {
// Plots[1].Brush = downColor;
}
}
}
#region Properties
[Browsable(false)]
[XmlIgnore]
public Series<double> Default
{
get { return Values[0]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> FT
{
get { return Values[1]; }
}
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "CCIPeriod", Description="CCI Period", GroupName = "NinjaScriptParameters", Order = 0)]
public int CCIPeriod
{ get; set; }
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "FTPeriod", Description="Fisher Transform Period", GroupName = "NinjaScriptParameters", Order = 1)]
public int FTPeriod
{ get; set; }
// [Range(-200, 0), NinjaScriptProperty]
// [Display(ResourceType = typeof(Custom.Resource), Name = "CCIBuyLevel", Description="CCI Buy Level", GroupName = "NinjaScriptParameters", Order = 2)]
// public int CCIBuyLevel
// { get; set; }
//
// [Range(1, 200), NinjaScriptProperty]
// [Display(ResourceType = typeof(Custom.Resource), Name = "CCISellLevel", Description="CCI Sell Level", GroupName = "NinjaScriptParameters", Order = 3)]
// public int CCISellLevel
// { get; set; }
#endregion
}
}
Comment