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

Slope() value

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

    Slope() value

    I am using the function LinRegSlope() or similarly Slope(LinReg()). When I output the the values they are typically around -.05 to .05. I'm wondering what the highest and lowest these values could go. I'm also trying to relate these values to what I know as the slope of a line in geometry (typically 45 degree, 90 degree [straight up] etc.). I was thinking .45 would correspond to 45 degree line (slope) but that doesn't seem to be the case. Can somebody help me make sense of the values that Slope() outputs as they relate to high, low and the angle of a line. Much thanks.

    #2
    Ethan,

    Slope just outputs the value in units price per bar so to speak. It's simply something like :

    (Price[index2] - Price[index1] )/ (index2-index1)

    As such the bounds on what it can output is highly dependent on the underlying series that its being calculated for. If you convert this to degrees or radians you could theoretically get between -90 and 90 degrees (but not including -90 or 90).

    Slope actually can have some scaling issues if you don't normalize for volatility or something similar like ATR. Also the slope isn't based on the angles you see on your chart, i.e. if you rescale the chart by dragging the axes the slope doesn't change.

    You may want to consider doing something like :

    Arctan( (Price[0] - Price[1] ) / Timeframe )

    This would return the value in radians, then you can simply convert to degrees. It also takes into account the time between one bar and the next.

    I believe this would be similar :

    Arctan ( Slope(Close,index1,index2) / timeframe )

    Using some trigonometry :

    Tangent ( angle ) = (Price[index2] - Price[index1] ) / (index2 - index1)

    So taking the inverse function :

    angle = Arctangent ( (Price[index2] - Price[index1] ) / (index2 - index1) )

    Please note this is all pseudo-code / formulas. Math.ATan() is the method you can use for arctangent (inverse function for tangent) in C#.
    Last edited by NinjaTrader_AdamP; 11-07-2012, 02:26 PM.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Ethan,

      I have attached a screenshot I drew some things on that may help in understanding.
      Attached Files
      Adam P.NinjaTrader Customer Service

      Comment


        #4
        Thanks for your responses Adam. I am not a Trig expert (took it in High School a long time ago). I like your chart and I see your formula. I like the circle with the degrees/angle line--THAT IS WHAT I'M TRYING TO CALCULATE. Are you saying take P2-P1/T2-T1 and normalize that somehow. I agree with the basic formula but don't see how to normalize it. Can you provide the actual code that would normalize. You say all pseudo-code / formulas but Math.ATan() is what I would use. What is the actual code to accomplish this? Thanks.

        Comment


          #5
          Hello EthanHunt,
          Please refer to this post which demonstrates how to calculate the angle in degrees.
          JoydeepNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Shansen, 08-30-2019, 10:18 PM
          24 responses
          941 views
          0 likes
          Last Post spwizard  
          Started by Max238, Today, 01:28 AM
          0 responses
          9 views
          0 likes
          Last Post Max238
          by Max238
           
          Started by rocketman7, Today, 01:00 AM
          0 responses
          4 views
          0 likes
          Last Post rocketman7  
          Started by wzgy0920, 04-20-2024, 06:09 PM
          2 responses
          28 views
          0 likes
          Last Post wzgy0920  
          Started by wzgy0920, 02-22-2024, 01:11 AM
          5 responses
          33 views
          0 likes
          Last Post wzgy0920  
          Working...
          X