I applied the ADX indie to a renko chart (lots of bars) and found performance somewhat lacking in fast moves. I took a look at the code. I noticed this
private Series<double> dmPlus;
private Series<double> dmMinus;
private Series<double> sumDmPlus;
private Series<double> sumDmMinus;
private Series<double> sumTr;
private Series<double> tr;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionADX;
Name = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameADX;
IsSuspendedWhileInactive = true;
Period = 14;
AddPlot(Brushes.DarkCyan, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameADX);
AddLine(Brushes.SlateBlue, 25, NinjaTrader.Custom.Resource.NinjaScriptIndicatorLower);
AddLine(Brushes.Goldenrod, 75, NinjaTrader.Custom.Resource.NinjaScriptIndicatorUpper);
}
else if (State == State.DataLoaded)
{
dmPlus = new Series<double>(this);
dmMinus = new Series<double>(this);
sumDmPlus = new Series<double>(this);
sumDmMinus = new Series<double>(this);
sumTr = new Series<double>(this);
tr = new Series<double>(this);
}
}
None of those series is actually required as the code appears to only ever use the [0] and [1] values.
It would seem (and appears) much faster to simply use 2 variables, or as I changed it, private double[] tr = new double[1]; and just shift the values, e.g. tr[1] = tr[0]; on IsFirstTickOfBar.
By my count, this saves at least 6 x 256 count series updating and shifting on each bar! Now, perhaps that is not a huge saving, but the original code does just seem somewhat wasteful of precious resources.
Just a suggestion...
