tzutrader
A composable C++ backtesting library for trading strategies (experimental)
Loading...
Searching...
No Matches
tzu::SMA Class Reference

Simple Moving Average (SMA). More...

#include <indicators.h>

Inheritance diagram for tzu::SMA:
tzu::Indicator< SMA, double, double >

Public Member Functions

 SMA (size_t window_size)
double get () const noexcept
double update (double value)
Public Member Functions inherited from tzu::Indicator< SMA, double, double >
double get () const noexcept
double update (double value)

Detailed Description

Simple Moving Average (SMA).

Maintains a fixed-size window of the most recent values and calculates the average. Returns NaN until enough values have been added to fill the window. Once the window is full, it updates the average efficiently by keeping a running sum and subtracting the value that falls out of the window.

Usage
SMA sma(20); // 20-period moving average
double result = sma.update(price);
SMA(size_t window_size)
Definition indicators.h:66

Constructor & Destructor Documentation

◆ SMA()

tzu::SMA::SMA ( size_t window_size)
inline

Member Function Documentation

◆ get()

double tzu::SMA::get ( ) const
inlinenoexcept

◆ update()

double tzu::SMA::update ( double value)
inline

The documentation for this class was generated from the following file: