diff --git a/indicators/hilo-index/HILOIndex.cs b/indicators/hilo-index/HILOIndex.cs new file mode 100644 index 0000000..573acba --- /dev/null +++ b/indicators/hilo-index/HILOIndex.cs @@ -0,0 +1,108 @@ +#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 = @""; + 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 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(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 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 input ) + { + return indicator.HILOIndex(input); + } + } +} + +#endregion