I'm trying to develop an indicator with the following charatceristics:
Must use data from NYSE TICK.
Must Calculate EMA n period of the High's and Low's, and then use it to perform
calculations.
I have an error on calculate avgH and avgL using EMA.
Thnak you for your help.
The code is the following (lines in red need help).
namespace NinjaTrader.Indicator
{
/// <summary>
/// Plot a cumulative tick using only high's and Low's above or bellow their EMA's
/// </summary>
[Description("")]
public class CumulativeTick : Indicator
{
#region Variables
// Wizard generated variables
private int nBars = 20; // Default setting for nBars
// User defined variables (add any user defined variables below)
private double tickH = 0;
private double tickL = 0;
private double avgH = 0;
private double avgL = 0;
private double bull = 0;
private double bear = 0;
private double cTick = 0;
#endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
This instruction is right to catch the NYSE TICK data?
Add("^TICK", Bars.Period.Id, Bars.Period.Value);
Add(new Plot(Color.MediumBlue, PlotStyle.Line, "CTick"));
CalculateOnBarClose = false;
DisplayInDataBox = false;
Overlay = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar < 1)
return;
tickH = High[0];
tickL = Low[0];
Error
// avgH = EMA(High[0],20);
// avgL = EMA(Low[0],nBars);
bull=0;
if (tickH > avgH)
bull = tickH - avgH;
bear=0;
if (tickL < avgL)
bear = tickL - avgL;
if (Bars.FirstBarOfSession)
CTick.Set(0);
else
CTick.Set(CTick[1] + bull + bear);
}
#region Properties
[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 CTick
{
get { return Values[0]; }
}
[Description("Numbers of bars used for calculations")]
[GridCategory("Parameters")]
public int BarsPeriod
{
get { return nBars; }
set { nBars = Math.Max(1, value); }
}
#endregion
}
}
Comment