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

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 manueldecastro, Today, 10:26 AM
            2 responses
            11 views
            0 likes
            Last Post manueldecastro  
            Started by i2ogu3, Yesterday, 11:31 PM
            3 responses
            21 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by cmtjoancolmenero, 04-29-2024, 03:40 PM
            23 responses
            70 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by reynoldsn, Yesterday, 04:40 PM
            3 responses
            14 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by llanqui, Today, 12:51 PM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X