namespace NinjaTrader.NinjaScript.Indicators
{
public class MyCustomIndicator : Indicator
{
private SMA sma21;
private EMA ema9;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "Adds 5-minute 21 SMA and 9 EMA to any chart";
Name = "5 Minute 21 sma and 9 ema";
Calculate = Calculate.OnEachTick;
IsOverlay = true;
DisplayInDataBox = true;
//AddPlot(new Stroke(Brushes.Crimson, 2), PlotStyle.Line, "sma");
//AddPlot(new Stroke(Brushes.Goldenrod, 2), PlotStyle.Line, "ema");
AddPlot(new Stroke(Brushes.Pink, DashStyleHelper.Dash, 3, 100), PlotStyle.Line, "sma");
AddPlot(new Stroke(Brushes.Purple, DashStyleHelper.Dash, 2, 75), PlotStyle.Line, "ema");
//AddPlot(Brushes.Goldenrod, "ema");
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Minute, 5);
sma21 = SMA(BarsArray[1], 21);
ema9 = EMA(BarsArray[1], 9);
// Set the plot colors
}
}
protected override void OnBarUpdate()
{
if (CurrentBars[1] < 1)
return;
Values[0][0] = sma21[0];
Values[1][0] = ema9[0];
//Print(Time[0] + " SMA " + Values[0][0]);
//Print(Time[0] + " EMA " + Values[1][0]);
}
}
}

Comment