Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Parameter initialisation not consistent for indicator parameter

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Parameter initialisation not consistent for indicator parameter

    Hi,

    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:

    Code:
        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); }
            }
        }

    #2
    adamus,

    I guess I am not really clear on what you are trying to do. What is the significance of these even numbers? Could you possible post a screen shot of it working as expected, and not working as expected?

    I look forward to helping.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Hi there,
      it is very simple - sometimes the bar numbers are odd, sometimes they are even. I posted the code, thinking you might be able to see why - it's really simple, just the value of 'start' variable. I can't! I figured it should always be even.

      Comment


        #4
        Originally posted by adamus View Post
        Hi there,
        it is very simple - sometimes the bar numbers are odd, sometimes they are even. I posted the code, thinking you might be able to see why - it's really simple, just the value of 'start' variable. I can't! I figured it should always be even.
        Your code is drawing text based on the value of CurrentBar, but the text being written is based on the value of sessionBar. As sessionBar is initialized per session, independent of CurrentBar, the codependency is variable. Therefore, if CurrentBar is even, but sessionBar is odd, you will end up DrawText()ing the odd numbers.
        Last edited by koganam; 12-08-2011, 12:51 PM. Reason: Corrected spelling

        Comment


          #5
          adamus,

          Please see Koganam's post. You can check if something is even or odd using the modulus operator like follows :

          if(Num % 2 == 0)
          {
          // It's even
          }
          else
          {
          // It's odd
          }
          Adam P.NinjaTrader Customer Service

          Comment


            #6
            Excellent.

            I am guilty of not even looking properly at what it was doing.

            I just figured I'd take the existing code and modify it slightly with my parameter. Thanks for the solution.
            Last edited by adamus; 12-08-2011, 03:52 AM.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            576 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            334 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            553 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            551 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X