calculate method
Pure computation function that produces an IndicatorResult from candles.
Implementation
@override
IndicatorResult calculate(List<Candle> candles) {
final n = candles.length;
final empty = List<double?>.filled(n, null);
if (n < 2) {
return _result(empty, empty, empty, empty, empty, empty, empty);
}
// Use the last-completed candle as the "previous session"
final prev = candles[n - 2];
final h = prev.high;
final l = prev.low;
final c = prev.close;
final p = (h + l + c) / 3.0;
final r1 = (2 * p) - l;
final r2 = p + (h - l);
final r3 = h + 2 * (p - l);
final s1 = (2 * p) - h;
final s2 = p - (h - l);
final s3 = l - 2 * (h - p);
// Flat lines across all candles
List<double?> flat(double v) => List<double?>.filled(n, v);
return _result(flat(p), flat(r1), flat(r2), flat(r3), flat(s1), flat(s2), flat(s3));
}