Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bull/Bear bodies

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

    Bull/Bear bodies

    Hi community,

    i like to get a percentage value of how many percent the BullBars (Close>Open) are bigger/smaller than the BearBars(Close<Open) in a given period. What would be a good way to implement this with Ninjascript?

    Thanks for reading.

    #2
    Originally posted by puravida View Post
    Hi community,

    i like to get a percentage value of how many percent the BullBars (Close>Open) are bigger/smaller than the BearBars(Close<Open) in a given period. What would be a good way to implement this with Ninjascript?

    Thanks for reading.
    Both kinds of candles are various sizes. Some of the bull bars are bigger than some of the bear bars, and some of the bull bars are smaller than some of the bear bars, so exactly how do you even determine what you want to count?

    Comment


      #3
      Hi koganam,

      thanks for helping me on this.

      To clarify what i mean:

      I like to have the SUM() of all bars in the given period, not a comparison between each of them. So for me it is enough to know the sum of the range (Open to Close) of every bull bar and vice versa for the bear bars and then calculate a ratio out of these two values. It should give an indication, if we have larger bull bars than bear bars in a given period to analyse buying/selling pressure.

      Comment


        #4
        I like to have the SUM() of all bars in the given period, not a comparison between each of them. So for me it is enough to know the sum of the range (Open to Close) of every bull bar and vice versa for the bear bars and then calculate a ratio out of these two values. It should give an indication, if we have larger bull bars than bear bars in a given period to analyse buying/selling pressure.
        Hi Puravida

        Just to try to be a bit of help:

        Firstly, you're looking for a ratio, R = (Total Up Bars)/(Total Down Bars), say. But if, over your range, there are no down bars - as can be the case - then R will be infinite or, as the math guys would say, that point is a 'singularity'.

        This, of course, must be avoided.

        One way to do this is to use the difference rather than the ratio.

        I've coded things similar to this and an approach I'd suggest would be to use a 'while loop'.

        Anyway, I've knocked up an indicator that seems to do the job and works well - I hope this helps you:


        Code:
        public class UpDownBarsDiff01 : Indicator
            {
                #region Variables
        
                    private int period = 20;
        
                #endregion
        
        
                protected override void Initialize()
                {
                    Add(new Plot(new Pen(Color.Blue, 6), PlotStyle.Line, "Plot0"));
                    Overlay                = false;
                }
        
        
                protected override void OnBarUpdate()
                {
        
                    
        double TotalUpBars = 0;
        double TotalDownBars = 0;
        int i = 0;
        int j = 0;
                    
                    if (CurrentBar < Period)
                        return;
        
        while (Close[i] > Open[i] && i < Period)
                    {
                        TotalUpBars = TotalUpBars + Close[i] - Open[i] ;   
                        i++;
                    }
                    
        while (Close[j] < Open[j] && j < Period)
                    {
                        TotalDownBars = TotalDownBars + Open[j] - Close[j] ;   
                        j++;
                    }
                    
        double r = TotalUpBars - TotalDownBars;
                    
                    Plot0.Set(r);
                }
        
                #region Properties
                [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                public DataSeries Plot0
                {
                    get { return Values[0]; }
                }
        
                [Description("")]
                [GridCategory("Parameters")]
                public int Period
                {
                    get { return period; }
                    set { period = Math.Max(1, value); }
                }
                #endregion

        Comment


          #5
          Hi again,

          Just to add that to avoid the singularity (infinity) with a ratio, you could of course use the following formula:
          Code:
          R = (TotalUpBars)/(TotalUpBars + TotalDownBars);
          With this, the denominator can never be zero.

          Comment


            #6
            Thanks, that did the trick for me.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            607 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            353 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            105 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            560 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            561 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X