Calculating Trend line slope in degree.

 

Hi,


I am trying to figure out slope degree calculation ,is it possible to calculate correctly.

i am using following data

p1= 1.17657 p2= 1.17854 angle(as told in mt5 chart) = 55 or 56

d1=D'2017.12.15 01:11'                         d2=D'2017.12.15 12:31


i have tried inverse tan or MathArctan.


I am not getting expected results any idea plz.

Files:
mtu.png  5 kb
 
Farrukh Aleem:

Hi,


I am trying to figure out slope degree calculation ,is it possible to calculate correctly.

i am using following data

p1= 1.17657 p2= 1.17854 angle(as told in mt5 chart) = 55 or 56

d1=D'2017.12.15 01:11'                         d2=D'2017.12.15 12:31


i have tried inverse tan or MathArctan.


I am not getting expected results any idea plz.


You are not the first. Please see 

https://www.mql5.com/en/forum/157287#comment_3806158

 

no working example found did lot of searching mql specific.

 
Farrukh Aleem:

no working example found did lot of searching mql specific.


Well in short, you can not. Change your chart size and the slope will change. Not sure if you can solve your problem using another method. But slope or angle calculation based on chart is useless.

 
Enrique Dangeroux: Well in short, you can not. Change your chart size and the slope will change. Not sure if you can solve your problem using another method. But slope or angle calculation based on chart is useless.

Change your chart size/scale, the slope will not change, the apparent angle will.

If you insist, take the two price/time coordinates, convert them to pixel coordinates and then to apparent angle with arctan.
          How to get the angle of a trendline and place a text object to it? - Trend Indicators - MQL4 and MetaTrader 4 - MQL4 programming forum - Page 2

 

you can use:

point value * window * timeframe coefficient

point value is minimum price change for example for eurusd is .00001

window is number of candles that you want to get their slope

time frame coefficient is 1 for 1 minute timeframe and 2 for 2 minute timeframe and ....


this python function calculate slope for given data (eg:moving average)


import math

def slope(data, window,point_value=.00001,time_frame_coefficient=1): s = pd.Series(index=data.index) for i in range(window, len(data.index)): m = (data.iloc[i] - data.iloc[i-window])/(window*point_value*time_frame_coefficient) atan = math.atan(m) degree = math.degrees(atan) s.iloc[i] = degree return s

 

Thanks shayan,

I did a manual calculation to see if I got the sums right.
Hourly bars on gold starting from 2022.02.23 11:00 XAUUSD  pointvalue = .01  price low rounded to for convenience sake 1890.00 to price high 24 bars later 1974.00 (8400 point rise)  

(.01 * 24bars * 60minutes = 14.4)
(.01 *  9bars * 60minutes = 5.4 )
XAUUSD 8400 points up over 24 hourly bars = 8400*.01 = 84 / 14.4 = 5.8333  MathArcTan(5.8333)=80°
XAUUSD 8400 points down over  9 hourly bars = 8400*.01 = 84 / 5.4  = 15.555  MathArcTan(15.555)=86°

https://www.math.net/calculators/arctan

Where 45° is MathArcTan(1). A 1 results when variable = divisor

A  60 pip rise (600points) over 10 * 60 minute bars is 45°
A  30 pip rise (300points) over  5 * 60 minute bars is 45°
A  24 pip rise (240points) over  4 * 60 minute bars is 45°
A  18 pip rise (180points) over  3 * 60 minute bars is 45°
A  12 pip rise (120points) over  2 * 60 minute bars is 45°
A   6 pip rise ( 60points) over  1 * 60 minute bars is 45°

Arctan Calculator
  • www.math.net
Calculator to give out the arctan value of a number.
Reason: