Back to list
DaveSkender

indicator-stream

by DaveSkender

Stock Indicators for .NET is a C# NuGet package that transforms raw equity, commodity, forex, or cryptocurrency financial market price quotes into technical indicators and trading insights. You'll need this essential data in the investment tools that you're building for algorithmic trading, technical analysis, machine learning, or visual charting.

1,169🍴 265📅 Jan 22, 2026

SKILL.md


name: indicator-stream description: Implement StreamHub real-time indicators with O(1) performance. Use for ChainHub or QuoteProvider implementations. Covers provider selection, RollbackState patterns, performance anti-patterns, and comprehensive testing with StreamHubTestBase.

StreamHub indicator development

Provider selection

Provider BaseInputOutputUse Case
ChainHub<IReusable, TResult>Single valueIReusableChainable indicators
ChainHub<IQuote, TResult>OHLCVIReusableQuote-driven, chainable output
QuoteProvider<IQuote, TResult>OHLCVIQuoteQuote-to-quote transformation
StreamHub<TProviderResult, TResult>Any hub resultAny resultCompound hubs (internal hub dependency)

Performance requirements

Target: StreamHub ≤ 1.5x slower than Series

Anti-pattern 1: O(n²) recalculation (FORBIDDEN)

// WRONG - Rebuilds entire history on each tick
for (int k = 0; k <= i; k++) { subset.Add(cache[k]); }
var result = subset.ToIndicator();

Correct: O(1) incremental update

// CORRECT - Maintain state, update incrementally
_avgGain = ((_avgGain * (period - 1)) + gain) / period;

Anti-pattern 2: O(n) window scans

Use RollingWindowMax/Min utilities instead of linear scans for max/min operations.

RollbackState pattern

Override when maintaining stateful fields:

protected override void RollbackState(DateTime timestamp)
{
    int targetIndex = ProviderCache.IndexGte(timestamp);

    _window.Clear();

    if (targetIndex <= 0) return;

    int restoreIndex = targetIndex - 1;  // Rebuild up to but NOT including timestamp
    int startIdx = Math.Max(0, restoreIndex + 1 - LookbackPeriods);

    for (int p = startIdx; p <= restoreIndex; p++)
        _window.Add(ProviderCache[p].Value);
}

Critical: Replay up to targetIndex - 1 (exclusive of rollback timestamp). The quote at the rollback timestamp will be recalculated when it arrives via normal processing.

Testing requirements

  1. Inherit from StreamHubTestBase
  2. Implement exactly ONE observer interface:
    • ITestChainObserver (most common)
    • ITestQuoteObserver (quote-only providers)
  3. Implement at most ONE provider interface: ITestChainProvider
  4. Comprehensive rollback validation (required):
    • Prefill warmup window before subscribing
    • Stream in-order including duplicates
    • Insert a late historical quote → verify recalculation
    • Remove a historical quote → verify recalculation
    • Compare results to Series with strict ordering

Required implementation

  • Source code: src/**/{IndicatorName}.StreamHub.cs file exists
    • Uses appropriate provider base (ChainHub or QuoteProvider)
    • Validates parameters in constructor; calls Reinitialize() as needed
    • Implements O(1) state updates; avoids O(n²) recalculation
    • Overrides RollbackState() when maintaining stateful fields
    • Overrides ToString() with concise hub name
  • Unit testing: tests/indicators/**/{IndicatorName}.StreamHub.Tests.cs exists
    • Inherits StreamHubTestBase with correct test interfaces
    • Comprehensive rollback validation present
    • Verifies Series parity

Examples

  • Chain: src/e-k/Ema/Ema.StreamHub.cs
  • Complex state: src/a-d/Adx/Adx.StreamHub.cs
  • Rolling window: src/a-d/Chandelier/Chandelier.StreamHub.cs
  • Compound hub: src/s-z/StochRsi/StochRsi.StreamHub.cs, src/e-k/Gator/Gator.StreamHub.cs

See references/ for detailed patterns:

  • provider-selection.md - Choosing the right provider base
  • rollback-patterns.md - RollbackState implementation examples
  • performance-patterns.md - O(1) optimization techniques
  • compound-hubs.md - Internal hub dependencies and construction patterns

Last updated: January 19, 2026

Score

Total Score

90/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

+10
人気

GitHub Stars 1000以上

+15
最近の活動

1ヶ月以内に更新

+10
フォーク

10回以上フォークされている

+5
Issue管理

オープンIssueが50未満

0/5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

+5

Reviews

💬

Reviews coming soon