I don't know what I did wrong, it's stil the same code as I wrote when it was working.
Can anyone please can look into the code and see what I have done wrong?
public class TSDivergence : Indicator
{
private bool positiveBarClose;
private bool negativeBarClose;
private bool positiveStochClose;
private bool negativeStochClose;
private int periodD;
private int periodK;
private int smooth;
private Series<double> value;
private Series<double> macdVal;
private Series<double> macdAvg;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "TS Divergence";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
}
else if (State == State.DataLoaded)
{
value = new Series<double>(this);
macdVal = new Series<double>(this);
macdAvg = new Series<double>(this);
}
}
protected override void OnBarUpdate()
{
//Add your custom indicator logic here.
value[0] = Stochastics(3, 5, 3).K[0];
macdVal[0] = MACD(12, 26, 9)[0];
macdAvg[0] = MACD(12, 26, 9).Avg[0];
positiveBarClose = Close[0] > Close[1];
negativeBarClose = Close[0] < Close[1];
positiveStochClose = value[0] > value[1];
negativeStochClose = value[0] < value[1];
if (macdVal[0] < macdAvg[0]) {
if (negativeBarClose & positiveStochClose) {
Draw.Diamond(this, "Down " + CurrentBar.ToString(), false, 0, Close[0] + 0 * TickSize, Brushes.Orange);
}
}
if (macdVal[0] > macdAvg[0]) {
if (positiveBarClose & negativeStochClose) {
Draw.Diamond(this, "Up" + CurrentBar.ToString(), false, 0, Close[0] - 0 * TickSize, Brushes.Cyan);
}
}
}
}
Comment