I want to color the zone between 2 EMA's on the main chart.
When the fast EMA upcrosses the slow EMA the zone must be colored ForestGreen
When the fast EMA downcrosses the slow EMA the zone must be colored orange.Red
I have written a script, but nothing is plotted.
Can Someone help me out. What am I doing wrong? I already added some Print commands but they never get executed
namespace NinjaTrader.NinjaScript.Indicators
{
public class EMACrossFillZone : Indicator
{
private Series<double> emaFast;
private Series<double> emaSlow;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Custom Indicator to plot zone between two EMAs with customizable settings";
Name = "EMACrossFillZone";
IsOverlay = true;
FastEMA = 20;
SlowEMA = 110;
FastEMACrossColor = Brushes.OrangeRed;
SlowEMACrossColor = Brushes.ForestGreen;
Opacity = 25;
}
else if (State == State.DataLoaded)
{
emaFast = new Series<double>(this);
emaSlow = new Series<double>(this);
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < SlowEMA || CurrentBar < FastEMA)
return;
emaFast[0] = EMA(Close, FastEMA)[0];
emaSlow[0] = EMA(Close, SlowEMA)[0];
if (CrossAbove(emaFast, emaSlow, 1))
{
PlotBrushes[0][0] = FastEMACrossColor;
Print("Fast EMA Crossed Above Slow EMA");
}
else if (CrossBelow(emaFast, emaSlow, 1))
{
PlotBrushes[0][0] = SlowEMACrossColor;
Print("Slow EMA Crossed Above Fast EMA");
}
else
{
PlotBrushes[0][0] = null;
}
// Plotting zone between EMAs
if (emaFast[0] > emaSlow[0])
{
PlotBrushes[1][0] = FastEMACrossColor;
PlotBrushes[2][0] = null;
Print("Zone Color: " + FastEMACrossColor.ToString());
}
else
{
PlotBrushes[1][0] = null;
PlotBrushes[2][0] = SlowEMACrossColor;
Print("Zone Color: " + SlowEMACrossColor.ToString());
}
}
region Properties
[Range(1, int.MaxValue), NinjaScriptProperty]
public int FastEMA { get; set; }
[Range(1, int.MaxValue), NinjaScriptProperty]
public int SlowEMA { get; set; }
[Display(Name = "Fast EMA Cross Color"), NinjaScriptProperty]
public Brush FastEMACrossColor { get; set; }
[Display(Name = "Slow EMA Cross Color"), NinjaScriptProperty]
public Brush SlowEMACrossColor { get; set; }
[Range(0, 100), NinjaScriptProperty]
public int Opacity { get; set; }
#endregion
}
}
Comment