I created an indicator that tracks the Max Min Middle and extensions based off the 9:30 to 10:30am timeframe. It is calculating everything correctly but this indicator is the highest on the NinjaScript Utilization and takes longer than most indicators to load (about 5 minutes).
I'm hoping to get an idea of where I am calculating too much unnecessarily.
Thanks for any help.
namespace NinjaTrader.NinjaScript.Indicators.Dhonn
{
public class ArangeGuide: Indicator
{
private int period;
private int bar1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "ArangeGuide";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = false;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = false;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
AddPlot(new Stroke(Brushes.Lime),PlotStyle.Hash, "h");
AddPlot(new Stroke(Brushes.Magenta),PlotStyle.Hash, "l");
AddPlot(new Stroke(Brushes.Green),PlotStyle.Line, "ibH");
AddPlot(new Stroke(Brushes.Red),PlotStyle.Line, "ibL");
AddPlot(new Stroke(Brushes.Goldenrod),PlotStyle.Dot, "ibM");
AddPlot(new Stroke(Brushes.Green),PlotStyle.Hash, "extH1");
AddPlot(new Stroke(Brushes.Green),PlotStyle.Hash, "extH2");
AddPlot(new Stroke(Brushes.Green),PlotStyle.Hash, "extH3");
AddPlot(new Stroke(Brushes.Red),PlotStyle.Hash, "extL1");
AddPlot(new Stroke(Brushes.Red),PlotStyle.Hash, "extL2");
AddPlot(new Stroke(Brushes.Red),PlotStyle.Hash, "extL3");
}
else if (State == State.Configure)
{
AddDataSeries(BarsPeriodType.Second,30);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBar > 10)
{
if ((ToTime(Time[0]) < 093000 ))
return;
if (h[1] != 0
&& ibH[1] != 0)
{
h[0] = h[1];
l[0] = l[1];
ibH[0] = ibH[1];
ibL[0] = ibL[1];
ibM[0] = ibM[1];
extH1[0] = extH1[1];
extH2[0] = extH2[1];
extH3[0] = extH3[1];
extL1[0] = extL1[1];
extL2[0] = extL2[1];
extL3[0] = extL3[1];
}
if ((ToTime(Time[0]) == 093000 ))
{
bar1 = CurrentBar;
}
if ((ToTime(Time[0]) >= 093029 ) && (ToTime(Time[0]) <= 103000 ))
{
if (CurrentBar > bar1)
{
period = CurrentBar - bar1;
}
if ( (ToTime(Time[0]) <= 093030))
{
h[0] = Highs[1][0];
l[0] = Lows[1][0];
}
else
{
h[0] = h[1];
l[0] = l[1];
ibH[0] = MAX(High,period)[0];
ibL[0] = MIN(Low,period)[0];
ibM[0] = (ibH[0] + ibL[0]) /2;
extH1[0] = ibH[0] + 15;
extL1[0] = ibL[0] - 21;
if( ibL[0] + 34 > ibH[0])
extH2[0] = ibL[0] + 34;
if( ibL[0] + 10.5 > ibH[0])
extH3[0] = ibL[0] + 10.5;
if( ibH[0] - 10.5 < ibL[0])
extL3[0] = ibH[0] - 10.5;
if( ibH[0] - 34 < ibL[0])
extL2[0] = ibH[0] - 34;
}
}
else
{
h[0] = h[1];
l[0] = l[1];
ibH[0] = ibH[1];
ibL[0] = ibL[1];
ibM[0] = ibM[1];
extH1[0] = extH1[1];
extH2[0] = extH2[1];
extH3[0] = extH3[1];
extL1[0] = extL1[1];
extL2[0] = extL2[1];
extL3[0] = extL3[1];
}
}
}
[Browsable(false)]
[XmlIgnore]
public Series<double> h
{
get { return Values[0]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> l
{
get { return Values[1]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> ibH
{
get { return Values[2]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> ibL
{
get { return Values[3]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> ibM
{
get { return Values[4]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> extH1
{
get { return Values[5]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> extH2
{
get { return Values[6]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> extH3
{
get { return Values[7]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> extL1
{
get { return Values[8]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> extL2
{
get { return Values[9]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> extL3
{
get { return Values[10]; }
}
}
}

Comment