I'm still getting my feet wet with NT, and I was hoping you could tell me if this is the most efficient way to implement the following.
1) Many of my indicators use session open gapless series for their calculation. I implemented this by creating an indicator to calculate the gap adjustment:
#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; #endregion // This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { /// <summary> /// Dataseries of session open gap adjustments. Used in creating gapless indicators. /// </summary> [Description("Dataseries of session open gap adjustments. Used in creating gapless indicators.")] public class GtGapAdjustment : Indicator { #region Variables // Wizard generated variables private double gapPercent = 0; // Default setting for GapPercent // User defined variables (add any user defined variables below) #endregion /// <summary> /// This method is used to configure the indicator and is called once before any bar data is loaded. /// </summary> protected override void Initialize() { Add(new Plot(Color.Cyan, "GapAdj")); Overlay = false; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { // Use this method for calculating your indicator values. Assign a value to each // plot below by replacing 'Close[0]' with your own formula. if (CurrentBar == 0) Value.Set(0d); else if (Bars.FirstBarOfSession && FirstTickOfBar) Value.Set(Value[1] + ( gapPercent * 0.01 * (Open[0] - Close[1]))); else Value.Set(Value[1]); } #region Properties [Description("Gap Percent")] [GridCategory("Parameters")] public double GapPercent { get { return gapPercent; } set { gapPercent = Math.Min(100, Math.Max(0, value)); } } #endregion } }
An example of how I would use it is as follows:
DataSeries highGapless = GtGaplessBars().HighGapless;
double tmp = SMA(highGapless, 30)[0] + GtGaplessBars().GapAdjustment[0]);
Is this the best way to approach it?
#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; #endregion namespace NinjaTrader.Indicator { [Description("Bar series where session open gaps are eliminated.")] public class GtGaplessBars : Indicator { #region Variables private double gapPercent = 0; private DataSeries gapAdjustment; private DataSeries openGapless; private DataSeries highGapless; private DataSeries lowGapless; private DataSeries closeGapless; #endregion protected override void Initialize() { gapAdjustment = new DataSeries(this); openGapless = new DataSeries(this); highGapless = new DataSeries(this); lowGapless = new DataSeries(this); closeGapless = new DataSeries(this); } protected override void OnBarUpdate() { gapAdjustment.Set(GtGapAdjustment(gapPercent)[0]); openGapless.Set(Open[0] - gapAdjustment[0]); highGapless.Set(High[0] - gapAdjustment[0]); lowGapless.Set(Low[0] - gapAdjustment[0]); closeGapless.Set(Close[0] - gapAdjustment[0]); } #region Properties [Description("Gap percent (0 = no gap, 100 = unadjusted)")] [GridCategory("Parameters")] public double GapPercent { get { return gapPercent; } set { gapPercent = Math.Min(100, Math.Max(0, value)); } } [Browsable(false)] [XmlIgnore()] public DataSeries OpenGapless { get { return openGapless; } } [Browsable(false)] [XmlIgnore()] public DataSeries HighGapless { get { return highGapless; } } [Browsable(false)] [XmlIgnore()] public DataSeries LowGapless { get { return lowGapless; } } [Browsable(false)] [XmlIgnore()] public DataSeries CloseGapless { get { return closeGapless; } } [Browsable(false)] [XmlIgnore()] public DataSeries GapAdjustment { get { return gapAdjustment; } } #endregion } }
Comment