I have adapted the Bar Numbering indicator so that I can tell it what the first number on the chart should be - e.g. 1 or 2 or 3, since I want to see even numbers on the chart as a personal preference but the indicator always gave me odd numbers.
However I modified the indicator to do these but on loading every day, it doesn't work.
I works when I open the indicator properties and set the parameter value manually, but somehow NT7 doesn't save the value to redisplay next time I open the chart.
Here's my code - perhaps there something obvious:
public class BarNumbers : Indicator { private int offset = 5; private Color textColor = Color.Gray; private Placement numberPosition = Placement.Bottom; private double y; private int sessionBar = 0; private int difference = 0; private int divisor = 3; private int start = 0; private int increment = 1; Font textFont = new Font("Verdana", 8F); protected override void Initialize() { CalculateOnBarClose = true; Overlay = true; PriceTypeSupported = false; } protected override void OnBarUpdate() { if (Bars.FirstBarOfSession) { sessionBar = 0; difference = CurrentBar; } if ((sessionBar + difference) != CurrentBar) { sessionBar = sessionBar + 1; } if (numberPosition == Placement.Bottom) y = (Low[0]-(TickSize*offset)); else y = (High[0] +(TickSize*offset)); if ((CurrentBar + start) % divisor == 0) DrawText("tag" + CurrentBar, true, "" + (sessionBar / increment), 0, y, 0, textColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0); } [Description("Text Font")] [Category("Bar Numbers")] [Gui.Design.DisplayName("Text Font")] [VisualizationOnly, XmlIgnore] public System.Drawing.Font TextFont { get {return this.textFont;} set {this.textFont = value;} } [Description("Number of ticks offset from bar")] [Category("Bar Numbers")] public int Offset { get { return offset; } set { offset = Math.Max(0, value); } } [Description("Every Nth bar")] [Gui.Design.DisplayNameAttribute("Every Nth bar")] [Category("Bar Numbers")] public int Divisor { get { return divisor; } set { divisor = Math.Max(1, value); } } [Description("Place first label on this bar")] [Gui.Design.DisplayNameAttribute("First label bar")] [Category("Bar Numbers")] public int Start { get { return start; } set { start = Math.Max(1, value); } } [Description("Increment every Nth bars")] [Gui.Design.DisplayNameAttribute("Increment every Nth bar")] [Category("Bar Numbers")] public int Increment { get { return increment; } set { increment = Math.Max(1, value); } } [XmlIgnore()] [Description("Color of the bar numbers.")] [Category("Bar Numbers")] [Gui.Design.DisplayNameAttribute("Color")] public Color TextColor { get { return textColor; } set { textColor = value; } } [Browsable(false)] public string TextColorSerialize { get { return NinjaTrader.Gui.Design.SerializableColor.ToString(textColor); } set { textColor = NinjaTrader.Gui.Design.SerializableColor.FromString(value); } } [Browsable(false)] public string MyFontSerialize { get { return NinjaTrader.Gui.Design.SerializableFont.ToString(textFont); } set { textFont = NinjaTrader.Gui.Design.SerializableFont.FromString(value); } } }
Comment