### Install talipp via PyPI Source: https://nardew.github.io/talipp/latest/getting-started?q= Standard installation command using pip. ```bash pip install talipp ``` -------------------------------- ### OHLCVFactory.from_matrix examples Source: https://nardew.github.io/talipp/latest/reference/talipp/ohlcv Examples showing input lists of various dimensions and corresponding OHLCV objects. ```python [[1,2,3,4,5], [6,7,8,9,0]] -> [OHLCV(1,2,3,4,5), OHLCV(6,7,8,9,0)] [[1,2,3,4], [6,7,8,9]] -> [OHLCV(1,2,3,4), OHLCV(6,7,8,9)] [[1,2,3,4,5,6], [7,8,9,10,11,12]] -> [OHLCV(1,2,3,4,5,6), OHLCV(7,8,9,10,11,12)] ``` -------------------------------- ### Install talipp via GitHub Source: https://nardew.github.io/talipp/latest/getting-started?q= Installation command to pull directly from the main branch on GitHub. ```bash pip install git+https://github.com/nardew/talipp.git@main ``` -------------------------------- ### Install talipp via Conda Source: https://nardew.github.io/talipp/latest/getting-started?q= Installation command using the conda-forge channel. ```bash conda install conda-forge::talipp ``` -------------------------------- ### Timeframe sampling examples Source: https://nardew.github.io/talipp/latest/reference/talipp/input?q= Examples demonstrating how different sampling periods and timestamps result in same or different timeframes. ```text Sampling: 1 sec Timestamp 1: 00:00:01.000000 Timestamp 2: 00:00:01.700000 Result: same timeframe Sampling: 5 sec Timestamp 1: 00:00:01.000000 Timestamp 2: 00:00:04.000000 Result: same timeframe Sampling: 5 sec Timestamp 1: 00:00:04.000000 Timestamp 2: 00:00:06.000000 Result: different timeframe ``` -------------------------------- ### composite_to_lists example output Source: https://nardew.github.io/talipp/latest/reference/talipp/indicator_util?q= Example showing the transformation of Bollinger Bands output values into a dictionary of lists. ```python [BBVal(lb=x1, cb=y1, ub=z1), BBVal(lb=x2, cb=y2, ub=z2), ...] ``` ```python {'lb': [x1, x2, ...], 'cb': [y1, y2, ...], 'ub': [z1, z2, ...]} ``` -------------------------------- ### has_valid_values examples Source: https://nardew.github.io/talipp/latest/reference/talipp/indicator_util?q= Examples demonstrating how different sequence, window, and exact parameters affect the validation result. ```python sequence=[1, 2], window=2, exact=True/False => return True sequence=[1, 2], window=1, exact=False => return True sequence=[1, 2], window=1, exact=True => return False sequence=[None, 2], window=1, exact=True => return True sequence=[None, 2], window=2, exact=True/False => return False ``` -------------------------------- ### from_matrix2 conversion examples Source: https://nardew.github.io/talipp/latest/reference/talipp/ohlcv Shows input matrix transformations into OHLCV object lists. ```text [[1,2], [3,4], [5,6], [7,8]] -> [OHLCV(1,3,5,7), OHLCV(2,4,6,8)] [[1,2], [3,4], [5,6], [7,8], [9,0]] -> [OHLCV(1,3,5,7,9), OHLCV(2,4,6,8,0)] [[1,2], [3,4], [5,6], [7,8], [9,0], [11, 12]] -> [OHLCV(1,3,5,7,9,11), OHLCV(2,4,6,8,0,12)] ``` -------------------------------- ### OHLCVFactory.from_matrix2 example and output Source: https://nardew.github.io/talipp/latest/input-types Similar to from_matrix, this method accepts a list of lists where the first list contains all 'open' values, the second contains all 'high' values, the third contains all 'low' values, and the fourth contains all 'close' values. The example shows the input as a 4x3 matrix and its output as a list of OHLCV objects. ```python from talipp.ohlcv import OHLCVFactory user_input = [ [ 1, 2, 3], [ 4, 5, 6], [ 7, 8, 9], [10, 11, 12] ] print(OHLCVFactory.from_matrix2(user_input)) ``` ```python [OHLCV(1, 4, 7, 10), OHLCV(2, 5, 8, 11), OHLCV(3, 6, 9, 12)] ``` -------------------------------- ### Import EMA indicator Source: https://nardew.github.io/talipp/latest/getting-started?q= Specific example showing how to import the EMA indicator. ```python from talipp.indicators import EMA ``` -------------------------------- ### OHLCVFactory.from_dict example and output Source: https://nardew.github.io/talipp/latest/input-types This example shows how to convert a dictionary with 'open', 'high', 'low', and 'close' list keys into a list of OHLCV objects using the from_dict static method. The output generates an OHLCV object for each index position. ```python from talipp.ohlcv import OHLCVFactory user_input = { 'open': [1, 2, 3], 'high': [4, 5, 6], 'low': [7, 8, 9], 'close': [10, 11, 12] } print(OHLCVFactory.from_dict(user_input)) ``` ```python [OHLCV(1, 4, 7, 10), OHLCV(2, 5, 8, 11), OHLCV(3, 6, 9, 12)] ``` -------------------------------- ### OHLCVFactory.from_matrix example and output Source: https://nardew.github.io/talipp/latest/input-types This method converts a list of tuples, where each tuple represents open, high, low, and close values, into a list of OHLCV objects. The example shows a three-row input matrix and its generated output. ```python from talipp.ohlcv import OHLCVFactory user_input = [ (1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12) ] print(OHLCVFactory.from_matrix(user_input)) ``` ```python [OHLCV(1, 2, 3, 4), OHLCV(5, 6, 7, 8), OHLCV(9, 10, 11, 12)] ``` -------------------------------- ### Sampler timeframe examples Source: https://nardew.github.io/talipp/latest/reference/talipp/input Examples illustrating how Sampler determines if two timestamps belong to the same timeframe based on the sampling period. ```text Sampling: 1 sec Timestamp 1: 00:00:01.000000 Timestamp 2: 00:00:01.700000 Result: same timeframe Sampling: 5 sec Timestamp 1: 00:00:01.000000 Timestamp 2: 00:00:04.000000 Result: same timeframe Sampling: 5 sec Timestamp 1: 00:00:04.000000 Timestamp 2: 00:00:06.000000 Result: different timeframe ``` -------------------------------- ### ADX Source Code Initialization Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/ADX The internal implementation of the ADX indicator's __init__ method, showing the setup of sub-indicators and managed sequences. ```python def __init__(self, di_period: int, adx_period: int, input_values: List[OHLCV] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, input_sampling: SamplingPeriodType = None): super().__init__(input_modifier=input_modifier, output_value_type=ADXVal, input_sampling=input_sampling) self.di_period = di_period self.adx_period = adx_period self.atr = ATR(di_period) self.add_sub_indicator(self.atr) # plus directional movement self.pdm = [] # minus directional movement self.mdm = [] self.add_managed_sequence(self.pdm) self.add_managed_sequence(self.mdm) # smoothed plus directional movement self.spdm = [] # smoothed minus directional movement self.smdm = [] self.add_managed_sequence(self.spdm) self.add_managed_sequence(self.smdm) # plus directional index self.pdi = [] # minus directional index self.mdi = [] self.add_managed_sequence(self.pdi) self.add_managed_sequence(self.mdi) # directional index self.dx = [] self.add_managed_sequence(self.dx) self.initialize(input_values, input_indicator) ``` -------------------------------- ### Example usage of indicators consuming float and OHLCV input Source: https://nardew.github.io/talipp/latest/input-types This example demonstrates that the SMA indicator consumes a list of floats, while the Stoch indicator requires a list of OHLCV objects. The OHLCV objects are created with open, high, low, and close price arguments. ```python from talipp.indicators import SMA, Stoch from talipp.ohlcv import OHLCV sma = SMA(period=3, input_values=[1, 2, 3]) stoch = Stoch(period=3, smoothing_period=2, input_values=[OHLCV(1, 2, 3, 4), OHLCV(5, 6, 7, 8)]) ``` -------------------------------- ### Enable auto-sampling with OBV indicator Source: https://nardew.github.io/talipp/latest/timeframe-sampling?q= Shows how to initialize an OBV indicator with 15-second auto-sampling and add OHLCV inputs. Demonstrates that inputs within the same timeframe update the last value, while inputs in a new period add a new value. ```python from datetime import datetime from talipp.indicators import OBV from talipp.input import SamplingPeriodType from talipp.ohlcv import OHLCV # choose auto-sampling by 15 seconds obv = OBV(input_sampling=SamplingPeriodType.SEC_15) dt = datetime(2024, 1, 1, 0, 0, 0) ohlcv = OHLCV(1, 1, 1, 1, 1, dt) # time 00:00:00 obv.add(ohlcv) print(len(obv)) # 1 # time 00:00:13 ohlcv.time = dt.replace(second=13) obv.add(ohlcv) # still within the same timeframe => no new value added, the last one updated print(len(obv)) # 1 # time 00:00:17 ohlcv.time = dt.replace(second=17) obv.add(ohlcv) # next period entered => new value added print(len(obv)) # 2 # time 00:00:25 ohlcv.time = dt.replace(second=25) obv.add(ohlcv) # still within the same timeframe => no new value added, the last one updated print(len(obv)) # 2 ``` -------------------------------- ### Sampling period validity examples Source: https://nardew.github.io/talipp/latest/reference/talipp/input Examples showing which sampling spans are allowed. Only spans that divide the full unit's period without remainder are valid. ```text 3 seconds => OK (60 % 3 = 0) 5 seconds => OK (60 % 5 = 0) 8 seconds => NOT OK (60 % 8 != 0) 4 hours => OK (24 % 4 = 0) 5 hours => NOT OK (24 % 5 != 0) ``` -------------------------------- ### OHLCVFactory.from_matrix signature and examples Source: https://nardew.github.io/talipp/latest/reference/talipp/ohlcv?q= Signature of the from_matrix method, which converts lists/tuples representing OHLCV values into a list of OHLCV objects. The expected input dimension is 4, 5, or 6 elements per row. Examples show different dimensions and corresponding outputs. ```python from_matrix(values: List[List[float]]) -> List[OHLCV] ``` ```python [[1,2,3,4,5], [6,7,8,9,0]] -> [OHLCV(1,2,3,4,5), OHLCV(6,7,8,9,0)] ``` ```python [[1,2,3,4], [6,7,8,9]] -> [OHLCV(1,2,3,4), OHLCV(6,7,8,9)] ``` ```python [[1,2,3,4,5,6], [7,8,9,10,11,12]] -> [OHLCV(1,2,3,4,5,6), OHLCV(7,8,9,10,11,12)] ``` -------------------------------- ### OBV Constructor Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/OBV Initializes an OBV (On Balance Volume) indicator instance. It accepts either a list of OHLCV values or an input indicator, along with optional input modifier and sampling settings. ```APIDOC ## OBV Constructor ### Description Initializes an OBV (On Balance Volume) indicator instance. It accepts either a list of OHLCV values or an input indicator, along with optional input modifier and sampling settings. ### Method Constructor ### Signature OBV(input_values: List[OHLCV] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, input_sampling: SamplingPeriodType = None) ### Parameters - **input_values** (List[OHLCV]) - Optional - List of input values. - **input_indicator** (Indicator) - Optional - Input indicator. - **input_modifier** (InputModifierType) - Optional - Input modifier. - **input_sampling** (SamplingPeriodType) - Optional - Input sampling type. ### Input Type OHLCV ### Output Type float ### Source Code ```python def __init__(self, input_values: List[OHLCV] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, input_sampling: SamplingPeriodType = None): super().__init__(input_modifier=input_modifier, input_sampling=input_sampling) self.initialize(input_values, input_indicator) ``` ``` -------------------------------- ### BB __init__ source code Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/BB Source code of the BB class __init__ method from talipp/indicators/BB.py. It initializes the indicator with the given parameters, creates a central band using MAFactory and a StdDev sub-indicator, and adds them as sub-indicators. ```python def __init__(self, period: int, std_dev_mult: float, input_values: List[float] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, ma_type: MAType = MAType.SMA, input_sampling: SamplingPeriodType = None): super().__init__(input_modifier=input_modifier, output_value_type=BBVal, input_sampling=input_sampling) self.period = period self.std_dev_mult = std_dev_mult self.central_band = MAFactory.get_ma(ma_type, period) self.std_dev = StdDev(self.period) self.add_sub_indicator(self.central_band) self.add_sub_indicator(self.std_dev) self.initialize(input_values, input_indicator) ``` -------------------------------- ### VTX __init__ source code Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/VTX?q= Source code for the VTX __init__ method from talipp/indicators/VTX.py. It initializes the indicator, sets the period, creates managed sequences for plus_vm and minus_vm, adds an ATR(1) sub-indicator, and initializes with provided inputs. ```python def __init__(self, period: int, input_values: List[OHLCV] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, input_sampling: SamplingPeriodType = None): super().__init__(input_modifier=input_modifier, output_value_type=VTXVal, input_sampling=input_sampling) self.period = period self.plus_vm = [] self.add_managed_sequence(self.plus_vm) self.minus_vm = [] self.add_managed_sequence(self.minus_vm) self.atr = ATR(1) self.add_sub_indicator(self.atr) self.initialize(input_values, input_indicator) ``` -------------------------------- ### Sampler.__init__ Source: https://nardew.github.io/talipp/latest/reference/talipp/input Constructor for the Sampler class. Initializes the sampler with a specified sampling period type. ```APIDOC ## Sampler.__init__ ### Description Constructor for the Sampler class. Initializes the sampler with a specified sampling period type. ### Method Constructor ### Signature ```python Sampler(period_type: SamplingPeriodType) ``` ### Parameters - **period_type** (SamplingPeriodType) - Required - The sampling period. ### Source Code ```python def __init__(self, period_type: SamplingPeriodType): self._period_type: SamplingPeriodType = period_type ``` ``` -------------------------------- ### Stochastic Oscillator complex output Source: https://nardew.github.io/talipp/latest/output-types?q= Example of a list of StochVal objects containing k and d attributes. ```python [StochVal(k=10, d=None), StochVal(k=20.0, d=15), StochVal(k=12, d=14)] ``` -------------------------------- ### Bollinger Bands output format Source: https://nardew.github.io/talipp/latest/output-types?q= Example of the list of BBVal objects returned when printing Bollinger Bands. ```python [BBVal(...), BBVal(...), BBVal(...), ...] ``` -------------------------------- ### UO __init__ source code Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/UO Source code of the UO indicator's __init__ method from talipp/indicators/UO.py. It initializes the indicator with the given periods, sets up managed sequences for buy pressure and true range, and calls initialize. ```python def __init__(self, fast_period: int, mid_period: int, slow_period: int, input_values: List[OHLCV] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, input_sampling: SamplingPeriodType = None): super().__init__(input_modifier=input_modifier, input_sampling=input_sampling) self.fast_period = fast_period self.mid_period = mid_period self.slow_period = slow_period self.buy_press = [] self.true_range = [] self.add_managed_sequence(self.buy_press) self.add_managed_sequence(self.true_range) self.initialize(input_values, input_indicator) ``` -------------------------------- ### Sampling period divisibility rules Source: https://nardew.github.io/talipp/latest/reference/talipp/input?q= Examples of valid and invalid sampling period spans based on unit divisibility. ```text 3 seconds => OK (60 % 3 = 0) 5 seconds => OK (60 % 5 = 0) 8 seconds => NOT OK (60 % 8 != 0) 4 hours => OK (24 % 4 = 0) 5 hours => NOT OK (24 % 5 != 0) ``` -------------------------------- ### KVO __init__ implementation Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/KVO Source code for the KVO __init__ method. It creates fast and slow moving averages using MAFactory, adds managed sequences for trend and cumulative measurement, and initializes with input values or indicator. ```python def __init__(self, fast_period: int, slow_period: int, input_values: List[OHLCV] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, ma_type: MAType = MAType.EMA, input_sampling: SamplingPeriodType = None): super().__init__(input_modifier=input_modifier, input_sampling=input_sampling) self.fast_ma = MAFactory.get_ma(ma_type, fast_period) self.add_managed_sequence(self.fast_ma) self.slow_ma = MAFactory.get_ma(ma_type, slow_period) self.add_managed_sequence(self.slow_ma) self.trend = [] self.add_managed_sequence(self.trend) self.cumulative_measurement = [] self.add_managed_sequence(self.cumulative_measurement) self.initialize(input_values, input_indicator) ``` -------------------------------- ### OHLCVFactory.from_dict example Source: https://nardew.github.io/talipp/latest/reference/talipp/ohlcv Shows the expected conversion behavior: input dict maps to OHLCV objects with None for missing keys. ```python {'open': [1,2], 'close': [3,4]} -> [OHLCV(1, None, None, 3, None, None), OHLCV(2, None, None, 4, None, None)] ``` -------------------------------- ### BB Source Code Initialization Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/BB?q= The internal implementation of the BB indicator's __init__ method, showing how sub-indicators like the central band and standard deviation are initialized. ```python def __init__(self, period: int, std_dev_mult: float, input_values: List[float] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, ma_type: MAType = MAType.SMA, input_sampling: SamplingPeriodType = None): super().__init__(input_modifier=input_modifier, output_value_type=BBVal, input_sampling=input_sampling) self.period = period self.std_dev_mult = std_dev_mult self.central_band = MAFactory.get_ma(ma_type, period) self.std_dev = StdDev(self.period) self.add_sub_indicator(self.central_band) self.add_sub_indicator(self.std_dev) self.initialize(input_values, input_indicator) ``` -------------------------------- ### Initialize indicator with input values Source: https://nardew.github.io/talipp/latest/getting-started?q= Feeding input values directly during the initialization of an indicator. ```python from talipp.indicators import EMA ema = EMA(period=3, input_values=[1, 2, 3, 4, 5]) ``` -------------------------------- ### PivotsHL source code __init__ Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/PivotsHL Implementation of the PivotsHL __init__ method from the source file in talipp/indicators/PivotsHL.py. ```python def __init__(self, high_period: int, low_period: int, input_values: List[OHLCV] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, input_sampling: SamplingPeriodType = None): super().__init__(input_modifier=input_modifier, output_value_type=PivotsHLVal, input_sampling=input_sampling) self.high_period = high_period self.low_period = low_period self.initialize(input_values, input_indicator) ``` -------------------------------- ### OHLCVFactory.from_dict signature and example Source: https://nardew.github.io/talipp/latest/reference/talipp/ohlcv?q= Signature of the static method from_dict, which converts a dict with OHLCV values into a list of OHLCV objects. Missing keys in the dict result in None values for corresponding OHLCV fields. ```python from_dict(values: Dict[str, List[float]]) -> List[OHLCV] ``` ```python {'open': [1,2], 'close': [3,4]} -> [OHLCV(1, None, None, 3, None, None), OHLCV(2, None, None, 4, None, None)] ``` -------------------------------- ### UO Implementation in talipp/indicators/UO.py Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/UO?q= The source code implementation of the UO indicator's __init__ method, showing how periods are initialized and managed sequences are added. ```python def __init__(self, fast_period: int, mid_period: int, slow_period: int, input_values: List[OHLCV] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, input_sampling: SamplingPeriodType = None): super().__init__(input_modifier=input_modifier, input_sampling=input_sampling) self.fast_period = fast_period self.mid_period = mid_period self.slow_period = slow_period self.buy_press = [] self.true_range = [] self.add_managed_sequence(self.buy_press) self.add_managed_sequence(self.true_range) self.initialize(input_values, input_indicator) ``` -------------------------------- ### Remove all values with SMA Source: https://nardew.github.io/talipp/latest/indicator-operations Shows the remove_all method to clear all input values. The example creates an SMA with period 3 and input values [1,2,3], removes all input values, and prints the result, which is an empty list. ```python from talipp.indicators import SMA sma = SMA(period=3, input_values=[1,2,3]) # remove all input values sma.remove_all() # outputs [] print(sma) ``` -------------------------------- ### Add values to SMA indicator Source: https://nardew.github.io/talipp/latest/indicator-operations Demonstrates the add method to incrementally add a single value or a list of values to an SMA indicator. The example creates an SMA with period 3 and input values [1,2,3], then adds 4 and then [4,5,6]. ```python from talipp.indicators import SMA sma = SMA(period=3, input_values=[1,2,3]) # add a single value sma.add(4) # add a list of values sma.add([4, 5, 6]) ``` -------------------------------- ### Read indicator values with SMA Source: https://nardew.github.io/talipp/latest/indicator-operations Shows how to read indicator values using the Sequence interface. The example creates an SMA with period 3 and input values [1,2,3], then prints all values, the last value, and the length. Outputs are [None, None, 2], 2, and 3 respectively. ```python from talipp.indicators import SMA sma = SMA(period=3, input_values=[1,2,3]) # print all values # outputs [None, None, 2] print(sma) # print last value # outputs 2 print(sma[-1]) # print number of values # outputs 3 print(len(sma)) ``` -------------------------------- ### from_matrix2 implementation Source: https://nardew.github.io/talipp/latest/reference/talipp/ohlcv Source code for the from_matrix2 static method in talipp/ohlcv.py. ```python @staticmethod def from_matrix2(values: List[List[float]]) -> List[OHLCV]: """Converts lists representing O, H, L, C, V and T values into a list of `OHLCV` objects. Examples: [[1,2], [3,4], [5,6], [7,8]] -> [OHLCV(1,3,5,7), OHLCV(2,4,6,8)] [[1,2], [3,4], [5,6], [7,8], [9,0]] -> [OHLCV(1,3,5,7,9), OHLCV(2,4,6,8,0)] [[1,2], [3,4], [5,6], [7,8], [9,0], [11, 12]] -> [OHLCV(1,3,5,7,9,11), OHLCV(2,4,6,8,0,12)] Args: values: A list of values to be converted into `OHLCV` objects. Returns: A list of `OHLCV` objects. """ if len(values) == 4: return OHLCVFactory.from_matrix(list(map(list, zip_longest(values[0], values[1], values[2], values[3])))) elif len(values) == 5: return OHLCVFactory.from_matrix(list(map(list, zip_longest(values[0], values[1], values[2], values[3], values[4])))) else: return OHLCVFactory.from_matrix(list(map(list, zip_longest(values[0], values[1], values[2], values[3], values[4], values[5])))) ``` -------------------------------- ### VTX __init__ source code Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/VTX Implementation of the VTX constructor. Sets the period, initializes internal sequences plus_vm and minus_vm, and adds an ATR(1) sub-indicator. Also registers the VTXVal output type. ```python def __init__(self, period: int, input_values: List[OHLCV] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, input_sampling: SamplingPeriodType = None): super().__init__(input_modifier=input_modifier, output_value_type=VTXVal, input_sampling=input_sampling) self.period = period self.plus_vm = [] self.add_managed_sequence(self.plus_vm) self.minus_vm = [] self.add_managed_sequence(self.minus_vm) self.atr = ATR(1) self.add_sub_indicator(self.atr) self.initialize(input_values, input_indicator) ``` -------------------------------- ### Remove most recent value with SMA Source: https://nardew.github.io/talipp/latest/indicator-operations Demonstrates the remove method to delete the most recent input value. The example creates an SMA with period 3 and input values [1,2,3], prints the values, removes the last input value, and prints again. Outputs change from [None, None, 2] to [None, None]. ```python from talipp.indicators import SMA sma = SMA(period=3, input_values=[1,2,3]) # outputs [None, None, 2] print(sma) # remove the last input value sma.remove() # outputs [None, None] print(sma) ``` -------------------------------- ### Update most recent value with SMA Source: https://nardew.github.io/talipp/latest/indicator-operations Shows the update method to replace the most recent input value. The example creates an SMA with period 3 and input values [1,2,3], then updates the last input value to 4. Note that update does not change the number of values; it removes the last input value and appends a new one. ```python from talipp.indicators import SMA sma = SMA(period=3, input_values=[1,2,3]) # update the last input value sma.update(4) ``` -------------------------------- ### Purge oldest values with SMA Source: https://nardew.github.io/talipp/latest/indicator-operations Demonstrates the purge_oldest method to remove the oldest values. The example creates an SMA with period 3 and input values [1,2,3], prints the values, purges the first value, and prints again. Outputs change from [None, None, 2] to [None, 2]. Purging is useful for memory management but be careful not to purge data still needed for calculations. ```python from talipp.indicators import SMA sma = SMA(period=3, input_values=[1,2,3]) # outputs [None, None, 2] print(sma) # purge the first value sma.purge_oldest(1) # outputs [None, 2] print(sma) ``` -------------------------------- ### SFX __init__ Source Code Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/SFX Source code for the SFX __init__ method. It initializes the ATR, StdDev, and moving average sub-indicators, and adds them as sub-indicators. ```python def __init__(self, atr_period: int, std_dev_period: int, std_dev_smoothing_period: int, input_values: List[OHLCV] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, ma_type: MAType = MAType.SMA, input_sampling: SamplingPeriodType = None): super().__init__(input_modifier=input_modifier, output_value_type=SFXVal, input_sampling=input_sampling) self.atr = ATR(atr_period) self.std_dev = StdDev(std_dev_period, input_modifier=ValueExtractor.extract_close) self.ma_std_dev = MAFactory.get_ma(ma_type, std_dev_smoothing_period, input_indicator=self.std_dev) self.add_sub_indicator(self.atr) self.add_sub_indicator(self.std_dev) self.initialize(input_values, input_indicator) ``` -------------------------------- ### UO Constructor Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/UO?q= Initializes the Ultimate Oscillator indicator with specified periods and optional input configuration. ```APIDOC ## UO Constructor ### Description Creates an instance of the Ultimate Oscillator (UO) indicator. The Ultimate Oscillator is a technical analysis indicator that combines short, mid, and long-term price action to generate buy and sell signals. It requires three period parameters and optionally accepts input values, an input indicator, a modifier, and a sampling type. ### Method Constructor ### Signature ``` UO( fast_period: int, mid_period: int, slow_period: int, input_values: List[OHLCV] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, input_sampling: SamplingPeriodType = None, ) ``` ### Parameters - **fast_period** (int) - Required - Fast period for the Ultimate Oscillator calculation. - **mid_period** (int) - Required - Mid period for the Ultimate Oscillator calculation. - **slow_period** (int) - Required - Slow period for the Ultimate Oscillator calculation. - **input_values** (List[OHLCV]) - Optional - List of input values (OHLCV data). Default is None. - **input_indicator** (Indicator) - Optional - Input indicator to use as source data. Default is None. - **input_modifier** (InputModifierType) - Optional - Input modifier to apply to the data. Default is None. - **input_sampling** (SamplingPeriodType) - Optional - Input sampling type. Default is None. ### Input Type OHLCV ### Output Type float ### Source Code ```python def __init__(self, fast_period: int, mid_period: int, slow_period: int, input_values: List[OHLCV] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, input_sampling: SamplingPeriodType = None): super().__init__(input_modifier=input_modifier, input_sampling=input_sampling) self.fast_period = fast_period self.mid_period = mid_period self.slow_period = slow_period self.buy_press = [] self.true_range = [] self.add_managed_sequence(self.buy_press) self.add_managed_sequence(self.true_range) self.initialize(input_values, input_indicator) ``` ``` -------------------------------- ### DEMA Initialization Source Code Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/DEMA?q= The implementation of the DEMA class constructor, showing how it initializes sub-indicators and manages sequences. ```python def __init__(self, period: int, input_values: List[float] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, input_sampling: SamplingPeriodType = None): super().__init__(input_modifier=input_modifier, input_sampling=input_sampling) self.period = period self.ema = EMA(period) self.add_sub_indicator(self.ema) self.ema_ema = EMA(period) self.add_managed_sequence(self.ema_ema) self.initialize(input_values, input_indicator) ``` -------------------------------- ### ChaikinOsc __init__ source code Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/ChaikinOsc Source code of the __init__ method from talipp/indicators/ChaikinOsc.py. It initializes the indicator, creates an AccuDist sub-indicator, and sets up fast and slow moving averages using MAFactory. ```python def __init__(self, fast_period: int, slow_period: int, input_values: List[OHLCV] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, ma_type: MAType = MAType.EMA, input_sampling: SamplingPeriodType = None): super().__init__(input_modifier=input_modifier, input_sampling=input_sampling) self.fast_period = fast_period self.slow_period = slow_period self.accu_dist = AccuDist() self.add_sub_indicator(self.accu_dist) self.ma_fast = MAFactory.get_ma(ma_type, fast_period, input_modifier=input_modifier) self.add_managed_sequence(self.ma_fast) self.ma_slow = MAFactory.get_ma(ma_type, slow_period, input_modifier=input_modifier) self.add_managed_sequence(self.ma_slow) self.initialize(input_values, input_indicator) ``` -------------------------------- ### TTM Source Code Initialization Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/TTM?q= The internal implementation of the TTM indicator's __init__ method, showing how sub-indicators like BB, DonchianChannels, and KeltnerChannels are initialized and managed. ```python def __init__(self, period: int, bb_std_dev_mult: float = 2, kc_atr_mult: float = 1.5, input_values: List[OHLCV] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, ma_type: MAType = MAType.SMA, input_sampling: SamplingPeriodType = None): super().__init__(input_modifier=input_modifier, output_value_type=TTMVal, input_sampling=input_sampling) self.period = period self.bb = BB(period, bb_std_dev_mult, input_modifier=ValueExtractor.extract_close) self.dc = DonchianChannels(period) self.kc = KeltnerChannels(period, period, kc_atr_mult, kc_atr_mult) self.ma = MAFactory.get_ma(ma_type, period, input_modifier=ValueExtractor.extract_close) self.add_sub_indicator(self.bb) self.add_sub_indicator(self.dc) self.add_sub_indicator(self.kc) self.add_sub_indicator(self.ma) self.deltas = [] self.add_managed_sequence(self.deltas) # pre-compute values for linear regression self.mean_x = sum(range(self.period)) / float(self.period) self.denom = 0 for x in range(self.period): self.denom += (x - self.mean_x) ** 2 self.initialize(input_values, input_indicator) ``` -------------------------------- ### Indicator.__init__ Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/Indicator?q= Constructor for the Indicator base class. Initializes the indicator with optional input modifier, output value type, and input sampling period. ```APIDOC ## Indicator.__init__ ### Description Initializes an Indicator instance with optional input modifier, output value type, and input sampling period. ### Method Constructor ### Signature ```python Indicator( input_modifier: InputModifierType = None, output_value_type: Type = float, input_sampling: SamplingPeriodType = None, ) ``` ### Parameters - **input_modifier** (InputModifierType) - Optional - Input modifier. - **output_value_type** (Type) - Optional - Output value type. Default is float. - **input_sampling** (SamplingPeriodType) - Optional - Input sampling type. ``` -------------------------------- ### WMA Implementation Source Code Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/WMA The internal implementation of the WMA indicator's __init__ method, showing how the period and denominator sum are initialized. ```python def __init__(self, period: int, input_values: List[float] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, input_sampling: SamplingPeriodType = None): super().__init__(input_modifier=input_modifier, input_sampling=input_sampling) self.period = period self.denom_sum = period * (period + 1) / 2.0 self.initialize(input_values, input_indicator) ``` -------------------------------- ### DPO __init__ source code Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/DPO Source code of the DPO class __init__ method from talipp/indicators/DPO.py. It initializes the indicator with the given period, creates a moving average sub-indicator using MAFactory, and adds it as a sub-indicator. ```python def __init__(self, period: int, input_values: List[float] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, ma_type: MAType = MAType.SMA, input_sampling: SamplingPeriodType = None): super().__init__(input_modifier=input_modifier, input_sampling=input_sampling) self.period = period self.ma = MAFactory.get_ma(ma_type, period) self.add_sub_indicator(self.ma) self.initialize(input_values, input_indicator) ``` -------------------------------- ### BOP __init__ source code Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/BOP Source code of the BOP class __init__ method from talipp/indicators/BOP.py. It initializes the indicator with the provided input values and indicator. ```python def __init__(self, input_values: List[OHLCV] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, input_sampling: SamplingPeriodType = None): super().__init__(input_modifier=input_modifier, input_sampling=input_sampling) self.initialize(input_values, input_indicator) ``` -------------------------------- ### ZLEMA __init__ source code Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/ZLEMA Source code of the ZLEMA __init__ method. It sets the lag as half the period minus one, creates an internal EMA indicator, adds it as a managed sequence, and initializes with the provided inputs. ```python def __init__(self, period: int, input_values: List[float] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, input_sampling: SamplingPeriodType = None): super().__init__(input_modifier=input_modifier, input_sampling=input_sampling) self.lag = round((period - 1) / 2.0) self.ema = EMA(period) self.add_managed_sequence(self.ema) self.initialize(input_values, input_indicator) ``` -------------------------------- ### Indicator.__init__ source code Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/Indicator?q= Source code for the Indicator constructor. Initializes input_modifier, output_value_type, input_sampler (if input_sampling is provided), and empty lists for input_values, output_values, managed_sequences, sub_indicators, and output_listeners. ```python def __init__(self, input_modifier: InputModifierType = None, output_value_type: Type = float, input_sampling: SamplingPeriodType = None): self.input_modifier = input_modifier self.output_value_type = output_value_type self.input_sampler: Sampler = None if input_sampling is not None: self.input_sampler = Sampler(input_sampling) self.input_values: ListAny = [] self.output_values: ListAny = [] self.managed_sequences: List[ManagedSequenceType] = [] self.sub_indicators: List[Indicator] = [] self.output_listeners: List[Indicator] = [] ``` -------------------------------- ### BOP Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/BOP Constructor for the BOP indicator. Initializes the indicator with input values, an input indicator, an input modifier, and input sampling. ```APIDOC ## BOP ### Description Constructor for the Balance Of Power (BOP) indicator. Initializes the indicator with input values, an input indicator, an input modifier, and input sampling. ### Method Constructor ### Signature ```python BOP( input_values: List[OHLCV] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, input_sampling: SamplingPeriodType = None, ) ``` ### Parameters - **input_values** (List[OHLCV]) - Optional - List of input values. - **input_indicator** (Indicator) - Optional - Input indicator. - **input_modifier** (InputModifierType) - Optional - Input modifier. - **input_sampling** (SamplingPeriodType) - Optional - Input sampling type. ### Input Type `float` ### Output Type `float` ### Source Code Source code in `talipp/indicators/BOP.py` ```python def __init__(self, input_values: List[OHLCV] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, input_sampling: SamplingPeriodType = None): super().__init__(input_modifier=input_modifier, input_sampling=input_sampling) self.initialize(input_values, input_indicator) ``` ``` -------------------------------- ### SFX Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/SFX?q= Constructor for the SFX indicator class. ```APIDOC ## SFX ### Description SFX indicator that computes ATR, standard deviation, and its moving average. ### Constructor ```python SFX( atr_period: int, std_dev_period: int, std_dev_smoothing_period: int, input_values: List[OHLCV] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, ma_type: MAType = MAType.SMA, input_sampling: SamplingPeriodType = None, ) ``` ### Parameters - **atr_period** (int) - Required - ATR period. - **std_dev_period** (int) - Required - Standard deviation period. - **std_dev_smoothing_period** (int) - Required - Standard deviation moving average period. - **input_values** (List[OHLCV]) - Optional - List of input values. Default: `None`. - **input_indicator** (Indicator) - Optional - Input indicator. Default: `None`. - **input_modifier** (InputModifierType) - Optional - Input modifier. Default: `None`. - **ma_type** (MAType) - Optional - Moving average type. Default: `SMA`. - **input_sampling** (SamplingPeriodType) - Optional - Input sampling type. Default: `None`. ### Output Type `SFXVal` ### Source Code ```python def __init__(self, atr_period: int, std_dev_period: int, std_dev_smoothing_period: int, input_values: List[OHLCV] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, ma_type: MAType = MAType.SMA, input_sampling: SamplingPeriodType = None): super().__init__(input_modifier=input_modifier, output_value_type=SFXVal, input_sampling=input_sampling) self.atr = ATR(atr_period) self.std_dev = StdDev(std_dev_period, input_modifier=ValueExtractor.extract_close) self.ma_std_dev = MAFactory.get_ma(ma_type, std_dev_smoothing_period, input_indicator=self.std_dev) self.add_sub_indicator(self.atr) self.add_sub_indicator(self.std_dev) self.initialize(input_values, input_indicator) ``` ``` -------------------------------- ### ParabolicSAR __init__ implementation Source: https://nardew.github.io/talipp/latest/reference/talipp/indicators/ParabolicSAR Source code of the ParabolicSAR __init__ method, which initializes the indicator with the provided parameters and calls initialize. ```python def __init__(self, init_accel_factor: float, accel_factor_inc: float, max_accel_factor: float, input_values: List[OHLCV] = None, input_indicator: Indicator = None, input_modifier: InputModifierType = None, input_sampling: SamplingPeriodType = None): super().__init__(input_modifier=input_modifier, output_value_type=ParabolicSARVal, input_sampling=input_sampling) self.init_accel_factor = init_accel_factor self.accel_factor_inc = accel_factor_inc self.max_accel_factor = max_accel_factor self.initialize(input_values, input_indicator) ```