Skip to main content

pivot_points

Function pivot_points 

Source
pub fn pivot_points(
    highs: &[f64],
    lows: &[f64],
    closes: &[f64],
) -> Result<Vec<Option<PivotPoints>>>
Expand description

Calculate classic (standard) pivot points.

Each bar’s levels are derived from the previous bar’s high/low/close; the first bar has no prior bar and is therefore None.

§Formula

  • Pivot = (High + Low + Close) / 3
  • R1 = 2×Pivot − Low, S1 = 2×Pivot − High
  • R2 = Pivot + (High − Low), S2 = Pivot − (High − Low)
  • R3 = High + 2×(Pivot − Low), S3 = Low − 2×(High − Pivot)

§Example

use finance_query::indicators::pivot_points;

let highs = vec![10.0, 12.0, 11.0];
let lows = vec![8.0, 9.0, 8.5];
let closes = vec![9.0, 11.0, 10.0];
let result = pivot_points(&highs, &lows, &closes).unwrap();

assert!(result[0].is_none());
assert!(result[1].is_some());