Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          579 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
          554 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