### Install and Run Docs Dev Server Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/AGENTS.md Installs project dependencies and starts the VitePress development server. Requires refreshing GitHub CLI token with read:packages scope. ```bash gh auth refresh --scopes read:packages NODE_AUTH_TOKEN=$(gh auth token) pnpm install pnpm run docs:dev ``` -------------------------------- ### SSE Simulation Examples Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/tools/simulate/README.md Examples demonstrating various configurations for SSE simulation, including different data types, delivery intervals, counts, and bar intervals. ```bash dotnet run -- sse # Bar data, 100ms delivery, 1m timestamps, runs indefinitely ``` ```bash dotnet run -- sse bar # Bar data, 100ms delivery, 1m timestamps, runs indefinitely ``` ```bash dotnet run -- sse bar 50 # Bar data, 50ms delivery, 1m timestamps, runs indefinitely ``` ```bash dotnet run -- sse bar 50 500 # Bar data, 50ms delivery, 1m timestamps, stops after 500 bars ``` ```bash dotnet run -- sse bar 100 1000 1h # Hourly bars delivered every 100ms, stops after 1000 bars ``` ```bash dotnet run -- sse bar 50 500 5m # 5-minute bars delivered every 50ms, stops after 500 bars ``` ```bash dotnet run -- sse bar 100 0 1d # Daily bars delivered every 100ms, runs indefinitely ``` ```bash dotnet run -- sse trade 100 1000 # Trade data, 100ms delivery, stops after 1000 ticks ``` -------------------------------- ### Coinbase WebSocket Simulation Examples Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/tools/simulate/README.md Examples for running Coinbase WebSocket simulations, covering kline, and ticker feeds for specified symbols and counts. ```bash dotnet run -- coinbase # BTC-USD klines, runs indefinitely ``` ```bash dotnet run -- coinbase-klines BTC-USD # BTC-USD klines, runs indefinitely ``` ```bash dotnet run -- coinbase-ticker ETH-USD # ETH-USD ticker feed, runs indefinitely ``` ```bash dotnet run -- coinbase BTC-USD 500 # BTC-USD klines, stops after 500 bars ``` ```bash dotnet run -- coinbase-ticker ETH-USD 1000 # ETH-USD ticker, stops after 1000 bars ``` -------------------------------- ### Start Docs Dev Server Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/AGENTS.md Starts the VitePress development server from the /docs folder. This is a prerequisite for using Playwright for visual inspection. ```bash # from /docs folder pnpm run docs:dev ``` -------------------------------- ### C# Usage Example Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/obv.md Demonstrates how to calculate OBV using historical price bars in C#. ```APIDOC ## C# Usage ```csharp IReadOnlyList results = bars.ToObv(); ``` ### Description This method calculates the On-Balance Volume (OBV) for a given collection of historical price bars. ### Requirements - Requires at least two historical price bars to cover warmup periods. More bars are recommended for trendline indicators. - `bars` should be a collection of generic `TBar` historical price bars with a consistent frequency. ### Response - Returns `IReadOnlyList`. - The number of elements in the result list is equal to the number of historical price bars provided. - The first period OBV will have a `0` value due to insufficient data for calculation. #### `ObvResult` Structure | Property | Type | Description | |-------------|----------|------------------------------| | `Timestamp` | `DateTime` | Date from evaluated `TBar` | | `Obv` | `double` | On-balance Volume value | ::: warning 馃毄 Absolute values in OBV are somewhat meaningless. Use with caution. ::: ### Utilities - [.Condense()](/utilities/results#condense) - [.Find(lookupDate)](/utilities/results#find-by-date) - [.RemoveWarmupPeriods(removePeriods)](/utilities/results#remove-warmup-periods) See [Utilities and helpers](/utilities/) for more information. ### Chaining Results can be further processed on `Obv` with additional chain-enabled indicators. ```csharp // example var results = bars .ToObv(..) .ToRsi(..); ``` This indicator must be generated from `bars` and **cannot** be generated from results of another chain-enabled indicator or method. See [Chaining indicators](/guide/chaining) for more. ### Streaming Use the buffer-style `List` when you need incremental calculations without a hub: ```csharp ObvList obvList = new(); foreach (IBar bar in bars) // simulating stream { obvList.Add(bar); } // based on `ICollection` IReadOnlyList results = obvList; ``` Subscribe to a `BarHub` for advanced streaming scenarios: ```csharp BarHub barHub = new(); ObvHub observer = barHub.ToObvHub(); foreach (IBar bar in bars) // simulating stream { barHub.Add(bar); } IReadOnlyList results = observer.Results; ``` See [Buffer lists](/guide/styles/buffer) and [Stream hubs](/guide/styles/stream) for full usage guides. ``` -------------------------------- ### Install Node Packages with Authentication Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/README.md Installs project dependencies using pnpm, authenticating with GitHub Packages using a personal access token. This is required for local development. ```bash gh auth refresh --scopes read:packages # one-time per token cd docs NODE_AUTH_TOKEN=$(gh auth token) pnpm install pnpm run docs:dev ``` -------------------------------- ### Stochastic RSI Backtest Example in C# Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/examples/index.md This example demonstrates a 20-year backtest of a Stochastic RSI strategy. It simulates buying and selling based on indicator crossovers in overbought and oversold regions. Ensure you have a data provider implemented for GetQuotesFromFeed(). ```csharp /* This is a basic 20-year backtest-style analysis of * Stochastic RSI. It will buy-to-open (BTO) one share * when the Stoch RSI (%K) is below 20 and crosses over the * Signal (%D). The reverse Sell-to-Close (STC) and * Sell-To-Open (STO) occurs when the Stoch RSI is above 80 and * crosses below the Signal. * * As a result, there will always be one open LONG or SHORT * position that is opened and closed at signal crossover * points in the overbought and oversold regions of the indicator. */ // fetch historical quotes from data provider List quotesList = GetQuotesFromFeed() .ToList(); // calculate Stochastic RSI List resultsList = quotesList .ToStochRsi(14, 14, 3, 1) .ToList(); // initialize decimal trdPrice = 0; decimal trdQty = 0; decimal rlzGain = 0; Console.WriteLine(" Date Close StRSI Signal Cross Net Gains"); Console.WriteLine("-------------------------------------------------------"); // roll through source values for (int i = 1; i < quotesList.Count; i++) { Quote q = quotesList[i]; StochRsiResult e = resultsList[i]; // evaluation period StochRsiResult l = resultsList[i - 1]; // last (prior) period string cross = string.Empty; // unrealized gain on open trade decimal trdGain = trdQty * (q.Close - trdPrice); // check for LONG event // condition: Stoch RSI was <= 20 and Stoch RSI crosses over Signal if (l.StochRsi <= 20 && l.StochRsi < l.Signal && e.StochRsi >= e.Signal && trdQty != 1) { // emulates BTC + BTO rlzGain += trdGain; trdQty = 1; trdPrice = q.Close; cross = "LONG"; } // check for SHORT event // condition: Stoch RSI was >= 80 and Stoch RSI crosses under Signal if (l.StochRsi >= 80 && l.StochRsi > l.Signal && e.StochRsi <= e.Signal && trdQty != -1) { // emulates STC + STO rlzGain += trdGain; trdQty = -1; trdPrice = q.Close; cross = "SHORT"; } if (cross != string.Empty) { Console.WriteLine( $讬专转{q.Timestamp,10:yyyy-MM-dd} " + $讬专转{q.Close,10:c2}" + $讬专转{e.StochRsi,7:N1}" + $讬专转{e.Signal,7:N1}" + $讬专转{cross,7}" + $讬专转{rlzGain + trdGain,13:c2}"); } } ``` -------------------------------- ### Install Stock Indicators NuGet Package Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/guide/getting-started.md Use the .NET CLI or Package Manager Console to add the FacioQuo.Stock.Indicators NuGet package to your project. ```bash # dotnet CLI example dotnet add package FacioQuo.Stock.Indicators ``` ```powershell # package manager example Install-Package FacioQuo.Stock.Indicators ``` -------------------------------- ### Basic C# Implementation Pattern Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/guide/getting-started.md This illustrates the fundamental steps for using the library: obtaining price bars and calculating indicator values. It's a starting point before diving into specific indicator styles. ```csharp using FacioQuo.Stock.Indicators; [..] // step 1: get price bar(s) from your source // step 2: calculate indicator value(s) ``` -------------------------------- ### C# Usage Example Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/fractal.md Demonstrates how to calculate Fractal results using historical price bars. Requires at least 2*S+1 bars for calculation. ```csharp IReadOnlyList results = bars.ToFractal(windowSpan); ``` -------------------------------- ### Install .NET CLI tools and restore NuGet packages Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/CONTRIBUTING.md Run these commands once after cloning to set up your development environment. Ensure .NET CLI tools are restored and all project dependencies are fetched. ```bash dotnet tool restore # install .NET CLI tools ``` ```bash dotnet restore # restore NuGet packages ``` -------------------------------- ### Chaining HtTrendline with CandlePart Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/ht-trendline.md Example of chaining the HtTrendline indicator after using CandlePart.HLC3, demonstrating how to preprocess bars before indicator calculation. ```csharp // example var results = bars .Use(CandlePart.HLC3) .ToHtTrendline(..); ``` -------------------------------- ### MACD Calculation with CandlePart.HL2 Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/macd.md This example demonstrates chaining the `ToMacd` indicator after using `CandlePart.HL2` to specify the price to be used in the calculation. This allows for flexible price selection for MACD computation. ```csharp // example var results = bars .Use(CandlePart.HL2) .ToMacd(..); ``` -------------------------------- ### Streaming Support for Technical Indicators in C# Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/README.md Demonstrates how to use the streaming capabilities introduced in v3 for real-time data processing. This example shows setting up a BarHub, subscribing indicators like EMA and RSI, and processing live price bars as they arrive. ```csharp BarHub barHub = new(); EmaHub emaHub = barHub.ToEma(20); RsiHub rsiHub = barHub.ToRsi(14); foreach (Bar bar in liveBars) { barHub.Add(bar); EmaResult emaResult = emaHub.Results[^1]; RsiResult rsiResult = rsiHub.Results[^1]; } ``` -------------------------------- ### C# Usage Example Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/pmo.md This C# code snippet demonstrates how to calculate the PMO indicator using historical price bars. It shows the method signature and the expected return type. ```APIDOC ## Calculate PMO ### Description Calculates the Price Momentum Oscillator (PMO) indicator for a given series of historical price bars. ### Method `ToPmo(timePeriods, smoothPeriods, signalPeriods)` ### Parameters #### Path Parameters - `bars` (IReadOnlyList) - Required - A collection of generic `TBar` historical price bars. #### Query Parameters - `timePeriods` (int) - Optional - Number of periods (`T`) for first ROC smoothing. Must be greater than 1. Default is 35. - `smoothPeriods` (int) - Optional - Number of periods (`S`) for second PMO smoothing. Must be greater than 0. Default is 20. - `signalPeriods` (int) - Optional - Number of periods (`G`) for Signal line EMA. Must be greater than 0. Default is 10. ### Response #### Success Response (IReadOnlyList) - `Timestamp` (DateTime) - Date from evaluated `TBar`. - `Pmo` (double) - Price Momentum Oscillator. - `Signal` (double) - Signal line is EMA of PMO. ### Request Example ```csharp IReadOnlyList results = bars.ToPmo(timePeriods, smoothPeriods, signalPeriods); ``` ### Response Example ```csharp // Example of PmoResult structure { "Timestamp": "2023-10-27T00:00:00Z", "Pmo": 15.75, "Signal": 12.30 } ``` ``` -------------------------------- ### Keltner Channels Chaining Example Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/keltner.md Demonstrates how to chain Keltner Channel calculations with other indicators. Note that Keltner Channels must be generated from raw price bars and cannot be chained from other indicator results. ```csharp // example var results = bars .ToKeltner(..); ``` -------------------------------- ### Streaming Heikin-Ashi Calculations with BarHub Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/heikin-ashi.md This example demonstrates advanced streaming of Heikin-Ashi calculations using a `BarHub`. This is ideal for real-time data feeds and complex streaming architectures. ```csharp BarHub barHub = new(); HeikinAshiHub observer = barHub.ToHeikinAshiHub(); foreach (IBar bar in bars) // simulating stream { barHub.Add(bar); } IReadOnlyList results = observer.Results; ``` -------------------------------- ### Build and Preview Docs Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/AGENTS.md Builds the production-ready documentation site and then previews it locally. The preview runs on port 4173. ```bash # Production build pnpm run docs:build # Preview production build (port 4173) pnpm run docs:preview ``` -------------------------------- ### Build and Run Application Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/tools/application/README.md Commands to navigate to the application directory, restore dependencies, build the project, and run the application. ```bash cd tools/application dotnet restore dotnet build dotnet run ``` -------------------------------- ### Display Help Information Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/tools/baselining/README.md Run this command to view all available options and usage instructions for the Baseline Generator tool. ```bash dotnet run --project tools/baselining -- --help ``` -------------------------------- ### Chain TEMA results with subsequent indicators Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/tema.md Results from TEMA can be further processed by other chain-enabled indicators, such as RSI in this example. ```csharp // example var results = bars .ToTema(..) .ToRsi(..); ``` -------------------------------- ### Build Documentation Site Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/README.md Builds the static documentation site for production. The output will be placed in the .vitepress/dist/ directory. ```bash pnpm run docs:build ``` -------------------------------- ### Run Documentation Development Server Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/CONTRIBUTING.md Navigate to the docs folder and run the development server for the documentation site. The site will be available at http://localhost:5173/. ```bash cd docs pnpm run docs:dev ``` -------------------------------- ### Chain TEMA with other indicators Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/tema.md TEMA can be chained with other indicators. This example first uses `CandlePart.HL2` and then calculates TEMA. ```csharp // example var results = bars .Use(CandlePart.HL2) .ToTema(..); ``` -------------------------------- ### Chaining MA Envelopes Calculation Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/ma-envelopes.md Example of how to chain the MA Envelopes indicator calculation after using a price bar selection. ```csharp // example var results = bars .Use(CandlePart.HLC3) .ToMaEnvelopes(..); ``` -------------------------------- ### Chain EPMA with Subsequent Indicators Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/epma.md Results from EPMA can be further processed by chaining additional indicators, such as RSI in this example. ```csharp // example var results = bars .ToEpma(..) .ToRsi(..); ``` -------------------------------- ### Build Project with Dotnet CLI Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/AGENTS.md Builds the solution using the dotnet CLI with minimal verbosity and no logo. ```bash dotnet build "Stock.Indicators.sln" -v minimal --nologo ``` -------------------------------- ### Run .NET Benchmarks Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/tools/performance/PERFORMANCE_ANALYSIS.md Navigate to the performance tools directory and execute release benchmarks. Results are saved in JSON format for compliance checks. ```bash cd tools/performance dotnet run -c Release ``` -------------------------------- ### Streaming HMA with BarHub Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/hma.md Subscribe to a BarHub for advanced streaming scenarios to get incremental HMA calculations. ```csharp BarHub barHub = new(); HmaHub observer = barHub.ToHmaHub(lookbackPeriods); foreach (IBar bar in bars) // simulating stream { barHub.Add(bar); } IReadOnlyList results = observer.Results; ``` -------------------------------- ### Chain EPMA Calculation with Other Indicators Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/epma.md EPMA can be chained with other indicators. This example shows calculating EPMA after using `CandlePart.HL2`. ```csharp // example var results = bars .Use(CandlePart.HL2) .ToEpma(..); ``` -------------------------------- ### Preview Production Build Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/README.md Builds and previews the documentation site as it would appear in production. This is useful for testing the final output before deployment. ```bash pnpm run docs:preview ``` -------------------------------- ### Run All Performance Benchmarks Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/CONTRIBUTING.md Execute all performance benchmarks in Release mode from the tools/performance directory. This process can take approximately one hour. ```bash # from /tools/performance folder # run all performance benchmarks (~1 hour) dotnet run -c Release ``` -------------------------------- ### MFI Hub Streaming Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/mfi.md Illustrates how to subscribe to a BarHub for advanced streaming scenarios to get incremental MFI calculations. ```APIDOC ## ToMfiHub ### Description Subscribes to a `BarHub` to receive incremental Money Flow Index (MFI) calculations. ### Usage ```csharp BarHub barHub = new BarHub(); MfiHub observer = barHub.ToMfiHub(lookbackPeriods); foreach (IBar bar in bars) // simulating stream { barHub.Add(bar); } // Access the calculated results IReadOnlyList results = observer.Results; ``` ``` -------------------------------- ### MACD Streaming with BarHub Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/macd.md Shows how to subscribe to a `BarHub` for advanced streaming scenarios to get MACD indicator values. ```APIDOC ## MacdHub ### Description Observes a `BarHub` to provide incremental MACD indicator calculations. ### Method Signature ```csharp public class MacdHub : IObservable ``` ### Usage Example ```csharp BarHub barHub = new(); MacdHub observer = barHub.ToMacdHub(fastPeriods, slowPeriods, signalPeriods); foreach (IBar bar in bars) // simulating stream { barHub.Add(bar); } // Access results IReadOnlyList results = observer.Results; ``` ``` -------------------------------- ### Create Performance Baseline Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/tools/performance/benchmarking.md Copies the latest benchmark results to a baseline file for future comparisons. Run from the repository root. ```bash # After running benchmarks (from repo root) cp tools/performance/BenchmarkDotNet.Artifacts/results/Performance.*-report-full.json tools/performance/baselines/baseline-v3.0.0.json ``` -------------------------------- ### C# Usage Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/smma.md Example of how to use the `ToSmma` extension method in C# to calculate the SMMA indicator on a collection of price bars. ```APIDOC ## C# Usage ### Description This code snippet demonstrates how to calculate the Smoothed Moving Average (SMMA) indicator using the `ToSmma` extension method in C#. It takes a collection of price bars and a lookback period as input and returns a list of `SmmaResult` objects. ### Method Signature ```csharp IReadOnlyList ToSmma(int lookbackPeriods) ``` ### Parameters #### Path Parameters - **lookbackPeriods** (`int`) - Required - Number of periods (`N`) in the moving average. Must be greater than 0. ### Request Example ```csharp // Assuming 'bars' is an IEnumerable or similar collection of price bars IReadOnlyList results = bars.ToSmma(lookbackPeriods); ``` ### Response - **Type**: `IReadOnlyList` - This method returns a time series of all available indicator values for the provided `bars`. - It always returns the same number of elements as there are in the historical price bars. - The first `N-1` periods will have `null` values since there's not enough data to calculate. ### `SmmaResult` Properties - **Timestamp** (`DateTime`) - Date from evaluated `TBar`. - **Smma** (`double`) - The calculated Smoothed Moving Average value. ``` -------------------------------- ### Basic Buffer List Usage Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/guide/styles/buffer.md Demonstrates how to create a buffer list, add bars incrementally, and safely access the latest result. Ensure bars are added in chronological order to avoid incorrect calculations. ```csharp using FacioQuo.Stock.Indicators; // create buffer list with lookback period SmaList smaList = new(lookbackPeriods: 20); // add bars incrementally (e.g., from a data feed) foreach (Bar bar in bars) { smaList.Add(bar); // safely get latest result if (smaList.Count > 0) { SmaResult r = smaList[^1]; // use result (SMA is null during warmup period) if (r.Sma is not null) { Console.WriteLine($"{r.Timestamp:d}: SMA = {r.Sma:N2}"); } } } ``` -------------------------------- ### Chain HMA with Candle Part Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/hma.md Example of chaining the HMA indicator after selecting a specific candle part (e.g., HL2). ```csharp // example var results = bars .Use(CandlePart.HL2) .ToHma(..); ``` -------------------------------- ### ConnorsRSI with Chained Indicators Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/connors-rsi.md Demonstrates chaining the ConnorsRSI calculation with other indicators, starting from price bars and potentially chaining further indicators after ConnorsRSI. ```csharp // example var results = bars .Use(CandlePart.HL2) .ToConnorsRsi(..); ``` ```csharp // example var results = bars .ToConnorsRsi(..) .ToSma(..); ``` -------------------------------- ### Sample SMA Calculation Output Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/guide/getting-started.md This is an example of the console output you might see after calculating the SMA for a series of historical price bars. ```console SMA on 4/19/2018 was $255.0590 SMA on 4/20/2018 was $255.2015 SMA on 4/23/2018 was $255.6135 SMA on 4/24/2018 was $255.5105 SMA on 4/25/2018 was $255.6570 SMA on 4/26/2018 was $255.9705 .. ``` -------------------------------- ### Grant GitHub CLI Token Access Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/CONTRIBUTING.md Grant your GitHub CLI token read:packages access. This is a one-time setup step. ```bash gh auth refresh --scopes read:packages ``` ```bash gh auth token ``` -------------------------------- ### Run All Performance Benchmarks Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/tests/indicators/README.md Execute all performance benchmarks in Release mode. This process can take approximately 15-20 minutes and generates benchmark performance data. ```bash dotnet run -c Release ``` -------------------------------- ### Filter Benchmarks by Name Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/tools/performance/benchmarking.md Use the --filter argument to run specific benchmark categories. This example filters for benchmarks containing 'Ema'. ```bash dotnet run -c Release -- --filter "*Ema*" ``` -------------------------------- ### Basic Stream Hub Usage with Indicators Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/guide/styles/stream.md Demonstrates creating a BarHub, subscribing SMA and RSI indicators, and processing live bars for coordinated updates and trading logic. ```csharp using FacioQuo.Stock.Indicators; // create bar hub (the data source) BarHub barHub = new(); // subscribe indicators to the hub SmaHub smaHub = barHub.ToSmaHub(20); RsiHub rsiHub = barHub.ToRsiHub(14); // stream bars as they arrive foreach (Bar bar in liveBars) { // adding to barHub automatically updates all subscribers barHub.Add(bar); // safely get latest results if (smaHub.Results.Count > 0) { SmaResult sma = smaHub.Results[^1]; RsiResult rsi = rsiHub.Results[^1]; // use results for trading logic, alerts, etc. if (sma.Sma is not null && rsi.Rsi > 70) { Console.WriteLine($"{bar.Timestamp:d}: Overbought at {bar.Close:C2}"); } } } ``` -------------------------------- ### Create Preview Tag for Deployment Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/CONTRIBUTING.md Use this command to create a Git tag for a pre-release version from a stable branch. GitVersion will use the tag's suffix for versioning. ```bash # Create preview tag git tag 2.8.0-preview.1 git push origin 2.8.0-preview.1 # Then trigger manual workflow deployment with preview=true ``` -------------------------------- ### Streaming Donchian Channels with Hubs Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/donchian.md Illustrates how to use `BarHub` and `DonchianHub` for advanced streaming scenarios to get incremental Donchian Channel calculations. ```APIDOC ## Streaming Donchian Channels with Hubs ### Description Subscribes to a `BarHub` to receive incremental Donchian Channel calculations using `DonchianHub`. ### Usage ```csharp BarHub barHub = new(); DonchianHub observer = barHub.ToDonchianHub(lookbackPeriods); foreach (IBar bar in bars) // simulating stream { barHub.Add(bar); } IReadOnlyList results = observer.Results; ``` ### Related Utilities - See [Stream hubs](/guide/styles/stream) for full usage guides. ``` -------------------------------- ### Configure Hub with Modest Cache Size Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/guide/styles/stream.md Shows how to configure a `BarHub` with a specific `maxCacheSize` to optimize memory usage while ensuring sufficient history for indicator warmups. ```csharp // configure a modest cache that still clears every warmup floor BarHub limitedHub = new(maxCacheSize: 500); // automatic FIFO pruning when limit reached SmaHub smaHub = limitedHub.ToSmaHub(20); ``` -------------------------------- ### C# Usage Syntax Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/cmf.md Example of how to calculate Chaikin Money Flow (CMF) using the `ToCmf` extension method on historical price bars in C#. ```APIDOC ## C# Usage Syntax ### Description Calculates the Chaikin Money Flow (CMF) indicator for a given number of lookback periods. ### Method Signature ```csharp IReadOnlyList ToCmf(this IEnumerable bars, int lookbackPeriods) ``` ### Parameters #### Path Parameters - `bars` (IEnumerable) - Required - Collection of historical price bars. - `lookbackPeriods` (int) - Required - Number of periods (N) in the moving average. Must be greater than 0. Default is 20. ### Response - `IReadOnlyList` - A list of CmfResult objects, each containing the indicator's calculated values for each bar. ### `CmfResult` Properties - `Timestamp` (DateTime) - Date from evaluated TBar. - `MoneyFlowMultiplier` (double) - Money Flow Multiplier. - `MoneyFlowVolume` (double) - Money Flow Volume. - `Cmf` (double) - Chaikin Money Flow = SMA of MFV. ### Example ```csharp // C# usage syntax IReadOnlyList results = bars.ToCmf(lookbackPeriods); ``` ``` -------------------------------- ### Run SSE Server Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/tools/sse-server/README.md Instructions for running the SSE server using dotnet run. Specify the URLs to bind to. ```bash dotnet run --project tools/sse-server -- --urls http://localhost:5001 ``` ```bash cd tools/sse-server dotnet run -- --urls http://localhost:5001 ``` -------------------------------- ### Chain WMA Calculation Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/wma.md Chain the `ToWma` method with other indicators or methods. This example shows calculating WMA after using `Use(CandlePart.HL2)` and chaining `ToRsi` after `ToWma`. ```csharp var results = bars .Use(CandlePart.HL2) .ToWma(..); ``` ```csharp var results = bars .ToWma(..) .ToRsi(..); ``` -------------------------------- ### Run Style Comparison Benchmark Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/tools/performance/PERFORMANCE_ANALYSIS.md Execute a comprehensive comparison benchmark for indicator styles using BenchmarkDotNet. Ensure you are in the tools/performance directory before running. ```bash cd tools/performance dotnet run -c Release -- --filter 'Performance.StyleComparison*' ``` -------------------------------- ### Streaming Example Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/tr.md Illustrates how to use True Range (TR) in a streaming context, either with buffer-style lists for incremental calculations or by subscribing to a BarHub for advanced scenarios. ```APIDOC ## Streaming True Range (TR) ### Description This section covers streaming calculations for the True Range (TR) indicator. It includes examples for both buffer-style lists and hub-based streaming. ### Buffer List Usage Use the buffer-style `List` when you need incremental calculations without a hub. ```csharp TrList trList = new(); foreach (IBar bar in bars) // simulating stream { trList.Add(bar); } // based on `ICollection` IReadOnlyList results = trList; ``` ### Stream Hub Usage Subscribe to a `BarHub` for advanced streaming scenarios. ```csharp BarHub barHub = new BarHub(); TrHub observer = barHub.ToTrHub(); foreach (IBar bar in bars) // simulating stream { barHub.Add(bar); } IReadOnlyList results = observer.Results; ``` ### Further Information See [Buffer lists](/guide/styles/buffer) and [Stream hubs](/guide/styles/stream) for full usage guides. ``` -------------------------------- ### Chaining Example Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/tr.md Demonstrates how to chain the True Range (TR) indicator with other indicators, such as calculating Average True Range (ATR) using a custom moving average. ```APIDOC ## Chaining Indicators ### Description Results from the True Range (TR) indicator can be used as input for subsequent chain-enabled indicators. This example shows calculating ATR using a custom moving average. ### Method Signature ```csharp // Example: ATR using a custom moving average var results = bars.ToTr().ToSmma(lookbackPeriods); ``` ### Important Note This indicator must be generated directly from `bars` and **cannot** be generated from the results of another chain-enabled indicator or method. ``` -------------------------------- ### Doji Pattern Calculation with Buffer List Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/doji.md Demonstrates incremental Doji pattern calculation using a buffer-style `List` for streaming scenarios without a hub. Add bars to the list as they become available. ```csharp DojiList dojiList = new(maxPriceChangePercent); foreach (IBar bar in bars) // simulating stream { dojiList.Add(bar); } // based on `ICollection` IReadOnlyList results = dojiList; ``` -------------------------------- ### Streaming SMA Calculation with Buffer List Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/sma.md Provides an example of incremental SMA calculations using a buffer-style `SmaList` in C#. This is suitable for scenarios without a hub. ```csharp SmaList smaList = new(lookbackPeriods); foreach (IBar bar in bars) // simulating stream { smaList.Add(bar); } // based on `ICollection` IReadOnlyList results = smaList; ``` -------------------------------- ### Chaining Gator Oscillator Calculation Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/gator.md Example of chaining the Gator Oscillator calculation after using a specific candle part (HLC3). Note that Gator results cannot be further chained. ```csharp var results = bars .Use(CandlePart.HLC3) .ToGator(); ``` -------------------------------- ### Implement Custom Indicator Logic Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/guide/customization.md Create a static extension method for IReadOnlyList to calculate your custom indicator. This example calculates an ATR-weighted moving average. ```csharp using FacioQuo.Stock.Indicators; namespace Custom.Indicators; public static class CustomIndicators { /// /// ATR-weighted moving average (custom indicator example) /// /// Historical price bars /// Lookback period /// Collection of AtrWmaResult public static IReadOnlyList ToAtrWma( this IReadOnlyList bars, int lookbackPeriods = 10) { // Validate parameters ArgumentNullException.ThrowIfNull(bars); if (lookbackPeriods <= 0) { throw new ArgumentOutOfRangeException( nameof(lookbackPeriods), "Lookback periods must be greater than 0."); } // Sort bars IReadOnlyList barsList = bars.ToSortedList(); // Check for sufficient bars if (barsList.Count < lookbackPeriods) { return []; } // Initialize results List results = new(barsList.Count); // Get ATR values (prerequisite indicator) IReadOnlyList atrResults = barsList.ToAtr(lookbackPeriods); // Calculate custom indicator for (int i = 0; i < barsList.Count; i++) { IBar q = barsList[i]; AtrWmaResult r = new() { Timestamp = q.Timestamp }; // Calculate only after warmup period if (i >= lookbackPeriods - 1) { double sumWma = 0; double sumAtr = 0; for (int p = i - lookbackPeriods + 1; p <= i; p++) { double close = (double)barsList[p].Close; double? atr = atrResults[p].Atr; if (atr.HasValue) { sumWma += atr.Value * close; sumAtr += atr.Value; } } r = r with { AtrWma = sumAtr != 0 ? sumWma / sumAtr : null }; } results.Add(r); } return results; } } ``` -------------------------------- ### Run Unit Tests with Settings File Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/tests/indicators/README.md Execute unit tests specifically using a .runsettings file for isolation. This is recommended for local development efficiency in IDEs. ```bash dotnet test --settings tests/tests.unit.runsettings ``` -------------------------------- ### Configuring BarHub Cache Size Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/guide/styles/stream.md Demonstrates creating a BarHub with the default maximum cache size and with a custom maximum cache size. Shows how a derived hub like SmaHub inherits this configuration and how new bars trigger automatic pruning when the limit is reached. ```csharp // default max cache size (100,000 items) BarHub barHub = new(); // or configure custom max cache size BarHub limitedHub = new(maxCacheSize: 500); // automatic FIFO pruning when limit reached SmaHub smaHub = limitedHub.ToSmaHub(20); // as new bars arrive, oldest results are removed automatically foreach (Bar bar in liveBars) { limitedHub.Add(bar); // oldest pruned if over limit } ``` -------------------------------- ### Filtering Pivots Results Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/pivots.md Examples of how to filter the results from the Pivots indicator to extract specific data points like pivot points, trend lines, or recent periods. ```APIDOC ## Filtering results Since this method returns one result per input bar (with `null` values where no pivot exists), you'll often want to filter results for specific use cases: ```csharp // get only records with pivot points var pivotsOnly = results.Condense(); // get only records with trend lines var trendsOnly = results .Where(x => x.HighTrend != null || x.LowTrend != null); // get only recent N periods var recentPivots = results.TakeLast(period); // get only high pivot points with Higher High trend var higherHighs = results .Where(x => x.HighPoint != null && x.HighTrend == PivotTrend.Hh); // combine filters: recent periods with trends var recentTrends = results .Where(x => x.HighTrend != null || x.LowTrend != null) .TakeLast(period); ``` ``` -------------------------------- ### Streaming MFI Calculation Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/mfi.md Demonstrates how to perform incremental MFI calculations using a buffer list. This is useful for real-time data streams where a full recalculation on each new bar is inefficient. ```csharp MfiList mfiList = new(lookbackPeriods); foreach (IBar bar in bars) // simulating stream { mfiList.Add(bar); } // based on `ICollection` IReadOnlyList results = mfiList; ``` -------------------------------- ### Chaining SMI with Slope Indicator Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/docs/indicators/smi.md Example of chaining the SMI indicator with the Slope indicator. Note that SMI must be generated from raw bars and cannot be chained from other indicator results. ```csharp // example var results = bars .ToSmi(..) .ToSlope(..); ``` -------------------------------- ### Run All Quality Gates Source: https://github.com/facioquo/stock-indicators-dotnet/blob/main/AGENTS.md Executes a sequence of commands for all quality gates, including formatting, building, testing, and Markdown linting. ```bash dotnet format --no-restore && dotnet build && dotnet test --no-restore && npx markdownlint-cli2 ```