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

How to claculate 'Avergae Bar Height' or bar price range average?

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

    How to claculate 'Avergae Bar Height' or bar price range average?

    I want to find the average 'bar height' (as I am calling it) or price range of each bar, averaged.

    The High minus the low of the bars, for a series of bars.

    So if High-Low=Height...How can I find the average height of say...last 30 bars...efficiently. As a condition in the strategy builder?

    thank you!

    #2
    Hello HaveGunsWillTravel,

    Thanks for writing in.

    You could use the SMA indicator with the Median price as the Input in the Strategy Builder to accomplish this.

    For example, in the Conditions and Actions section, you could create a condition that checks if the current Close price is greater than SMA(Median,30)[0].

    To do so, you would click 'add' in the Conditions section of the Conditions and Actions screen, on the left side of the condition builder screen you would open the Price folder and choose the Close price. In the center drop-down menu choose greater. Then on the right side you would open the Indicators folder, select the SMA indicator, click the Input series field, set the Price Type drop-down menu to Median, click OK, and set the SMA Period field to 30. See the attached screenshots.

    Also, see this help guide page for more information: https://ninjatrader.com/support/help...lueComparisons

    Let us know if we may assist further.
    Attached Files
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      What I need though is the value in ‘height’ rather than price. For example I want to know if the average height of the last 30 bars is less than $2.00 in height…the SMA route would return the SMA price as the value right? I’m using it as sort of making sure volitility is low or consistent on a tick chart.

      Comment


        #4
        Hello HaveGunsWillTravel,

        Thanks for your note.

        It would not be possible to accomplish this using the Strategy Builder due to the limitations of the Strategy Builder.

        The Strategy Builder is limited in the math that is able to be used for calculations. Only offsets are able to be used for mathematical calculations in the Strategy Builder. The kind of complex math it would take to accomplish this would likely need to be done in an unlocked script and manually coded.

        If the Strategy Builder had better support for mathematical offsets on variables, this would be easier to do in the Strategy Builder. We have a pending feature request for this with the internal ticket ID SFT-2059 and I will add your vote to the feature request.

        Please reference this internal tracking number when contacting Platform Support if you ever have questions regarding this feature request.

        When a feature request is implemented, you'll find a description of the new feature in the release notes:Let us know if we may assist further.

        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          anyone coded this as an indicator for nt8 yet? thanks

          Comment


            #6
            Hello chris.nucleus,

            Thanks for your note.

            I am not aware of any pre-existing scripts currently available that accomplish this.

            That said, this thread will be open for other community members to share their insight.

            Let us know if we may further assist.
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              thanks Brandon

              Comment


                #8
                Originally posted by chris.nucleus View Post
                anyone coded this as an indicator for nt8 yet? thanks
                I have been working on this, so far it works for low period (1~10)...BUT for whatever reason, on higher periods it does not. It shows no plot and the scale goes to lower decimal values. Here is the code, perhaps some one can help us refine it to work for periods up to 50, 100 or whatever.... Inidcator zip and code below. Thanks for the help all.


                protected override void OnBarUpdate()
                {
                //LOGIC BY "Z"
                //Loop: X bars back for averaging height
                //declare
                int i = 0;
                double height =0.0;
                double cheight = 0.0;
                //loop calc
                do
                {
                height = ((High[(i)])-(Low[(i)]));
                cheight = cheight + height;
                i = i + 1;
                }
                while (i < (BarsBack-1));
                //Plot
                Value[0] = cheight / BarsBack;
                }

                Attached Files
                Last edited by HaveGunsWillTravel; 01-24-2022, 06:27 PM.

                Comment


                  #9
                  Originally posted by chris.nucleus View Post
                  thanks Brandon
                  I got it! Just needed to return unitl enough bars were pulled in...Works good.
                  Attached Files

                  Comment


                    #10
                    Originally posted by HaveGunsWillTravel View Post

                    I got it! Just needed to return unitl enough bars were pulled in...Works good.
                    Awesome thanks!

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by fx.practic, 10-15-2013, 12:53 AM
                    5 responses
                    5,403 views
                    0 likes
                    Last Post Bidder
                    by Bidder
                     
                    Started by Shai Samuel, 07-02-2022, 02:46 PM
                    4 responses
                    95 views
                    0 likes
                    Last Post Bidder
                    by Bidder
                     
                    Started by DJ888, Yesterday, 10:57 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post DJ888
                    by DJ888
                     
                    Started by MacDad, 02-25-2024, 11:48 PM
                    7 responses
                    159 views
                    0 likes
                    Last Post loganjarosz123  
                    Started by Belfortbucks, Yesterday, 09:29 PM
                    0 responses
                    8 views
                    0 likes
                    Last Post Belfortbucks  
                    Working...
                    X