Sidechair

math.atan()

Browse the reference

Returns the arctangent of a number, an angle in radians whose tangent is that number.

Try it in the editor

math.atan is the inverse of math.tan. Every real number has an arctangent, which lands between -math.pi / 2 and math.pi / 2.

Because it squeezes any number into a bounded range, it is a convenient way to compress a slope: math.atan(slope) is a bounded angle.

Syntax

Pine Script
math.atan(angle: simple int/float) -> simple float
math.atan(angle: input int/float) -> input float
math.atan(angle: const int/float) -> const float
math.atan(angle: series int/float) -> series float

Arguments

NameTypeDefaultDescription
angleconst/input/simple/series int/floatrequiredAny number, the ratio of a rise to a run. The result is an angle in radians.

Returns

const/input/simple/series float: the angle in radians.

Remarks

  • To get the angle of a price slope in degrees, use math.todegrees(math.atan(slope)).

Example

Pine ScriptAngle of the average's slopeOpen in editor
//@version=6
indicator("Slope angle")
slope = (ta.sma(close, 20) - ta.sma(close, 20)[5]) / ta.atr(14) / 5
plot(math.todegrees(math.atan(slope)), "Angle", color = color.purple)
hline(0)

See also

Runs on Sidechair