#region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Gui.Chart; using System.Collections.Generic; #endregion namespace NinjaTrader.Indicator { [Description("Enter the description of your new custom indicator here")] public class Frequency : Indicator { SortedDictionary Tdict = new SortedDictionary(); SortedDictionary hldict = new SortedDictionary(); SortedDictionary ocdict = new SortedDictionary(); SortedDictionary voldict = new SortedDictionary(); int c = 0; protected override void Initialize() { Overlay = false; } protected override void OnBarUpdate() { double hl = High[0] - Low[0]; double oc = Math.Abs(Open[0] - Close[0]); double vol = Volume[0]; string time = Time[0].Hour.ToString(); double t = 0; if (Open[0] < Close[0]) { t = (High[0] - Close[0]) + (Open[0] - Low[0]); } if (Open[0] > Close[0]) { t = (High[0] - Open[0]) + (Close[0] - Low[0]); } if (Open[0] == Close[0]) { t = (High[0] - Close[0]) + (Close[0] - Low[0]); } if (hldict.ContainsKey(time)) { double valueholderHL = hldict[time]; double valueholderOC = ocdict[time]; double valueholderVOL = voldict[time]; double valueholderT = Tdict[time]; hldict.Remove(time); ocdict.Remove(time); voldict.Remove(time); Tdict.Remove(time); hldict.Add(time, valueholderHL + hl); ocdict.Add(time, valueholderOC + oc); voldict.Add(time, valueholderVOL + vol); Tdict.Add(time, valueholderT + t); } else { hldict.Add(time, hl); ocdict.Add(time, oc); voldict.Add(time,vol); Tdict.Add(time,t); } } protected override void OnMarketData(MarketDataEventArgs e) { if (e.MarketDataType == MarketDataType.Last) { if (c == 0) { Print(""); Print("HL"); foreach(KeyValuePair x in hldict) { Print(x.Key + " " + x.Value); } Print(""); Print("OC"); foreach(KeyValuePair x in ocdict) { Print(x.Key + " " + x.Value); } Print(""); Print("VOL"); foreach(KeyValuePair x in voldict) { Print(x.Key + " " + x.Value); } Print(""); Print("TAIL"); foreach(KeyValuePair x in Tdict) { Print(x.Key + " " + x.Value); } c++; } } } #region Properties #endregion } } #region NinjaScript generated code. Neither change nor remove. // This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { public partial class Indicator : IndicatorBase { private Frequency[] cacheFrequency = null; private static Frequency checkFrequency = new Frequency(); /// /// Enter the description of your new custom indicator here /// /// public Frequency Frequency() { return Frequency(Input); } /// /// Enter the description of your new custom indicator here /// /// public Frequency Frequency(Data.IDataSeries input) { if (cacheFrequency != null) for (int idx = 0; idx < cacheFrequency.Length; idx++) if (cacheFrequency[idx].EqualsInput(input)) return cacheFrequency[idx]; lock (checkFrequency) { if (cacheFrequency != null) for (int idx = 0; idx < cacheFrequency.Length; idx++) if (cacheFrequency[idx].EqualsInput(input)) return cacheFrequency[idx]; Frequency indicator = new Frequency(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; #if NT7 indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256; indicator.MaximumBarsLookBack = MaximumBarsLookBack; #endif indicator.Input = input; Indicators.Add(indicator); indicator.SetUp(); Frequency[] tmp = new Frequency[cacheFrequency == null ? 1 : cacheFrequency.Length + 1]; if (cacheFrequency != null) cacheFrequency.CopyTo(tmp, 0); tmp[tmp.Length - 1] = indicator; cacheFrequency = tmp; return indicator; } } } } // This namespace holds all market analyzer column definitions and is required. Do not change it. namespace NinjaTrader.MarketAnalyzer { public partial class Column : ColumnBase { /// /// Enter the description of your new custom indicator here /// /// [Gui.Design.WizardCondition("Indicator")] public Indicator.Frequency Frequency() { return _indicator.Frequency(Input); } /// /// Enter the description of your new custom indicator here /// /// public Indicator.Frequency Frequency(Data.IDataSeries input) { return _indicator.Frequency(input); } } } // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { public partial class Strategy : StrategyBase { /// /// Enter the description of your new custom indicator here /// /// [Gui.Design.WizardCondition("Indicator")] public Indicator.Frequency Frequency() { return _indicator.Frequency(Input); } /// /// Enter the description of your new custom indicator here /// /// public Indicator.Frequency Frequency(Data.IDataSeries input) { if (InInitialize && input == null) throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method"); return _indicator.Frequency(input); } } } #endregion