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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        635 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        365 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        106 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        567 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        571 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X