I am trying to create a $ATR Indicator, for which I'm using the formula:
$ATR = ATR * PointValue
However I'm running into some problems that I haven't been able to figure out. I thought I'd just use the existing ATR indicator and multiply it's Value[0] with the PointValue, like this:
public class DollarATR : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionATR;
Name = "$ATR";
IsSuspendedWhileInactive = true;
Period = 14;
AddPlot(Brushes.DarkCyan, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameATR);
}
}
protected override void OnBarUpdate()
{
double PointValue = Instrument.MasterInstrument.PointValue;
double high0 = High[0];
double low0 = Low[0];
if (CurrentBar == 0)
Value[0] = (high0 - low0) * PointValue;
else
{
double close1 = Close[1];
double trueRange = Math.Max(Math.Abs(low0 - close1), Math.Max(high0 - low0, Math.Abs(high0 - close1)));
Value[0] = (((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, Period)) * PointValue;
Print("Point Value: " + PointValue + " $ATR: " + Value[0]);
}
}
From the Output I see that it seems to grow at a rate of something like 33 ^ x:
The first lines:
Does anyone know why this error occurs and how I might solve it? Is there a better way to code this indicator?
Sincerely,
Axel


Comment