mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-26 06:18:05 +00:00
Add eventing support to WMA indicator and implement unit tests for various indicators
- Enhanced WMA indicator with event-driven capabilities using ITValuePublisher interface. - Created a new TODO file listing various indicators and their corresponding libraries. - Added unit tests for DEMA, HMA, TEMA, and WMA indicators to ensure proper functionality. - Implemented tests for handling new bars, ticks, and historical data updates across indicators. - Verified that indicators correctly compute values and handle different source types.
This commit is contained in:
@@ -125,6 +125,34 @@ sma.Update(new TValue(time + 1, 101.2), isNew: true);
|
||||
|
||||
**Implementation detail:** Bar correction is O(1) using scalar state save/restore, not buffer copying.
|
||||
|
||||
### Eventing and Reactive Support
|
||||
|
||||
This indicator implements the `ITValuePublisher` interface, enabling event-driven and reactive workflows.
|
||||
|
||||
* **Subscription:** Can be constructed with an `ITValuePublisher` (e.g., `TSeries`) to automatically update when the source emits a new value.
|
||||
* **Publication:** Emits a `Pub` event with the new `TValue` whenever it is updated.
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
// 1. Setup a source (publisher)
|
||||
var source = new TSeries();
|
||||
|
||||
// 2. Create indicator subscribed to source
|
||||
// It waits for events from 'source'
|
||||
var sma = new Sma(source, period: 10);
|
||||
|
||||
// 3. Optional: Subscribe to indicator's output
|
||||
sma.Pub += (item) => Console.WriteLine($"SMA Updated: {item.Value}");
|
||||
|
||||
// 4. Ingest data into source
|
||||
// This triggers the chain: source -> sma -> Console.WriteLine
|
||||
source.Add(new TValue(DateTime.Now, 100));
|
||||
source.Add(new TValue(DateTime.Now, 105));
|
||||
```
|
||||
|
||||
This pattern allows building complex, reactive processing pipelines without manual update loops.
|
||||
|
||||
### Handling Invalid Values (NaN/Infinity)
|
||||
|
||||
`Sma` uses **last-value substitution** for handling invalid inputs:
|
||||
|
||||
Reference in New Issue
Block a user