I am using it on a 1-min chart and a 30-sec chart. However when connected, it flatlines. If I reload the ninjascript, then it display correctly.
What am I doing wrong?
public class EMA3Min : Indicator
{
private int period = 1;
protected override void Initialize()
{
Add(PeriodType.Minute, 3);
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "EMA 3-min"));
Overlay = true;
}
protected override void OnBarUpdate()
{
if (CurrentBars[0] <= BarsRequired
|| CurrentBars[1] <= BarsRequired)
return;
if (CurrentBars.Length > 1 && CurrentBars[1] > 0)
Value.Set(EMA(BarsArray[1], period)[0]);
else
Value.Set(Input[0]);
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Plot0
{
get { return Values[0]; }
}
[Description("")]
[GridCategory("Parameters")]
public int Period
{
get { return period; }
set { period = Math.Max(1, value); }
}
}
Comment