// Plots PeriodD color when rising or falling
if (IsRising(D)) <<<<------ I get errors starting at this line
{
PlotBrushes[0][0] = DUp;
}
else if (IsFalling(D))
{
PlotBrushes[0][0] = DDown;
// Plots PeriodK color when rising or falling
if (IsRising(K))
{
PlotBrushes[1][0] = KUp;
}
else if (IsFalling(K))
{
PlotBrushes[1] = Kdown;
}
Thank you.
#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.Gui.Tools;
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
{
public class StochasticUpDown : Indicator
{
private Series<double> den;
private Series<double> fastK;
private MIN min;
private MAX max;
private Series<double> nom;
private SMA smaFastK;
private SMA smaK;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionStochastics;
Name = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameStochastics;
IsSuspendedWhileInactive = true;
PeriodD = 7;
PeriodK = 14;
Smooth = 3;
AddPlot(Brushes.DodgerBlue, NinjaTrader.Custom.Resource.StochasticsD);
AddPlot(Brushes.Goldenrod, NinjaTrader.Custom.Resource.StochasticsK);
AddPlot(Brushes.Violet, "DUp");
AddPlot(Brushes.Turquoise, "DDown");
AddPlot(Brushes.LightGreen, "KUp");
AddPlot(Brushes.Red, "KDown");
AddLine(Brushes.Red, 20, NinjaTrader.Custom.Resource.NinjaScriptIndicatorLower);
AddLine(Brushes.Green, 80, NinjaTrader.Custom.Resource.NinjaScriptIndicatorUpper);
AddLine(Brushes.Black, 45, Plotstyle.Dot, "NLower");
AddLine(Brushes.Black, 55, Plotstyle.Dot, "NUpper");
}
else if (State == State.DataLoaded)
{
den = new Series<double>(this);
nom = new Series<double>(this);
fastK = new Series<double>(this);
min = MIN(Low, PeriodK);
max = MAX(High, PeriodK);
smaFastK = SMA(fastK, Smooth);
smaK = SMA(K, PeriodD);
}
}
protected override void OnBarUpdate()
{
double min0 = min[0];
nom[0] = Close[0] - min0;
den[0] = max[0] - min0;
if (den[0].ApproxCompare(0) == 0)
fastK[0] = CurrentBar == 0 ? 50 : fastK[1];
else
fastK[0] = Math.Min(100, Math.Max(0, 100 * nom[0] / den[0]));
// Slow %K == Fast %D
K[0] = smaFastK[0];
D[0] = smaK[0];
}
// Plots PeriodD color when rising or falling
if (IsRising(D))
{
PlotBrushes[0][0] = DUp;
}
else if (IsFalling(D))
{
PlotBrushes[0][0] = DDown;
// Plots PeriodK color when rising or falling
if (IsRising(K))
{
PlotBrushes[1][0] = KUp;
}
else if (IsFalling(K))
{
PlotBrushes[1] = Kdown;
}
#region Properties
[Browsable(false)]
[XmlIgnore()]
public Series<double> D
{
get { return Values[0]; }
}
[Browsable(false)]
[XmlIgnore()]
public Series<double> K
{
get { return Values[1]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> DUp
{
get { return Values[2]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> DDown
{
get { return Values[3]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> KUp
{
get { return Values[4]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> KDown
{
get { return Values[5]; }
}
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "PeriodD", GroupName = "NinjaScriptParameters", Order = 0)]
public int PeriodD
{ get; set; }
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "PeriodK", GroupName = "NinjaScriptParameters", Order = 1)]
public int PeriodK
{ get; set; }
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "Smooth", GroupName = "NinjaScriptParameters", Order = 2)]
public int Smooth
{ get; set; }
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private StochasticUpDown[] cacheStochasticUpDown;
public StochasticUpDown StochasticUpDown(int periodD, int periodK, int smooth)
{
return StochasticUpDown(Input, periodD, periodK, smooth);
}
public StochasticUpDown StochasticUpDown(ISeries<double> input, int periodD, int periodK, int smooth)
{
if (cacheStochasticUpDown != null)
for (int idx = 0; idx < cacheStochasticUpDown.Length; idx++)
if (cacheStochasticUpDown[idx] != null && cacheStochasticUpDown[idx].PeriodD == periodD && cacheStochasticUpDown[idx].PeriodK == periodK && cacheStochasticUpDown[idx].Smooth == smooth && cacheStochasticUpDown[idx].EqualsInput(input))
return cacheStochasticUpDown[idx];
return CacheIndicator<StochasticUpDown>(new StochasticUpDown(){ PeriodD = periodD, PeriodK = periodK, Smooth = smooth }, input, ref cacheStochasticUpDown);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.StochasticUpDown StochasticUpDown(int periodD, int periodK, int smooth)
{
return indicator.StochasticUpDown(Input, periodD, periodK, smooth);
}
public Indicators.StochasticUpDown StochasticUpDown(ISeries<double> input , int periodD, int periodK, int smooth)
{
return indicator.StochasticUpDown(input, periodD, periodK, smooth);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.StochasticUpDown StochasticUpDown(int periodD, int periodK, int smooth)
{
return indicator.StochasticUpDown(Input, periodD, periodK, smooth);
}
public Indicators.StochasticUpDown StochasticUpDown(ISeries<double> input , int periodD, int periodK, int smooth)
{
return indicator.StochasticUpDown(input, periodD, periodK, smooth);
}
}
}
#endregion

Comment