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 cmoran13, Yesterday, 01:02 PM
        0 responses
        30 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        22 views
        0 likes
        Last Post PaulMohn  
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        160 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        95 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        148 views
        2 likes
        Last Post CaptainJack  
        Working...
        X