109 lines
3.0 KiB
C#
109 lines
3.0 KiB
C#
#region Using declarations
|
|
using NinjaTrader.Gui;
|
|
using System.Windows.Media;
|
|
#endregion
|
|
|
|
namespace NinjaTrader.NinjaScript.Indicators
|
|
{
|
|
public class HILOIndex : Indicator
|
|
{
|
|
private const int PrimaryBars = 0;
|
|
private const int NewHighsBars = 1;
|
|
private const int NewLowsBars = 2;
|
|
|
|
protected override void OnStateChange()
|
|
{
|
|
if (State == State.SetDefaults)
|
|
{
|
|
Name = "HILO Index";
|
|
Description = @"New 52-Week Highs - New 52-Week Lows";
|
|
Calculate = Calculate.OnPriceChange;
|
|
IsOverlay = false;
|
|
|
|
AddPlot(new Stroke(Brushes.Yellow, DashStyleHelper.Solid, 3), PlotStyle.Line, "HILO Index");
|
|
}
|
|
else if (State == State.Configure)
|
|
{
|
|
AddDataSeries("FINH");
|
|
AddDataSeries("FINL");
|
|
}
|
|
}
|
|
|
|
protected override void OnBarUpdate()
|
|
{
|
|
if (PrimaryBars != BarsInProgress)
|
|
return;
|
|
|
|
if (CurrentBars[NewHighsBars] < 1 || CurrentBars[NewLowsBars] < 1)
|
|
return;
|
|
|
|
double newHighs = BarsArray[NewHighsBars].GetClose(BarsArray[NewHighsBars].GetBar(Time[0]));
|
|
double newLows = BarsArray[NewLowsBars].GetClose(BarsArray[NewLowsBars].GetBar(Time[0]));
|
|
|
|
Value[0] = newHighs - newLows;
|
|
}
|
|
|
|
public override string DisplayName
|
|
{
|
|
get { return Name; }
|
|
}
|
|
}
|
|
}
|
|
|
|
#region NinjaScript generated code. Neither change nor remove.
|
|
|
|
namespace NinjaTrader.NinjaScript.Indicators
|
|
{
|
|
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
|
|
{
|
|
private HILOIndex[] cacheHILOIndex;
|
|
public HILOIndex HILOIndex()
|
|
{
|
|
return HILOIndex(Input);
|
|
}
|
|
|
|
public HILOIndex HILOIndex(ISeries<double> input)
|
|
{
|
|
if (cacheHILOIndex != null)
|
|
for (int idx = 0; idx < cacheHILOIndex.Length; idx++)
|
|
if (cacheHILOIndex[idx] != null && cacheHILOIndex[idx].EqualsInput(input))
|
|
return cacheHILOIndex[idx];
|
|
return CacheIndicator<HILOIndex>(new HILOIndex(), input, ref cacheHILOIndex);
|
|
}
|
|
}
|
|
}
|
|
|
|
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
|
|
{
|
|
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
|
|
{
|
|
public Indicators.HILOIndex HILOIndex()
|
|
{
|
|
return indicator.HILOIndex(Input);
|
|
}
|
|
|
|
public Indicators.HILOIndex HILOIndex(ISeries<double> input )
|
|
{
|
|
return indicator.HILOIndex(input);
|
|
}
|
|
}
|
|
}
|
|
|
|
namespace NinjaTrader.NinjaScript.Strategies
|
|
{
|
|
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
|
|
{
|
|
public Indicators.HILOIndex HILOIndex()
|
|
{
|
|
return indicator.HILOIndex(Input);
|
|
}
|
|
|
|
public Indicators.HILOIndex HILOIndex(ISeries<double> input )
|
|
{
|
|
return indicator.HILOIndex(input);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|