How timeframe auto-sampling works
mainTimeframe auto-sampling is a feature for indicators using OHLCV input. Instead of adding a new output value for every single input received, the indicator 'merges' multiple inputs that fall within the same selected timeframe. It keeps only the last value received within that period.
This is particularly useful for real-time applications that receive high-frequency data (e.g., hundreds of updates per second) but require indicators to be calculated on a specific sampled timeframe like 1 minute or 15 seconds.
# Example of the merging behavior
obv = OBV(input_sampling=SamplingPeriodType.SEC_15)
# 00:00:00 -> New timeframe starts, length becomes 1
obv.add(OHLCV(..., time=dt.replace(second=0)))
# 00:00:13 -> Still within the same 15s window, length stays 1 (last value updated)
obv.add(OHLCV(..., time=dt.replace(second=13)))
# 00:00:17 -> New 15s window started, length becomes 2
obv.add(OHLCV(..., time=dt.replace(second=17)))