How to find the angle of the SMA

 

Hello

Assuming I have an smaHandle piping in SMA values to my smaVals[] array, I need to find the angle of the trend over a specified number of bars in a zoom-friendly manner.

I've seen 

OBJ_TRENDBYANGLE

but it looks like it's geared towards price.  Does anyone know if there is a more general tool for calculating this in mql5?  As is already known

ATan(vertical height / horizontal length) * 180 / PI()

would give me the angle of the trend, but as the horizontal length and vertical height are different units, I'm stuck.  I've read somewhere else on the forum that it's not possible as such, but an equivalent would do it. 

Documentation on MQL5: Timeseries and Indicators Access / Bars
Documentation on MQL5: Timeseries and Indicators Access / Bars
  • www.mql5.com
Timeseries and Indicators Access / Bars - Documentation on MQL5
 
strontiumDog:

Hello

Assuming I have an smaHandle piping in SMA values to my smaVals[] array, I need to find the angle of the trend over a specified number of bars in a zoom-friendly manner.

I've seen 

OBJ_TRENDBYANGLE

but it looks like it's geared towards price.  Does anyone know if there is a more general tool for calculating this in mql5?  As is already known

ATan(vertical height / horizontal length) * 180 / PI()

would give me the angle of the trend, but as the horizontal length and vertical height are different units, I'm stuck.  I've read somewhere else on the forum that it's not possible as such, but an equivalent would do it. 

Maybe this code can help you ?
 
strontiumDog:

Hello

Assuming I have an smaHandle piping in SMA values to my smaVals[] array, I need to find the angle of the trend over a specified number of bars in a zoom-friendly manner.

You can't . . .  angles only work when you have the same units for the two lines that make an angle,  use a gradient or slope instead. 
 
Maybe you could also try to use the linear regression of the SMA, just my suggestion.
Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Types
Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Types
  • www.mql5.com
Standard Constants, Enumerations and Structures / Objects Constants / Object Types - Documentation on MQL5