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

Linear regression bands

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

    Linear regression bands

    Is there already a standard indicator that is like Bollinger Bands, but based on using Linear Regression for the moving average and then applying standard deviation bands around it?

    (I know that if the answer is no, then I can pretty easily put one together myself.)

    --EV

    #2
    You could look into the sharing section here, I think the Standard Error Bands I created come close:

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      You could look into the sharing section here, I think the Standard Error Bands I created come close:

      http://www.ninjatrader.com/support/f...1&pp=15&page=2
      I'll take a look -- it does sound nice. I am puzzled by the reference to smoothing, though -- linear regression is pretty smooth to begin with, so I would not have thought any further smoothing was needed. I'll load it and take a look.

      --EV

      Comment


        #4
        Originally posted by NinjaTrader_Bertrand View Post
        You could look into the sharing section here, I think the Standard Error Bands I created come close:

        http://www.ninjatrader.com/support/f...1&pp=15&page=2
        I note that Tucker refers to standard error bands, as does this indicator (presumably because it is implementing Tucker's indicator). Bollinger Bands, on the other hand, use standard deviation.

        Is there some reason why standard error is better? Why not use standard deviation? (Yes, I know that for any given length, they are proportional. Just curious why use standard error, since the usual information on what percent of samples will be included is based on standard deviation.)

        --EV

        Comment


          #5
          You would need to test what's best for your scenario - some argue StdError reacting quicker thus better adaptation to volatility changes.
          BertrandNinjaTrader Customer Service

          Comment


            #6
            I just installed it, and I like it. One thing I have missed with the NT Bollinger Bands is the shading -- I am used to that from elsewhere, and find it helpful. I also use the double bands, so it is nice to not need two BB's to do that. Good job -- I like what you have done with this indicator. Very well done.

            --EV

            Comment


              #7
              Thanks for the kind words, appreciated.
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Now that I have had the StdErrorSmoothV2 indicator up for a few hours, I have a couple of observations:
                • I like it very much, including the way the background cosmetics are handled. The indicator was done very well.

                • I don't like the long lag that all the smoothing give it. (I believe that is a consequence of implementing Tucker's indicator.) For the chart I am looking at, I am using 42 days. The indicator lags 15 days at the bottom I am examining, while the LinReg(42) only lags 3 days! One should be able to smooth a LinReg quite a bit without introducing 12 more days of lag. (I know that Tucker hand-waves that you can live with the lag, but that's a lot of lag to live with.)

                • For some reason, perhaps the lag or perhaps the use of StdErr instead of StdDev, the relationship of the price to the bands is not at all like Bollinger Bands. With BB's, in sustained up or down trends the prices often ride the edge of the envelope, making it easy to see when there is a larger excursion. With this indicator, prices can get well away from the bands, precluding an unusual excursion being all that obvious.

                • The initialization needs work -- what gets plotted initially is so far off the stock's value that it forces a great deal of vertical compression -- I had to scroll that part out of view to get a reasonable look at anything else. Specifically, on the earliest day plotted by the indicator the stock closes at 134.97, while the lower band is 37.04. The shading itself continues on loser, down to ab out 30.

                --EV

                Comment


                  #9
                  Thanks for the kind words, you're free to play with it and modify as needed to help visualize your signals / market swings needed. The way it's presented here it's certainly different from regular Bollinger Bands, they are more breakout bands / finding trend resistance and support.

                  It's important to understand that some concepts need the lag to be useful, but of course if you prefer lower lag, set shorter smoothing lengths or integrate other formulas focused on reducing lag further.

                  You could set BarsRequired in the Initialize() to get a smoother init of the indicator display.

                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    I gather from the description that this would mean OnBarUpdate() would not get called until there were that many bars?

                    It sounds as if setting this is a viable alternative to what all of the tutorials do:

                    if (CurrentBar < Period) return;

                    Right?

                    --EV

                    Comment


                      #11
                      EV, no, the OnBarUpdate() is called, you still need to outlined check here...BarsRequired for indicators is only visual.
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        New tool for exploring moving averages

                        Bertrand,

                        Inspired by your program, I decided to write my own indicator to explore moving averages. As a newcomer, I am impressed with how well the framework works, and as a result how few bugs I actually coded. The code is pretty straightforward, which is a credit to the framework NT provides.

                        I finished my indicator this evening, and have given it a good first pass, but it is scarcely guaranteed to be production quality. No real color tuning. Could still be bugs, though it has been pretty smooth for me. No GUI review -- might be a way to do a couple of things a bit smoother. I have not put in support for configuring all of the parameters for the adaptive moving averages -- just hard coded the conventional recommended values (other than length)

                        My indicator is an extension of some others I have seen mentioned around here. It allows one to pretty thoroughly explore moving averages to see just how they work. I'll bet some will find it interesting, just as a learning tool. Some of the features:
                        • You can plot pretty much any moving average you want to. (No MAMA, because that is paired with FAMA and does not fit in well with what this indicator does.

                        • You can do the obvious things, such as set the length of the moving average

                        • You can choose what type of bands and how wide you want them. As with your indicator, there are inner and outer bands. Types of bands / envelopes are: constant width, percentage, stddev and stderror. (I was going to also do ATR bands, but I forgot -- perhaps I'll go back and add that. Might be interesting to compare with Keltner.)

                        • You can control the color and transparency of filling your band or bands

                        • You can do bull/bear coloring of your moving average line (I did not take it as far as allowing coloring the fill area, and I have no plan to do that). Bull/bear coloring is based on your choice of: slope of the indicator line, an EMA signal line (similar to MACD signal, but not plotted), or when the closing price is above/below the moving average.

                        • You can choose how much smoothing of the moving average to do: none, single, double, and triple EMA. You can control the number of bars used in the smoothing, so it is pretty flexible about letting you explore the effects of smoothing.

                        One thing I did that was educational was to add a Bollinger Band to my chart. Then I set my indicator to SMA, same length as the BB, 2 std dev bands -- and it mapped exactly onto the BB (as it should , but nice confirmation). Then I switched to StdError bands in mine. You could really see the difference between StdDev and StdError bands - for one thing, the idea of getting straight and narrow along trends really shows up..

                        That's about it. I think it is a pretty good tool to explore moving averages and related matters. I have attached a copy of the source to this message -- think of it as an alpha release. If you do get a chance to play with it, and you have any comments, I'd like to hear them. Being new to NT, it would not surprise me if I missed something.

                        If you or anyone else reading this likes it enough I'll look into packaging it up and putting it in the public area. I still want to think about a couple of the usability aspects, though. I should probably at least add support for the parameters for the various adaptive moving averages -- would not be hard, I'm just worried about cluttering the GUI with little-used items. (Too bad the user configuring is not more flexible, so you could bring items for those MAs into view only if the MA is selected.) Probably should also add ATR bands -- also pretty easy to do at this point.

                        --EV
                        Attached Files

                        Comment


                          #13
                          Thanks for sharing your work and enhancements here, I'm sure it will be received well...once you're done making changes and after some testing we would appreciate if you post it into the sharing for future reference.
                          BertrandNinjaTrader Customer Service

                          Comment


                            #14
                            OK -- I have tidied the indicator up a bit and attached the latest version. I guess the next thing is to figure out how to share it (beyond attaching it here).

                            Changes since my last posting:
                            • GUI tuning -- I prefer the plot to be a little subtle, so that's the way it is. Others may want stronger colors -- that's configurable, so go knock yourself out.
                            • Improved parameter setting organization.
                            • Some miscellaneous code cleanup
                            • Added one more bull/bear choice: bar completely above the MA is bullish
                            • Added one more band style: ATR -- SMA with 3 ATR envelope looks very much like Keltner bands (although not identical, as the Keltner calculation is a bit different than ATR)
                            • Allow different types for inner and outer bands. For example, it is illuminating to configure the inner band to be StdError and the outer band to be StdDev.

                            I have used this a fair amount now. It works well to explore moving averages and related items. It also allows things no other indicator does, such as any pairing kind of bands with any kind of moving average.

                            The configuration is more extensive than most indicators require. That is unavoidable, because it needs to be to control the flexibility this indicator offers. The best I can do it to make it as clear and intuitive as possible. I have revised the configuration a bit and think it is pretty understandable now.

                            If anyone sees anything obvious that I missed, please let me know. My intent is that choices be pretty comprehensive, so if I overlooked a band style, type of moving average, common bull/bear criterion, etc I'd like to know so I can add it.

                            --EV
                            Attached Files

                            Comment


                              #15
                              I placed it in a .zip and loaded it into NT. NT took the script, nothing shows up in my indicator list. Is it under a different name or is it Rwbma? Rwbma does not show up. Am I missing something here?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by zstheorist, Today, 07:52 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post zstheorist  
                              Started by pmachiraju, 11-01-2023, 04:46 AM
                              8 responses
                              149 views
                              0 likes
                              Last Post rehmans
                              by rehmans
                               
                              Started by mattbsea, Today, 05:44 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post mattbsea  
                              Started by RideMe, 04-07-2024, 04:54 PM
                              6 responses
                              33 views
                              0 likes
                              Last Post RideMe
                              by RideMe
                               
                              Started by tkaboris, Today, 05:13 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post tkaboris  
                              Working...
                              X