Mathematical/probuilder · probacktest · proorder · proscreener

ACOS

ACOS in ProBuilder returns the arc cosine of a value, the angle in radians whose cosine equals the input. Input range, syntax, parameters and examples.

Syntax

probuilder
ACOS(value)

Parameters

NameTypeDescription
valuenumberA value between -1 and 1 inclusive. Inputs outside this range are invalid because no real angle has a cosine beyond those bounds.

Formula

code
ACOS(x) = angle in radians such that COS(angle) = x,   -1 <= x <= 1

The returned angle falls between 0 and PI radians (0 to 180 degrees). To convert the result to degrees, multiply by 180 / PI.

How it works

ACOS reverses the cosine relationship: given a ratio it returns the angle that produced it. Because cosine only ever ranges from -1 to 1, the input must stay inside that band. ACOS(1) returns 0, ACOS(0) returns roughly 1.5708 (PI/2), and ACOS(-1) returns PI.

The output is in radians, consistent with COS, SIN and TAN, which all expect radian input. If a downstream calculation works in degrees, apply the 180 / PI conversion after the call.

Examples

Example 1, Angle from a normalized ratio (Indicator)

probuilder
// Recover an angle in degrees from a cosine ratio
ratio = 0.5
angleRad = ACOS(ratio)
angleDeg = angleRad * 180 / 3.14159265
RETURN angleDeg AS "Angle (deg)"

ACOS(0.5) returns about 1.047 radians, which the conversion turns into 60 degrees.

Example 2, Guard the input range (ProScreener)

probuilder
// Only compute the angle where the ratio is a valid cosine
x = (close - Lowest[20](low)) / (Highest[20](high) - Lowest[20](low))
valid = x >= -1 AND x <= 1
angle = ACOS(MIN(1, MAX(-1, x)))
SCREENER[valid](angle AS "ACOS")

Clamping x with MIN and MAX keeps the input inside [-1, 1] so ACOS never sees an out-of-range value.

Example 3, Angle-based filter (ProOrder)

probuilder
// Convert a bounded oscillator reading into an angle and gate entries by it
osc = (close - Average[20](close)) / (2 * STD[20](close))
osc = MIN(1, MAX(-1, osc))
theta = ACOS(osc)
IF NOT LongOnMarket AND theta < 1 THEN
  BUY 1 CONTRACT AT MARKET
ENDIF

The clamp guarantees a legal input, and ACOS maps the bounded reading onto an angle used as a threshold.

Common errors and gotchas

  • Input must stay in [-1, 1]. An argument below -1 or above 1 is not a valid cosine and raises an error. Clamp with MIN(1, MAX(-1, x)) when the value can drift out of range.
  • Result is in radians. The output ranges from 0 to PI. Multiply by 180 / PI if you need degrees.
  • Inverse of COS, not 1 / COS. ACOS undoes cosine. It is not the reciprocal of COS.
  • ASIN, arc sine, the inverse of SIN.
  • ATAN, arc tangent, the inverse of TAN.
  • COS, cosine of an angle in radians, the function ACOS reverses.
  • SIN, sine of an angle in radians.
  • TAN, tangent of an angle in radians.
  • ABS, absolute value, useful when preparing inputs.
  • SQRT, square root, common alongside trigonometric ratios.