Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need Help in Calculating Slope to Degrees

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

    Need Help in Calculating Slope to Degrees

    Hi,

    I found the following formula to calculate the slope of a line:


    public int CalcSlope(IDataSeries line)
    {
    double radToDegrees = 180/Math.PI;
    return (int)(radToDegrees*(Math.Atan((line[0]-(line[1]+line[2])/2) /1.5/TickSize))) ;
    }
    I want to enable the calculation of the slope in degrees given any number of bars, from 1 to n. I don't understand why the line is divided by 1.5.

    Would the following formula be valid? Say I want to calculate the slope for the last 3 bars:

    return (int)(radToDegrees*(Math.Atan((line[0]-(line[1]+line[2]+line[3])/3) /1.5/TickSize)))

    If not, what is the formula?

    Thanks.

    rpq

    #2
    rpg, you could also check into our Slope() method - http://www.ninjatrader-support.com/H...eV6/Slope.html

    This will give you a rise over run calculation between two points, you would then need to add logic for converting to degrees...

    The cited logic for converting to degress is valid, not sure why the 1.5 divisor is needed - best is to print / plot the result and then verify by hand / visuals.

    Comment


      #3
      It looks as if (line[1]+line[2])/2) is calculating the value of 'line' at a point 1/2 way between 2bars ago and 1bar ago ~ that is 1 1/2 bars ago from line[0]. Hence the use of 1.5 which is normalizing the slope to give a rise value for one bar.

      To get the angle in degrees for 3 bars, I think this will work, but not tested:-
      return (int)(radToDegrees*(Math.Atan((line[0]-line[3])/3/TickSize)));

      Comment


        #4
        Thanks MJT..... I'll try it out to see if it works. I tried with the Slope() function, but it doesn't seem to give correct results.

        Regards,

        RPQ

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        56 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        143 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        160 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        96 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        276 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X