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 Channel Slope

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

    Linear Regression Channel Slope

    I am trying to add a command into my strategy that identifies when the Linear Regression Channel goes flat or starts sloping in the opposite direction, but I cannot figure out how to make it happen.

    It seems that the Linear Regression Indicator and the Linear Regression Slope indicator are both based on how the endpoint of a regression line is changing, rather than what the slope of the whole regression line/channel is based solely on the current bar (not comparing it to the previous bar).

    Does this make sense?

    Obviously this information is in the program somewhere. I can have the strategy draw the regression channel on the chart and I can visually see the slope.

    Thanks in advance for the help!

    #2
    You can use the Slope() method to get the slope of any data series/indicator.

    RayNinjaTrader Customer Service

    Comment


      #3
      Thank you.

      I probably should have explicitly mentioned that I have tried using the Slope() function, but it does not seem to be giving me the result I need.

      I have modified the LinearRegressionSlope indicator from the File Sharing section to try and get it to display the Slope() of a RegressionChannel(). This is what the code looks like:

      LRSlope.Set(Slope(RegressionChannel(Period, 2), Period, 0));

      The attached file shows what readings it is giving to me. I put a RegressionChannel on the chart, and dropped it on the first bar that the RegressionChannel goes from sloping down to sloping up. The number of bars in length that this RegressionChannel ended up being was 41. I then applied the indicator with a length of 41, and it doesn't seem to show any kind of slope reversal at all.

      What am I missing?
      Attached Files

      Comment


        #4
        Sorry I misunderstood, unfortunately I don't have any more ideas to put forth.
        RayNinjaTrader Customer Service

        Comment


          #5
          I've just hit this brickwall as well.
          I can't find a way to measure the slope "the way the regression channel looks on screen".
          Slope() doesn't work. Rising() doesn't work.
          etc[1] > etc[2] doesn't work.

          Comment


            #6
            There was an extensive thread about slope. Try searching the forums for "slope".
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              NinjaTrader knows the value!

              Thanks Josh.

              I had seen the extensive "Slope()" thread before, and I did just go re-read it, but I don't see anything in there that applies to my particular problem.

              The issue is that when you draw a regression channel, the whole thing looks completely different from bar to bar. If you simply move a regression channel forward one bar, it displays different values for past bars. This is unlike a moving average, which once the value is calculated it continues to look and stay the same forever.

              Am I making any sense?

              I know that the value I am looking for is somewhere stored in NinjaTrader! It has to know what angle the lines of the regression channel are. It's plotting them on the chart. I simply need to know where NinjaTrader stores these values and how I can access them.

              Please, can someone help saltminer and I?

              Comment


                #8
                The plots of the the reg channel are custom drawn via the Plot() method of the indicator. You can snoop around the source code to get an idea of what is happening.
                RayNinjaTrader Customer Service

                Comment


                  #9
                  Success

                  Thanks for the tip!
                  I have created a version of the Regression Channel indicator which makes public the slopeSeries, which contains the slope data we are looking for.
                  To use it, simple ask for the value JRRegressionChannel( etc ).slopeSeries[0]
                  e.g.
                  double MySlope = JRRegressionChannel(Close,35,2).slopeSeries[0];

                  Cheers,
                  saltminer
                  Attached Files

                  Comment


                    #10
                    salt,

                    Also keep in mind that the slope you may calculate mathematically is going to be different compared to what you are seeing with your eye. The slope with your eye is scaled based on;

                    - the amount of data you have loaded on the chart.
                    - the amount of movement on the chart.

                    Think of this as the viewable angle slope, which I very different to what the calculation of (rise / run), or using y = mx + b will give you.

                    just some food for thought in your slope venture.
                    mrlogik
                    NinjaTrader Ecosystem Vendor - Purelogik Trading

                    Comment


                      #11
                      Originally posted by jvracing View Post
                      I probably should have explicitly mentioned that I have tried using the Slope() function, but it does not seem to be giving me the result I need.
                      Maybe this is because the built-in Slope() method doesn't actually return the slope. It returns the average momentum per bar in the lookback interval (basically (Close[0]-Close[N])/N). If you want the actual slope of a regression line, see the LinRegSlopeSFX indicator in the file sharing area.
                      -Alex

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by guillembm, Today, 11:25 AM
                      1 response
                      5 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by owensd, 04-21-2024, 11:34 PM
                      9 responses
                      34 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by trilliantrader, 04-10-2024, 09:33 PM
                      7 responses
                      25 views
                      0 likes
                      Last Post NinjaTrader_BrandonH  
                      Started by traderqz, Today, 12:06 AM
                      5 responses
                      11 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by Mongo, Today, 11:05 AM
                      2 responses
                      10 views
                      0 likes
                      Last Post Mongo
                      by Mongo
                       
                      Working...
                      X