Hi I am trying to create an indicator to show when a stochastic is below 20
I would like to show when a 60-10 stochastic is below 20
But it only shows when a 9-3 stochastic is below 20 for some reason?
Thanks
namespace NinjaTrader.NinjaScript.Indicators
{
public class StochasticHighlighter : Indicator
{
private Stochastics stoch60_10;
private double stochValue60_10;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Highlights a vertical bar when 60-10 stochastics are below 20.";
Name = "MyCustomIndicator";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
AddPlot(Brushes.Transparent, "InvisiblePlot"); // Adding an invisible plot to comply with indicator structure
}
else if (State == State.DataLoaded)
{
stoch60_10 = Stochastics(Close, 60, 10, 3);
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < Math.Max(60, 10) || CurrentBar == 0)
return;
stochValue60_10 = stoch60_10.K[0];
if (stochValue60_10 < 20)
{
Draw.VerticalLine(this, "Highlight_" + CurrentBar, 0, Brushes.Red, DashStyleHelper.Solid, 2);
string label = string.Format("Stoch (60-10): {0:F2}", stochValue60_10);
Draw.Text(this, "StochLabel_" + CurrentBar, label, 0, High[0] + TickSize, Brushes.Blue);
}
}
}
}

Comment