Skip to main content

nautilus_indicators/support/
mod.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Numerical building blocks shared by indicators: shifted rolling moments and
17//! regression sums, and input validation.
18
19mod moments;
20mod regression;
21
22pub(crate) use self::{moments::ShiftedMoments, regression::RollingOls};
23
24pub(crate) const SMA_RESEED_WINDOWS: usize = 16;
25/// The maximum period accepted by windowed indicators.
26pub const MAX_PERIOD: usize = 1 << 24;
27
28pub(crate) fn is_valid_hlc(high: f64, low: f64, close: f64) -> bool {
29    is_valid_high_low(high, low) && close.is_finite() && close >= low && close <= high
30}
31
32pub(crate) fn is_valid_high_low(high: f64, low: f64) -> bool {
33    high.is_finite() && low.is_finite() && high >= low
34}
35
36pub(crate) fn typical_price(high: f64, low: f64, close: f64) -> f64 {
37    (high + low + close) / 3.0
38}