I am trying to set up a new indicator based on Stochastics values on 5 mins and 10 mins data.
I am setting 5 minutes as primary and adding 10 minutes data by using:
AddDataSeries(Data.BarsPeriodType.Minute, 10);
The logic is as following:
1. If on 5 minutes, Stochastics K and D both >= 80, then kd = kd + 5;
1. If on 5 minutes, Stochastics K and D both <= 20, then kd = kd - 5;
1. If on 10 minutes, Stochastics K and D both >= 80, then kd = kd + 10;
1. If on 10 minutes, Stochastics K and D both >= 80, then kd = kd - 10;
To use the primary array, am I supposed to use BarsArray[0]? For the secondary data, it should be BarsArray[1]??
The code I have does not plot anything.
public class KDJ : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Mark K + D";
Name = "KDJ";
Calculate = Calculate.OnEachTick;
IsOverlay = false;
DisplayInDataBox = false;
DrawOnPricePanel = false;
DrawHorizontalGridLines = false;
DrawVerticalGridLines = false;
PaintPriceMarkers = false;
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;
AddLine(Brushes.Orange, 0.5, "Zero");
AddPlot(new Stroke(Brushes.Orange, 2), PlotStyle.Bar, "KD");
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Minute, 10);
}
}
protected override void OnBarUpdate()
{
//Add your custom indicator logic here.
double kd = 0;
//For the 5 minutes data
if (Stochastics(BarsArray[0],3, 9, 3).D[0]>=80 & Stochastics(BarsArray[0],3, 9, 3).K[0]>=80)
{
kd = kd + 5;
}
else if (Stochastics(BarsArray[0],3, 9, 3).D[0]>=80 & Stochastics(BarsArray[0],3, 9, 3).K[0]>=80)
{
kd= kd - 5;
}
else{
kd = 0;
}
//For the 10 minutes data
if (Stochastics(BarsArray[1],3, 9, 3).D[0]>=80 & Stochastics(BarsArray[1],3, 9, 3).K[0]>=80)
{
kd = kd + 10;
}
else if (Stochastics(BarsArray[1],3, 9, 3).D[0]>=80 & Stochastics(BarsArray[1],3, 9, 3).K[0]>=80)
{
kd= kd - 10;
}
else{
kd = 0;
}
KD[0] = kd;
}
Comment