Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Indicator that count the bar

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

    Indicator that count the bar

    Hi everybody,

    I'm looking for a simple indicator that can count the number of days that are up.
    May you help me with this ?

    Many thanks in advance,
    Chris.

    #2
    Hello Chris,

    Thank you for your post.

    Do you wish to count sequential days up or the number of days up over a set period?

    I look forward to your response.

    Comment


      #3
      Hi Patrick,
      Just the number of days up during a certain period.
      Thank you.

      Comment


        #4
        Hello Chris,

        Thank you for your note.

        This code will count the number of times the close is greater than the open for the day within the period:
        Code:
        		#region Variables
        		private int period = 15;
        		private int upCount = 0;
                #endregion
        
          
                protected override void Initialize()
                {
                    Add(PeriodType.Day, 1);
                }
        
        
                protected override void OnBarUpdate()
                {
        			if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired)
        				return;
        			
        			upCount = 0;
        			for(int i = period; i > 0; i--)
        			{
        				if(Closes[1][i] > Opens[1][i])
        					upCount++;
        			}
        			Print("Number of up Days: " + upCount);
        		}
        
                #region Properties
                [Description("Numbers of bars used for calculations")]
        		[GridCategory("Parameters")]
        		public int Period
        		{
        			get { return period; }
        			set { period = Math.Max(1, value); }
        		}
                #endregion
        Please let me know if you have any questions.

        Comment


          #5
          Thank you for your help Patrick.

          Last question :
          How can I use it on a chart to know how many days were up this year ?

          Thank you in advance.
          Last edited by Chris128; 11-21-2013, 02:06 PM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by ghoul, Today, 06:02 PM
          3 responses
          14 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          44 views
          0 likes
          Last Post jeronymite  
          Started by Barry Milan, Yesterday, 10:35 PM
          7 responses
          20 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by AttiM, 02-14-2024, 05:20 PM
          10 responses
          180 views
          0 likes
          Last Post jeronymite  
          Started by DanielSanMartin, Yesterday, 02:37 PM
          2 responses
          13 views
          0 likes
          Last Post DanielSanMartin  
          Working...
          X