private double ao = 0; // EMA difference
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"AOEMA with a exponential moving average.";
Name = "AOEMAma";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
DisplayInDataBox = true;
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;
EMA1 = 5;
EMA2 = 34;
EMA_Period = 5;
AddPlot(new Stroke(Brushes.Lime, 2), PlotStyle.Bar, "AOBarPlot");
AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.Bar, "AOLinePlot");
AddLine(Brushes.Gray, 0, "ZeroLine");
AddPlot(Brushes.Blue, "EMALine");
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
ao = EMA(Median,EMA1)[0] - EMA(Median,EMA2)[0]; // Get EMA difference
AOBarPlot[0] = ao; // plot the bar histogram
AOLinePlot[0] = ao; // plot the line on top of the histogram
//Value[4][0] = EMA(aoEMA2(EMA1,EMA2),EMA_Period)[0];
if (IsRising(AOBarPlot)) // Color Bar based on Current value to initial value
{
PlotBrushes[0][0] = Brushes.Lime;
Value[4][0] = EMA(aoEMA2(EMA1,EMA2),EMA_Period)[0];
}
else
{
PlotBrushes[0][0] = Brushes.Red;
Value[4][0] = EMA(aoEMA2(EMA1,EMA2),EMA_Period)[0];
}
}

Comment