mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-18 18:48:05 +00:00
docs
This commit is contained in:
+64
-64
@@ -51,70 +51,6 @@ For the calculation, we use a **RingBuffer** to store the price window. The weig
|
||||
|
||||
**Configuration note:** The default combination (Period 9, Offset 0.85, Sigma 6) is widely used as a responsive trend filter.
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
var alma = new Alma(period: 9, offset: 0.85, sigma: 6.0);
|
||||
|
||||
// Process each new bar
|
||||
TValue result = alma.Update(new TValue(timestamp, closePrice));
|
||||
Console.WriteLine($"ALMA: {result.Value:F2}");
|
||||
|
||||
// Check if buffer is full
|
||||
if (alma.IsHot)
|
||||
{
|
||||
// Indicator is fully initialized
|
||||
}
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TSeries API (object-oriented)
|
||||
TSeries prices = ...;
|
||||
TSeries almaValues = Alma.Batch(prices, period: 9, offset: 0.85, sigma: 6.0);
|
||||
|
||||
// High-performance Span API (zero allocation)
|
||||
double[] prices = new double[10000];
|
||||
double[] output = new double[10000];
|
||||
Alma.Calculate(prices.AsSpan(), output.AsSpan(), period: 9, offset: 0.85, sigma: 6.0);
|
||||
```
|
||||
|
||||
### Bar Correction (isNew Parameter)
|
||||
|
||||
```csharp
|
||||
var alma = new Alma(9);
|
||||
|
||||
// New bar arrives
|
||||
alma.Update(new TValue(time, 100.5), isNew: true);
|
||||
|
||||
// Intra-bar price updates (real-time tick data)
|
||||
alma.Update(new TValue(time, 101.0), isNew: false); // Updates current bar
|
||||
alma.Update(new TValue(time, 100.8), isNew: false); // Updates current bar
|
||||
|
||||
// Next bar
|
||||
alma.Update(new TValue(time + 60, 101.2), isNew: true); // Advances state
|
||||
```
|
||||
|
||||
### Event-Driven Architecture
|
||||
|
||||
```csharp
|
||||
var source = new TSeries();
|
||||
var alma = new Alma(source, period: 9);
|
||||
|
||||
// Subscribe to ALMA output
|
||||
alma.Pub += (value) => {
|
||||
Console.WriteLine($"New ALMA value: {value.Value}");
|
||||
};
|
||||
|
||||
// Feeding source automatically triggers the chain
|
||||
source.Add(new TValue(DateTime.Now, 105.2));
|
||||
```
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
@@ -201,3 +137,67 @@ This implementation makes specific trade-offs:
|
||||
## References
|
||||
|
||||
- Legoux, Arnaud. "ALMA: Arnaud Legoux Moving Average."
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
var alma = new Alma(period: 9, offset: 0.85, sigma: 6.0);
|
||||
|
||||
// Process each new bar
|
||||
TValue result = alma.Update(new TValue(timestamp, closePrice));
|
||||
Console.WriteLine($"ALMA: {result.Value:F2}");
|
||||
|
||||
// Check if buffer is full
|
||||
if (alma.IsHot)
|
||||
{
|
||||
// Indicator is fully initialized
|
||||
}
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TSeries API (object-oriented)
|
||||
TSeries prices = ...;
|
||||
TSeries almaValues = Alma.Batch(prices, period: 9, offset: 0.85, sigma: 6.0);
|
||||
|
||||
// High-performance Span API (zero allocation)
|
||||
double[] prices = new double[10000];
|
||||
double[] output = new double[10000];
|
||||
Alma.Calculate(prices.AsSpan(), output.AsSpan(), period: 9, offset: 0.85, sigma: 6.0);
|
||||
```
|
||||
|
||||
### Bar Correction (isNew Parameter)
|
||||
|
||||
```csharp
|
||||
var alma = new Alma(9);
|
||||
|
||||
// New bar arrives
|
||||
alma.Update(new TValue(time, 100.5), isNew: true);
|
||||
|
||||
// Intra-bar price updates (real-time tick data)
|
||||
alma.Update(new TValue(time, 101.0), isNew: false); // Updates current bar
|
||||
alma.Update(new TValue(time, 100.8), isNew: false); // Updates current bar
|
||||
|
||||
// Next bar
|
||||
alma.Update(new TValue(time + 60, 101.2), isNew: true); // Advances state
|
||||
```
|
||||
|
||||
### Event-Driven Architecture
|
||||
|
||||
```csharp
|
||||
var source = new TSeries();
|
||||
var alma = new Alma(source, period: 9);
|
||||
|
||||
// Subscribe to ALMA output
|
||||
alma.Pub += (value) => {
|
||||
Console.WriteLine($"New ALMA value: {value.Value}");
|
||||
};
|
||||
|
||||
// Feeding source automatically triggers the chain
|
||||
source.Add(new TValue(DateTime.Now, 105.2));
|
||||
```
|
||||
|
||||
+43
-43
@@ -42,49 +42,6 @@ The `Conv` indicator uses a **RingBuffer** to store the price history efficientl
|
||||
|
||||
**Note:** The kernel is not automatically normalized. If you want a moving average that tracks price levels, the sum of your kernel weights should equal 1.0. If the sum is 0 (e.g., `[-1, 1]`), it will act as an oscillator.
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
// Create a custom kernel (e.g., a 3-period weighted average)
|
||||
double[] weights = { 0.1, 0.3, 0.6 };
|
||||
var conv = new Conv(weights);
|
||||
|
||||
// Process each new bar
|
||||
TValue result = conv.Update(new TValue(timestamp, closePrice));
|
||||
Console.WriteLine($"Conv: {result.Value:F2}");
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TSeries API
|
||||
TSeries prices = ...;
|
||||
double[] kernel = { 0.2, 0.2, 0.2, 0.2, 0.2 }; // 5-period SMA
|
||||
TSeries sma5 = Conv.Batch(prices, kernel);
|
||||
|
||||
// Span API (High Performance)
|
||||
double[] prices = new double[1000];
|
||||
double[] output = new double[1000];
|
||||
double[] edgeDetector = { -1, 1 }; // Simple difference
|
||||
Conv.Batch(prices.AsSpan(), output.AsSpan(), edgeDetector);
|
||||
```
|
||||
|
||||
### Bar Correction (isNew Parameter)
|
||||
|
||||
```csharp
|
||||
var conv = new Conv(new[] { 0.5, 0.5 });
|
||||
|
||||
// New bar
|
||||
conv.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
conv.Update(new TValue(time, 101), isNew: false); // Replaces 100 with 101
|
||||
```
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
@@ -129,3 +86,46 @@ This implementation makes specific trade-offs:
|
||||
|
||||
- Smith, Steven W. "The Scientist and Engineer's Guide to Digital Signal Processing." California Technical Publishing, 1997.
|
||||
- Ehlers, John F. "Cycle Analytics for Traders." Wiley, 2013.
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
// Create a custom kernel (e.g., a 3-period weighted average)
|
||||
double[] weights = { 0.1, 0.3, 0.6 };
|
||||
var conv = new Conv(weights);
|
||||
|
||||
// Process each new bar
|
||||
TValue result = conv.Update(new TValue(timestamp, closePrice));
|
||||
Console.WriteLine($"Conv: {result.Value:F2}");
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TSeries API
|
||||
TSeries prices = ...;
|
||||
double[] kernel = { 0.2, 0.2, 0.2, 0.2, 0.2 }; // 5-period SMA
|
||||
TSeries sma5 = Conv.Batch(prices, kernel);
|
||||
|
||||
// Span API (High Performance)
|
||||
double[] prices = new double[1000];
|
||||
double[] output = new double[1000];
|
||||
double[] edgeDetector = { -1, 1 }; // Simple difference
|
||||
Conv.Batch(prices.AsSpan(), output.AsSpan(), edgeDetector);
|
||||
```
|
||||
|
||||
### Bar Correction (isNew Parameter)
|
||||
|
||||
```csharp
|
||||
var conv = new Conv(new[] { 0.5, 0.5 });
|
||||
|
||||
// New bar
|
||||
conv.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
conv.Update(new TValue(time, 101), isNew: false); // Replaces 100 with 101
|
||||
```
|
||||
|
||||
+45
-45
@@ -43,51 +43,6 @@ Our implementation uses a zero-lag initialization technique for the internal EMA
|
||||
|
||||
**Configuration note:** Because DEMA is faster than EMA, you may need to use a slightly longer period (e.g., 14 instead of 10) to get comparable smoothness with better responsiveness.
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
var dema = new Dema(period: 10);
|
||||
|
||||
// Process each new bar
|
||||
TValue result = dema.Update(new TValue(timestamp, closePrice));
|
||||
Console.WriteLine($"DEMA: {result.Value:F2}");
|
||||
|
||||
// Check if buffer is full
|
||||
if (dema.IsHot)
|
||||
{
|
||||
// Indicator is fully initialized
|
||||
}
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TSeries API
|
||||
TSeries prices = ...;
|
||||
TSeries demaValues = Dema.Calculate(prices, period: 10);
|
||||
|
||||
// Span API (High Performance)
|
||||
double[] prices = new double[1000];
|
||||
double[] output = new double[1000];
|
||||
Dema.Calculate(prices.AsSpan(), output.AsSpan(), period: 10);
|
||||
```
|
||||
|
||||
### Bar Correction (isNew Parameter)
|
||||
|
||||
```csharp
|
||||
var dema = new Dema(10);
|
||||
|
||||
// New bar
|
||||
dema.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
dema.Update(new TValue(time, 101), isNew: false); // Replaces 100 with 101
|
||||
```
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
@@ -151,3 +106,48 @@ This implementation makes specific trade-offs:
|
||||
## References
|
||||
|
||||
- Mulloy, Patrick G. "Smoothing Data With Faster Moving Averages." Technical Analysis of Stocks & Commodities, Jan. 1994.
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
var dema = new Dema(period: 10);
|
||||
|
||||
// Process each new bar
|
||||
TValue result = dema.Update(new TValue(timestamp, closePrice));
|
||||
Console.WriteLine($"DEMA: {result.Value:F2}");
|
||||
|
||||
// Check if buffer is full
|
||||
if (dema.IsHot)
|
||||
{
|
||||
// Indicator is fully initialized
|
||||
}
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TSeries API
|
||||
TSeries prices = ...;
|
||||
TSeries demaValues = Dema.Calculate(prices, period: 10);
|
||||
|
||||
// Span API (High Performance)
|
||||
double[] prices = new double[1000];
|
||||
double[] output = new double[1000];
|
||||
Dema.Calculate(prices.AsSpan(), output.AsSpan(), period: 10);
|
||||
```
|
||||
|
||||
### Bar Correction (isNew Parameter)
|
||||
|
||||
```csharp
|
||||
var dema = new Dema(10);
|
||||
|
||||
// New bar
|
||||
dema.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
dema.Update(new TValue(time, 101), isNew: false); // Replaces 100 with 101
|
||||
```
|
||||
|
||||
+45
-45
@@ -42,51 +42,6 @@ Our implementation wraps two instances of the `Wma` class.
|
||||
|
||||
**Configuration note:** A DWMA(10) will have roughly the same lag as a WMA(15-20) but will be significantly smoother.
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
var dwma = new Dwma(period: 14);
|
||||
|
||||
// Process each new bar
|
||||
TValue result = dwma.Update(new TValue(timestamp, closePrice));
|
||||
Console.WriteLine($"DWMA: {result.Value:F2}");
|
||||
|
||||
// Check if buffer is full
|
||||
if (dwma.IsHot)
|
||||
{
|
||||
// Indicator is fully initialized
|
||||
}
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TSeries API
|
||||
TSeries prices = ...;
|
||||
TSeries dwmaValues = Dwma.Batch(prices, period: 14);
|
||||
|
||||
// Span API (High Performance)
|
||||
double[] prices = new double[1000];
|
||||
double[] output = new double[1000];
|
||||
Dwma.Calculate(prices.AsSpan(), output.AsSpan(), period: 14);
|
||||
```
|
||||
|
||||
### Bar Correction (isNew Parameter)
|
||||
|
||||
```csharp
|
||||
var dwma = new Dwma(14);
|
||||
|
||||
// New bar
|
||||
dwma.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
dwma.Update(new TValue(time, 101), isNew: false); // Replaces 100 with 101
|
||||
```
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
@@ -150,3 +105,48 @@ This implementation makes specific trade-offs:
|
||||
## References
|
||||
|
||||
- Kaufman, Perry J. "Trading Systems and Methods." Wiley, 2013.
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
var dwma = new Dwma(period: 14);
|
||||
|
||||
// Process each new bar
|
||||
TValue result = dwma.Update(new TValue(timestamp, closePrice));
|
||||
Console.WriteLine($"DWMA: {result.Value:F2}");
|
||||
|
||||
// Check if buffer is full
|
||||
if (dwma.IsHot)
|
||||
{
|
||||
// Indicator is fully initialized
|
||||
}
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TSeries API
|
||||
TSeries prices = ...;
|
||||
TSeries dwmaValues = Dwma.Batch(prices, period: 14);
|
||||
|
||||
// Span API (High Performance)
|
||||
double[] prices = new double[1000];
|
||||
double[] output = new double[1000];
|
||||
Dwma.Calculate(prices.AsSpan(), output.AsSpan(), period: 14);
|
||||
```
|
||||
|
||||
### Bar Correction (isNew Parameter)
|
||||
|
||||
```csharp
|
||||
var dwma = new Dwma(14);
|
||||
|
||||
// New bar
|
||||
dwma.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
dwma.Update(new TValue(time, 101), isNew: false); // Replaces 100 with 101
|
||||
```
|
||||
|
||||
+45
-45
@@ -60,51 +60,6 @@ Standard EMAs usually start at 0 or the first price, requiring a long "warmup" p
|
||||
|
||||
**Configuration note:** The 200-day EMA is a standard institutional benchmark for long-term trend direction.
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
var ema = new Ema(period: 14);
|
||||
|
||||
// Process each new bar
|
||||
TValue result = ema.Update(new TValue(timestamp, closePrice));
|
||||
Console.WriteLine($"EMA: {result.Value:F2}");
|
||||
|
||||
// Check if buffer is full
|
||||
if (ema.IsHot)
|
||||
{
|
||||
// Indicator is fully initialized
|
||||
}
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TSeries API
|
||||
TSeries prices = ...;
|
||||
TSeries emaValues = Ema.Batch(prices, period: 14);
|
||||
|
||||
// Span API (High Performance)
|
||||
double[] prices = new double[1000];
|
||||
double[] output = new double[1000];
|
||||
Ema.Batch(prices.AsSpan(), output.AsSpan(), period: 14);
|
||||
```
|
||||
|
||||
### Bar Correction (isNew Parameter)
|
||||
|
||||
```csharp
|
||||
var ema = new Ema(14);
|
||||
|
||||
// New bar
|
||||
ema.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
ema.Update(new TValue(time, 101), isNew: false); // Replaces 100 with 101
|
||||
```
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
@@ -176,3 +131,48 @@ This implementation makes specific trade-offs:
|
||||
|
||||
- Brown, Robert G. "Statistical Forecasting for Inventory Control." McGraw-Hill, 1959.
|
||||
- Appel, Gerald. "Technical Analysis: Power Tools for Active Investors." FT Press, 2005.
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
var ema = new Ema(period: 14);
|
||||
|
||||
// Process each new bar
|
||||
TValue result = ema.Update(new TValue(timestamp, closePrice));
|
||||
Console.WriteLine($"EMA: {result.Value:F2}");
|
||||
|
||||
// Check if buffer is full
|
||||
if (ema.IsHot)
|
||||
{
|
||||
// Indicator is fully initialized
|
||||
}
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TSeries API
|
||||
TSeries prices = ...;
|
||||
TSeries emaValues = Ema.Batch(prices, period: 14);
|
||||
|
||||
// Span API (High Performance)
|
||||
double[] prices = new double[1000];
|
||||
double[] output = new double[1000];
|
||||
Ema.Batch(prices.AsSpan(), output.AsSpan(), period: 14);
|
||||
```
|
||||
|
||||
### Bar Correction (isNew Parameter)
|
||||
|
||||
```csharp
|
||||
var ema = new Ema(14);
|
||||
|
||||
// New bar
|
||||
ema.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
ema.Update(new TValue(time, 101), isNew: false); // Replaces 100 with 101
|
||||
```
|
||||
|
||||
+45
-45
@@ -48,51 +48,6 @@ Our implementation orchestrates three internal `Wma` instances.
|
||||
|
||||
**Configuration note:** HMA is significantly faster than SMA or EMA. An HMA(20) is often faster than an EMA(10).
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
var hma = new Hma(period: 14);
|
||||
|
||||
// Process each new bar
|
||||
TValue result = hma.Update(new TValue(timestamp, closePrice));
|
||||
Console.WriteLine($"HMA: {result.Value:F2}");
|
||||
|
||||
// Check if buffer is full
|
||||
if (hma.IsHot)
|
||||
{
|
||||
// Indicator is fully initialized
|
||||
}
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TSeries API
|
||||
TSeries prices = ...;
|
||||
TSeries hmaValues = Hma.Batch(prices, period: 14);
|
||||
|
||||
// Span API (High Performance)
|
||||
double[] prices = new double[1000];
|
||||
double[] output = new double[1000];
|
||||
Hma.Calculate(prices.AsSpan(), output.AsSpan(), period: 14);
|
||||
```
|
||||
|
||||
### Bar Correction (isNew Parameter)
|
||||
|
||||
```csharp
|
||||
var hma = new Hma(14);
|
||||
|
||||
// New bar
|
||||
hma.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
hma.Update(new TValue(time, 101), isNew: false); // Replaces 100 with 101
|
||||
```
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
@@ -154,3 +109,48 @@ This implementation makes specific trade-offs:
|
||||
|
||||
- Hull, Alan. "Active Investing." Wrightbooks, 2005.
|
||||
- [Alan Hull's Official HMA Description](https://alan.hull.com.au/hma.html)
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
var hma = new Hma(period: 14);
|
||||
|
||||
// Process each new bar
|
||||
TValue result = hma.Update(new TValue(timestamp, closePrice));
|
||||
Console.WriteLine($"HMA: {result.Value:F2}");
|
||||
|
||||
// Check if buffer is full
|
||||
if (hma.IsHot)
|
||||
{
|
||||
// Indicator is fully initialized
|
||||
}
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TSeries API
|
||||
TSeries prices = ...;
|
||||
TSeries hmaValues = Hma.Batch(prices, period: 14);
|
||||
|
||||
// Span API (High Performance)
|
||||
double[] prices = new double[1000];
|
||||
double[] output = new double[1000];
|
||||
Hma.Calculate(prices.AsSpan(), output.AsSpan(), period: 14);
|
||||
```
|
||||
|
||||
### Bar Correction (isNew Parameter)
|
||||
|
||||
```csharp
|
||||
var hma = new Hma(14);
|
||||
|
||||
// New bar
|
||||
hma.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
hma.Update(new TValue(time, 101), isNew: false); // Replaces 100 with 101
|
||||
```
|
||||
|
||||
+45
-45
@@ -42,51 +42,6 @@ Our implementation follows Ehlers' original code structure but optimized for C#.
|
||||
|
||||
**Configuration note:** The lack of parameters is a feature, not a bug. It prevents "curve fitting" and ensures the indicator relies on measured market properties rather than user guesses.
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
var htit = new Htit();
|
||||
|
||||
// Process each new bar
|
||||
TValue result = htit.Update(new TValue(timestamp, closePrice));
|
||||
Console.WriteLine($"HTIT: {result.Value:F2}");
|
||||
|
||||
// Check if buffer is full (requires some history to establish cycle)
|
||||
if (htit.IsHot)
|
||||
{
|
||||
// Indicator is fully initialized
|
||||
}
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TSeries API
|
||||
TSeries prices = ...;
|
||||
TSeries htitValues = Htit.Batch(prices);
|
||||
|
||||
// Span API (High Performance)
|
||||
double[] prices = new double[1000];
|
||||
double[] output = new double[1000];
|
||||
Htit.Batch(prices.AsSpan(), output.AsSpan());
|
||||
```
|
||||
|
||||
### Bar Correction (isNew Parameter)
|
||||
|
||||
```csharp
|
||||
var htit = new Htit();
|
||||
|
||||
// New bar
|
||||
htit.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
htit.Update(new TValue(time, 101), isNew: false); // Replaces 100 with 101
|
||||
```
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
@@ -138,3 +93,48 @@ This implementation makes specific trade-offs:
|
||||
|
||||
- Ehlers, John F. "Rocket Science for Traders: Digital Signal Processing Applications." Wiley, 2001.
|
||||
- Ehlers, John F. "Cybernetic Analysis for Stocks and Futures." Wiley, 2004.
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
var htit = new Htit();
|
||||
|
||||
// Process each new bar
|
||||
TValue result = htit.Update(new TValue(timestamp, closePrice));
|
||||
Console.WriteLine($"HTIT: {result.Value:F2}");
|
||||
|
||||
// Check if buffer is full (requires some history to establish cycle)
|
||||
if (htit.IsHot)
|
||||
{
|
||||
// Indicator is fully initialized
|
||||
}
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TSeries API
|
||||
TSeries prices = ...;
|
||||
TSeries htitValues = Htit.Batch(prices);
|
||||
|
||||
// Span API (High Performance)
|
||||
double[] prices = new double[1000];
|
||||
double[] output = new double[1000];
|
||||
Htit.Batch(prices.AsSpan(), output.AsSpan());
|
||||
```
|
||||
|
||||
### Bar Correction (isNew Parameter)
|
||||
|
||||
```csharp
|
||||
var htit = new Htit();
|
||||
|
||||
// New bar
|
||||
htit.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
htit.Update(new TValue(time, 101), isNew: false); // Replaces 100 with 101
|
||||
```
|
||||
|
||||
+45
-45
@@ -47,51 +47,6 @@ Our implementation is optimized for performance:
|
||||
|
||||
**Configuration note:** The `Phase` parameter is unique to JMA. A phase of 100 makes it act like a TEMA (very fast, some overshoot), while -100 makes it act like a Gaussian filter (no overshoot, more lag). 0 is the optimal balance.
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
var jma = new Jma(period: 10, phase: 0);
|
||||
|
||||
// Process each new bar
|
||||
TValue result = jma.Update(new TValue(timestamp, closePrice));
|
||||
Console.WriteLine($"JMA: {result.Value:F2}");
|
||||
|
||||
// Check if buffer is full (JMA needs a long warmup)
|
||||
if (jma.IsHot)
|
||||
{
|
||||
// Indicator is fully initialized
|
||||
}
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TSeries API
|
||||
TSeries prices = ...;
|
||||
TSeries jmaValues = Jma.Batch(prices, period: 10, phase: 0);
|
||||
|
||||
// Span API (High Performance)
|
||||
double[] prices = new double[1000];
|
||||
double[] output = new double[1000];
|
||||
Jma.Batch(prices.AsSpan(), output.AsSpan(), period: 10, phase: 0);
|
||||
```
|
||||
|
||||
### Bar Correction (isNew Parameter)
|
||||
|
||||
```csharp
|
||||
var jma = new Jma(10);
|
||||
|
||||
// New bar
|
||||
jma.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
jma.Update(new TValue(time, 101), isNew: false); // Replaces 100 with 101
|
||||
```
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
@@ -146,3 +101,48 @@ This implementation makes specific trade-offs:
|
||||
|
||||
- Jurik, Mark. "Jurik Research." [http://www.jurikres.com/](http://www.jurikres.com/)
|
||||
- "JMA - Jurik Moving Average." Technical Analysis of Stocks & Commodities.
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
var jma = new Jma(period: 10, phase: 0);
|
||||
|
||||
// Process each new bar
|
||||
TValue result = jma.Update(new TValue(timestamp, closePrice));
|
||||
Console.WriteLine($"JMA: {result.Value:F2}");
|
||||
|
||||
// Check if buffer is full (JMA needs a long warmup)
|
||||
if (jma.IsHot)
|
||||
{
|
||||
// Indicator is fully initialized
|
||||
}
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TSeries API
|
||||
TSeries prices = ...;
|
||||
TSeries jmaValues = Jma.Batch(prices, period: 10, phase: 0);
|
||||
|
||||
// Span API (High Performance)
|
||||
double[] prices = new double[1000];
|
||||
double[] output = new double[1000];
|
||||
Jma.Batch(prices.AsSpan(), output.AsSpan(), period: 10, phase: 0);
|
||||
```
|
||||
|
||||
### Bar Correction (isNew Parameter)
|
||||
|
||||
```csharp
|
||||
var jma = new Jma(10);
|
||||
|
||||
// New bar
|
||||
jma.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
jma.Update(new TValue(time, 101), isNew: false); // Replaces 100 with 101
|
||||
```
|
||||
|
||||
+45
-45
@@ -50,51 +50,6 @@ Our implementation is fully optimized for O(1) updates.
|
||||
|
||||
**Configuration note:** The default settings (10, 2, 30) are widely used and robust. Adjusting the Slow Period to 80 or 100 can create an extremely stable filter for long-term trend following.
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
var kama = new Kama(period: 10, fastPeriod: 2, slowPeriod: 30);
|
||||
|
||||
// Process each new bar
|
||||
TValue result = kama.Update(new TValue(timestamp, closePrice));
|
||||
Console.WriteLine($"KAMA: {result.Value:F2}");
|
||||
|
||||
// Check if buffer is full
|
||||
if (kama.IsHot)
|
||||
{
|
||||
// Indicator is fully initialized
|
||||
}
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TSeries API
|
||||
TSeries prices = ...;
|
||||
TSeries kamaValues = Kama.Batch(prices, period: 10);
|
||||
|
||||
// Span API (High Performance)
|
||||
double[] prices = new double[1000];
|
||||
double[] output = new double[1000];
|
||||
Kama.Batch(prices.AsSpan(), output.AsSpan(), period: 10, fastPeriod: 2, slowPeriod: 30);
|
||||
```
|
||||
|
||||
### Bar Correction (isNew Parameter)
|
||||
|
||||
```csharp
|
||||
var kama = new Kama(10);
|
||||
|
||||
// New bar
|
||||
kama.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
kama.Update(new TValue(time, 101), isNew: false); // Replaces 100 with 101
|
||||
```
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
@@ -140,3 +95,48 @@ This implementation makes specific trade-offs:
|
||||
|
||||
- Kaufman, Perry J. "Smarter Trading: Improving Performance in Changing Markets." McGraw-Hill, 1995.
|
||||
- Kaufman, Perry J. "Trading Systems and Methods." Wiley, 2013.
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
var kama = new Kama(period: 10, fastPeriod: 2, slowPeriod: 30);
|
||||
|
||||
// Process each new bar
|
||||
TValue result = kama.Update(new TValue(timestamp, closePrice));
|
||||
Console.WriteLine($"KAMA: {result.Value:F2}");
|
||||
|
||||
// Check if buffer is full
|
||||
if (kama.IsHot)
|
||||
{
|
||||
// Indicator is fully initialized
|
||||
}
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TSeries API
|
||||
TSeries prices = ...;
|
||||
TSeries kamaValues = Kama.Batch(prices, period: 10);
|
||||
|
||||
// Span API (High Performance)
|
||||
double[] prices = new double[1000];
|
||||
double[] output = new double[1000];
|
||||
Kama.Batch(prices.AsSpan(), output.AsSpan(), period: 10, fastPeriod: 2, slowPeriod: 30);
|
||||
```
|
||||
|
||||
### Bar Correction (isNew Parameter)
|
||||
|
||||
```csharp
|
||||
var kama = new Kama(10);
|
||||
|
||||
// New bar
|
||||
kama.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
kama.Update(new TValue(time, 101), isNew: false); // Replaces 100 with 101
|
||||
```
|
||||
|
||||
+53
-53
@@ -56,6 +56,59 @@ This allows the LSMA to update in constant time regardless of the period length.
|
||||
| Offset | 0 | Projection shift | 0 = current bar; >0 projects future; <0 retrieves past regression value |
|
||||
| Source | Close | Price input | Can be applied to any data series |
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
|-----------|------------|-------------------|
|
||||
| Streaming update | O(1) | Constant time regression update |
|
||||
| Bar correction | O(1) | Efficient state rollback for real-time feeds |
|
||||
| Batch processing | O(n) | Fast sequential processing |
|
||||
| Memory footprint | O(period) | Uses a RingBuffer to store the lookback window |
|
||||
|
||||
## Interpretation
|
||||
|
||||
### Trading Signals
|
||||
|
||||
#### Trend Direction
|
||||
|
||||
- **Bullish:** LSMA is rising and price is above LSMA.
|
||||
- **Bearish:** LSMA is falling and price is below LSMA.
|
||||
|
||||
#### Crossovers
|
||||
|
||||
- **Price Crossover:** Price crossing the LSMA line is often used as a signal of trend change.
|
||||
- **Slope Change:** A change in the slope of the LSMA (e.g., from positive to negative) indicates a potential reversal.
|
||||
|
||||
### When It Works Best
|
||||
|
||||
- **Trending Markets:** LSMA provides a smooth, responsive trend line that hugs price action closer than SMA.
|
||||
- **Reversals:** Due to its regression nature, it can identify turning points relatively quickly.
|
||||
|
||||
### When It Struggles
|
||||
|
||||
- **Sideways Markets:** Like other moving averages, it can produce whipsaws in ranging conditions, though the regression fit may offer slightly better noise filtering than a raw SMA.
|
||||
|
||||
### Architecture Notes
|
||||
|
||||
This implementation makes specific trade-offs:
|
||||
|
||||
### Choice: O(1) Regression Update
|
||||
|
||||
- **Alternative:** Recalculate regression sums every bar (O(n)).
|
||||
- **Trade-off:** Requires maintaining running sums for $\sum y$ and $\sum xy$.
|
||||
- **Rationale:** Essential for performance when using long periods or processing high-frequency data.
|
||||
|
||||
### Choice: Periodic Resync
|
||||
|
||||
- **Alternative:** Rely solely on incremental updates.
|
||||
- **Trade-off:** Small CPU cost every 1,000 ticks.
|
||||
- **Rationale:** Prevents floating-point error accumulation in the $\sum xy$ term, ensuring long-term accuracy.
|
||||
|
||||
## References
|
||||
|
||||
- [Linear Regression in Technical Analysis](https://www.investopedia.com/terms/l/linearregression.asp)
|
||||
- [Least Squares Moving Average](https://www.tradingview.com/support/solutions/43000502584-least-squares-moving-average-lsma/)
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
@@ -129,56 +182,3 @@ lsma.Update(new TValue(time, 100));
|
||||
lsma.Update(new TValue(time, double.NaN)); // Uses last valid value (100)
|
||||
lsma.Update(new TValue(time, 110)); // Resumes normal calculation
|
||||
```
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
|-----------|------------|-------------------|
|
||||
| Streaming update | O(1) | Constant time regression update |
|
||||
| Bar correction | O(1) | Efficient state rollback for real-time feeds |
|
||||
| Batch processing | O(n) | Fast sequential processing |
|
||||
| Memory footprint | O(period) | Uses a RingBuffer to store the lookback window |
|
||||
|
||||
## Interpretation
|
||||
|
||||
### Trading Signals
|
||||
|
||||
#### Trend Direction
|
||||
|
||||
- **Bullish:** LSMA is rising and price is above LSMA.
|
||||
- **Bearish:** LSMA is falling and price is below LSMA.
|
||||
|
||||
#### Crossovers
|
||||
|
||||
- **Price Crossover:** Price crossing the LSMA line is often used as a signal of trend change.
|
||||
- **Slope Change:** A change in the slope of the LSMA (e.g., from positive to negative) indicates a potential reversal.
|
||||
|
||||
### When It Works Best
|
||||
|
||||
- **Trending Markets:** LSMA provides a smooth, responsive trend line that hugs price action closer than SMA.
|
||||
- **Reversals:** Due to its regression nature, it can identify turning points relatively quickly.
|
||||
|
||||
### When It Struggles
|
||||
|
||||
- **Sideways Markets:** Like other moving averages, it can produce whipsaws in ranging conditions, though the regression fit may offer slightly better noise filtering than a raw SMA.
|
||||
|
||||
### Architecture Notes
|
||||
|
||||
This implementation makes specific trade-offs:
|
||||
|
||||
### Choice: O(1) Regression Update
|
||||
|
||||
- **Alternative:** Recalculate regression sums every bar (O(n)).
|
||||
- **Trade-off:** Requires maintaining running sums for $\sum y$ and $\sum xy$.
|
||||
- **Rationale:** Essential for performance when using long periods or processing high-frequency data.
|
||||
|
||||
### Choice: Periodic Resync
|
||||
|
||||
- **Alternative:** Rely solely on incremental updates.
|
||||
- **Trade-off:** Small CPU cost every 1,000 ticks.
|
||||
- **Rationale:** Prevents floating-point error accumulation in the $\sum xy$ term, ensuring long-term accuracy.
|
||||
|
||||
## References
|
||||
|
||||
- [Linear Regression in Technical Analysis](https://www.investopedia.com/terms/l/linearregression.asp)
|
||||
- [Least Squares Moving Average](https://www.tradingview.com/support/solutions/43000502584-least-squares-moving-average-lsma/)
|
||||
|
||||
+48
-49
@@ -42,6 +42,54 @@ The implementation uses a Homodyne Discriminator to measure the cycle period and
|
||||
| Fast Limit | 0.5 | Maximum adaptation rate | Controls sensitivity in trending markets. Higher = faster response. |
|
||||
| Slow Limit | 0.05 | Minimum adaptation rate | Controls stability in ranging markets. Lower = smoother. |
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
|-----------|------------|-------------------|
|
||||
| Streaming update | O(1) | Constant time DSP calculation |
|
||||
| Batch processing | O(n) | Fast sequential processing |
|
||||
| Memory footprint | O(1) | Fixed-size RingBuffers (7 elements) |
|
||||
|
||||
## Interpretation
|
||||
|
||||
### Trading Signals
|
||||
|
||||
#### Crossovers
|
||||
|
||||
- **Bullish:** MAMA crosses above FAMA. This typically happens early in a new uptrend.
|
||||
- **Bearish:** MAMA crosses below FAMA. This signals the start of a downtrend.
|
||||
|
||||
#### Trend Strength
|
||||
|
||||
- **Separation:** The distance between MAMA and FAMA indicates the strength of the trend. Wide separation suggests a strong trend; convergence suggests consolidation.
|
||||
|
||||
### When It Works Best
|
||||
|
||||
- **Cycle-to-Trend Transitions:** MAMA excels at identifying when a market breaks out of a cycle into a trend, adapting its speed instantly.
|
||||
|
||||
### When It Struggles
|
||||
|
||||
- **Erratic Volatility:** Extremely noisy markets with no discernible cycle or trend can cause the phase calculation to be erratic, leading to false signals.
|
||||
|
||||
### Architecture Notes
|
||||
|
||||
This implementation makes specific trade-offs:
|
||||
|
||||
### Choice: Fixed-Size Buffers
|
||||
|
||||
- **Implementation:** Uses `RingBuffer` of size 7.
|
||||
- **Rationale:** The Hilbert Transform and smoothing filters used by Ehlers have fixed coefficients requiring exactly 7 historical points. This ensures O(1) memory usage.
|
||||
|
||||
### Choice: Stack Allocation for Batch
|
||||
|
||||
- **Implementation:** Uses `stackalloc` for internal buffers in the static `Calculate` method.
|
||||
- **Rationale:** Eliminates heap allocations during batch processing, maximizing performance for large datasets.
|
||||
|
||||
## References
|
||||
|
||||
- Ehlers, John F. "MESA and Trading Market Cycles." John Wiley & Sons, 2001.
|
||||
- Ehlers, John F. "Cycle Analytics for Traders." John Wiley & Sons, 2013.
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
@@ -90,52 +138,3 @@ mama.Pub += (value) => {
|
||||
|
||||
// Feeding source automatically triggers the chain
|
||||
source.Add(new TValue(DateTime.Now, 105.2));
|
||||
```
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
|-----------|------------|-------------------|
|
||||
| Streaming update | O(1) | Constant time DSP calculation |
|
||||
| Batch processing | O(n) | Fast sequential processing |
|
||||
| Memory footprint | O(1) | Fixed-size RingBuffers (7 elements) |
|
||||
|
||||
## Interpretation
|
||||
|
||||
### Trading Signals
|
||||
|
||||
#### Crossovers
|
||||
|
||||
- **Bullish:** MAMA crosses above FAMA. This typically happens early in a new uptrend.
|
||||
- **Bearish:** MAMA crosses below FAMA. This signals the start of a downtrend.
|
||||
|
||||
#### Trend Strength
|
||||
|
||||
- **Separation:** The distance between MAMA and FAMA indicates the strength of the trend. Wide separation suggests a strong trend; convergence suggests consolidation.
|
||||
|
||||
### When It Works Best
|
||||
|
||||
- **Cycle-to-Trend Transitions:** MAMA excels at identifying when a market breaks out of a cycle into a trend, adapting its speed instantly.
|
||||
|
||||
### When It Struggles
|
||||
|
||||
- **Erratic Volatility:** Extremely noisy markets with no discernible cycle or trend can cause the phase calculation to be erratic, leading to false signals.
|
||||
|
||||
### Architecture Notes
|
||||
|
||||
This implementation makes specific trade-offs:
|
||||
|
||||
### Choice: Fixed-Size Buffers
|
||||
|
||||
- **Implementation:** Uses `RingBuffer` of size 7.
|
||||
- **Rationale:** The Hilbert Transform and smoothing filters used by Ehlers have fixed coefficients requiring exactly 7 historical points. This ensures O(1) memory usage.
|
||||
|
||||
### Choice: Stack Allocation for Batch
|
||||
|
||||
- **Implementation:** Uses `stackalloc` for internal buffers in the static `Calculate` method.
|
||||
- **Rationale:** Eliminates heap allocations during batch processing, maximizing performance for large datasets.
|
||||
|
||||
## References
|
||||
|
||||
- Ehlers, John F. "MESA and Trading Market Cycles." John Wiley & Sons, 2001.
|
||||
- Ehlers, John F. "Cycle Analytics for Traders." John Wiley & Sons, 2013.
|
||||
|
||||
+47
-48
@@ -41,54 +41,6 @@ Where:
|
||||
| Period | 14 | Base lookback window | Standard is 14. Adjust based on the timeframe (e.g., 10 for short-term, 20+ for long-term). |
|
||||
| K | 0.6 | Sensitivity constant | 0.6 (60%) is the standard. Lower values make it more sensitive; higher values make it smoother. |
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
var mgdi = new Mgdi(period: 14, k: 0.6);
|
||||
|
||||
// Process each new bar
|
||||
TValue result = mgdi.Update(new TValue(timestamp, closePrice));
|
||||
Console.WriteLine($"MGDI: {result.Value:F2}");
|
||||
|
||||
// Check if buffer is full
|
||||
if (mgdi.IsHot)
|
||||
{
|
||||
// Indicator is fully initialized
|
||||
}
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TSeries API (object-oriented)
|
||||
TSeries prices = ...;
|
||||
TSeries mgdiValues = Mgdi.Batch(prices, period: 14, k: 0.6);
|
||||
|
||||
// High-performance Span API (zero allocation)
|
||||
double[] prices = new double[10000];
|
||||
double[] output = new double[10000];
|
||||
Mgdi.Calculate(prices.AsSpan(), output.AsSpan(), period: 14, k: 0.6);
|
||||
```
|
||||
|
||||
### Event-Driven Architecture
|
||||
|
||||
```csharp
|
||||
var source = new TSeries();
|
||||
var mgdi = new Mgdi(source, period: 14);
|
||||
|
||||
// Subscribe to MGDI output
|
||||
mgdi.Pub += (value) => {
|
||||
Console.WriteLine($"New MGDI value: {value.Value}");
|
||||
};
|
||||
|
||||
// Feeding source automatically triggers the chain
|
||||
source.Add(new TValue(DateTime.Now, 105.2));
|
||||
```
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
@@ -138,3 +90,50 @@ This implementation makes specific trade-offs:
|
||||
|
||||
- [Investopedia: McGinley Dynamic Indicator](https://www.investopedia.com/terms/m/mcginley-dynamic.asp)
|
||||
- [Stock Indicators for .NET: McGinley Dynamic](https://dotnet.stockindicators.dev/indicators/Dynamic/)
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
var mgdi = new Mgdi(period: 14, k: 0.6);
|
||||
|
||||
// Process each new bar
|
||||
TValue result = mgdi.Update(new TValue(timestamp, closePrice));
|
||||
Console.WriteLine($"MGDI: {result.Value:F2}");
|
||||
|
||||
// Check if buffer is full
|
||||
if (mgdi.IsHot)
|
||||
{
|
||||
// Indicator is fully initialized
|
||||
}
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TSeries API (object-oriented)
|
||||
TSeries prices = ...;
|
||||
TSeries mgdiValues = Mgdi.Batch(prices, period: 14, k: 0.6);
|
||||
|
||||
// High-performance Span API (zero allocation)
|
||||
double[] prices = new double[10000];
|
||||
double[] output = new double[10000];
|
||||
Mgdi.Calculate(prices.AsSpan(), output.AsSpan(), period: 14, k: 0.6);
|
||||
```
|
||||
|
||||
### Event-Driven Architecture
|
||||
|
||||
```csharp
|
||||
var source = new TSeries();
|
||||
var mgdi = new Mgdi(source, period: 14);
|
||||
|
||||
// Subscribe to MGDI output
|
||||
mgdi.Pub += (value) => {
|
||||
Console.WriteLine($"New MGDI value: {value.Value}");
|
||||
};
|
||||
|
||||
// Feeding source automatically triggers the chain
|
||||
source.Add(new TValue(DateTime.Now, 105.2));
|
||||
|
||||
+48
-49
@@ -51,6 +51,54 @@ This allows the indicator to update in constant time, regardless of the period l
|
||||
|-----------|---------|---------|----------------------|
|
||||
| Period | 14 | Lookback window | Shorter (5-10) for momentum; Longer (20+) for trend smoothing. |
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
|-----------|------------|-------------------|
|
||||
| Streaming update | O(1) | Constant time triple-sum update |
|
||||
| Bar correction | O(1) | Efficient state rollback |
|
||||
| Batch processing | O(n) | Fast sequential processing |
|
||||
| Memory footprint | O(period) | Uses a RingBuffer to store the lookback window |
|
||||
|
||||
## Interpretation
|
||||
|
||||
### Trading Signals
|
||||
|
||||
#### Momentum
|
||||
|
||||
- **Rapid Turns:** PWMA is excellent for identifying the exact moment a trend loses momentum, often turning before the price itself peaks or troughs.
|
||||
|
||||
#### Velocity
|
||||
|
||||
- **PWMA - WMA:** Subtracting a WMA from a PWMA of the same period creates a powerful momentum oscillator (Velocity) that is smoother than ROC but with less lag.
|
||||
|
||||
### When It Works Best
|
||||
|
||||
- **Fast Trends:** Markets that move parabolically or have sharp V-bottoms/tops.
|
||||
|
||||
### When It Struggles
|
||||
|
||||
- **Noise:** The extreme sensitivity to recent data means PWMA can be noisy in choppy markets. It is often best used as part of a composite indicator rather than a standalone filter.
|
||||
|
||||
## Architecture Notes
|
||||
|
||||
This implementation makes specific trade-offs:
|
||||
|
||||
### Choice: Triple Running Sums
|
||||
|
||||
- **Implementation:** Maintains S1, S2, and S3.
|
||||
- **Rationale:** Enables O(1) updates. A naive implementation would be O(n), which is unacceptable for large periods or high-frequency trading.
|
||||
|
||||
### Choice: Periodic Resync
|
||||
|
||||
- **Implementation:** Recalculates sums from scratch every 1,000 ticks.
|
||||
- **Rationale:** Floating-point errors accumulate rapidly in the $S3$ term (which involves $n^2$). Periodic resync ensures long-term stability.
|
||||
|
||||
## References
|
||||
|
||||
- Colby, Robert W. "The Encyclopedia of Technical Market Indicators." McGraw-Hill, 2002.
|
||||
- Jurik Research. "Velocity."
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
@@ -113,52 +161,3 @@ pwma.Pub += (value) => {
|
||||
|
||||
// Feeding source automatically triggers the chain
|
||||
source.Add(new TValue(DateTime.Now, 105.2));
|
||||
```
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
|-----------|------------|-------------------|
|
||||
| Streaming update | O(1) | Constant time triple-sum update |
|
||||
| Bar correction | O(1) | Efficient state rollback |
|
||||
| Batch processing | O(n) | Fast sequential processing |
|
||||
| Memory footprint | O(period) | Uses a RingBuffer to store the lookback window |
|
||||
|
||||
## Interpretation
|
||||
|
||||
### Trading Signals
|
||||
|
||||
#### Momentum
|
||||
|
||||
- **Rapid Turns:** PWMA is excellent for identifying the exact moment a trend loses momentum, often turning before the price itself peaks or troughs.
|
||||
|
||||
#### Velocity
|
||||
|
||||
- **PWMA - WMA:** Subtracting a WMA from a PWMA of the same period creates a powerful momentum oscillator (Velocity) that is smoother than ROC but with less lag.
|
||||
|
||||
### When It Works Best
|
||||
|
||||
- **Fast Trends:** Markets that move parabolically or have sharp V-bottoms/tops.
|
||||
|
||||
### When It Struggles
|
||||
|
||||
- **Noise:** The extreme sensitivity to recent data means PWMA can be noisy in choppy markets. It is often best used as part of a composite indicator rather than a standalone filter.
|
||||
|
||||
## Architecture Notes
|
||||
|
||||
This implementation makes specific trade-offs:
|
||||
|
||||
### Choice: Triple Running Sums
|
||||
|
||||
- **Implementation:** Maintains S1, S2, and S3.
|
||||
- **Rationale:** Enables O(1) updates. A naive implementation would be O(n), which is unacceptable for large periods or high-frequency trading.
|
||||
|
||||
### Choice: Periodic Resync
|
||||
|
||||
- **Implementation:** Recalculates sums from scratch every 1,000 ticks.
|
||||
- **Rationale:** Floating-point errors accumulate rapidly in the $S3$ term (which involves $n^2$). Periodic resync ensures long-term stability.
|
||||
|
||||
## References
|
||||
|
||||
- Colby, Robert W. "The Encyclopedia of Technical Market Indicators." McGraw-Hill, 2002.
|
||||
- Jurik Research. "Velocity."
|
||||
|
||||
+39
-40
@@ -44,6 +44,45 @@ Our implementation uses the recursive formula for O(1) updates.
|
||||
|-----------|---------|---------|----------------------|
|
||||
| Period | 14 | Lookback window | Standard is 14 (Wilder's default). |
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
|-----------|------------|-------------------|
|
||||
| Streaming update | O(1) | Simple scalar math |
|
||||
| Bar correction | O(1) | Efficient state rollback |
|
||||
| Batch processing | O(N) | Single pass through data |
|
||||
| Memory footprint | O(1) | Minimal state (previous value only) |
|
||||
|
||||
## Interpretation
|
||||
|
||||
### Trading Signals
|
||||
|
||||
#### Trend Filter
|
||||
|
||||
- **Direction:** Because RMA is slower than EMA, it acts as an excellent long-term trend filter.
|
||||
- **Support/Resistance:** In strong trends, price often respects the RMA line as dynamic support/resistance.
|
||||
|
||||
### When It Works Best
|
||||
|
||||
- **Smoothing Volatility:** RMA is the gold standard for smoothing volatile sub-indicators (like True Range to get ATR) because it doesn't react jerkily to single spikes.
|
||||
|
||||
### When It Struggles
|
||||
|
||||
- **Fast Reversals:** Due to its lag (approx $2N-1$ EMA equivalent), it is too slow for catching rapid market turns.
|
||||
|
||||
## Architecture Notes
|
||||
|
||||
This implementation makes specific trade-offs:
|
||||
|
||||
### Choice: Wilder's Initialization
|
||||
|
||||
- **Implementation:** The first value is the SMA of the first $N$ bars.
|
||||
- **Rationale:** Strict adherence to Wilder's definition ensures values match standard platforms (TradingView, etc.) exactly.
|
||||
|
||||
## References
|
||||
|
||||
- Wilder, J. Welles Jr. "New Concepts in Technical Trading Systems." Trend Research, 1978.
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
@@ -87,43 +126,3 @@ rma.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
rma.Update(new TValue(time, 101), isNew: false); // Replaces 100 with 101
|
||||
```
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
|-----------|------------|-------------------|
|
||||
| Streaming update | O(1) | Simple scalar math |
|
||||
| Bar correction | O(1) | Efficient state rollback |
|
||||
| Batch processing | O(N) | Single pass through data |
|
||||
| Memory footprint | O(1) | Minimal state (previous value only) |
|
||||
|
||||
## Interpretation
|
||||
|
||||
### Trading Signals
|
||||
|
||||
#### Trend Filter
|
||||
|
||||
- **Direction:** Because RMA is slower than EMA, it acts as an excellent long-term trend filter.
|
||||
- **Support/Resistance:** In strong trends, price often respects the RMA line as dynamic support/resistance.
|
||||
|
||||
### When It Works Best
|
||||
|
||||
- **Smoothing Volatility:** RMA is the gold standard for smoothing volatile sub-indicators (like True Range to get ATR) because it doesn't react jerkily to single spikes.
|
||||
|
||||
### When It Struggles
|
||||
|
||||
- **Fast Reversals:** Due to its lag (approx $2N-1$ EMA equivalent), it is too slow for catching rapid market turns.
|
||||
|
||||
## Architecture Notes
|
||||
|
||||
This implementation makes specific trade-offs:
|
||||
|
||||
### Choice: Wilder's Initialization
|
||||
|
||||
- **Implementation:** The first value is the SMA of the first $N$ bars.
|
||||
- **Rationale:** Strict adherence to Wilder's definition ensures values match standard platforms (TradingView, etc.) exactly.
|
||||
|
||||
## References
|
||||
|
||||
- Wilder, J. Welles Jr. "New Concepts in Technical Trading Systems." Trend Research, 1978.
|
||||
|
||||
+44
-45
@@ -38,51 +38,6 @@ This ensures that calculating an SMA(200) takes the exact same amount of CPU tim
|
||||
|-----------|---------|---------|----------------------|
|
||||
| Period | 10 | Lookback window | Short (10-20) for short-term trends; Medium (50) for intermediate; Long (200) for major trends. |
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
var sma = new Sma(period: 20);
|
||||
|
||||
// Process each new bar
|
||||
TValue result = sma.Update(new TValue(timestamp, closePrice));
|
||||
Console.WriteLine($"SMA: {result.Value:F2}");
|
||||
|
||||
// Check if buffer is full
|
||||
if (sma.IsHot)
|
||||
{
|
||||
// Indicator is fully initialized
|
||||
}
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TSeries API
|
||||
TSeries prices = ...;
|
||||
TSeries smaValues = Sma.Batch(prices, period: 20);
|
||||
|
||||
// Span API (High Performance)
|
||||
double[] prices = new double[1000];
|
||||
double[] output = new double[1000];
|
||||
Sma.Calculate(prices.AsSpan(), output.AsSpan(), period: 20);
|
||||
```
|
||||
|
||||
### Bar Correction (isNew Parameter)
|
||||
|
||||
```csharp
|
||||
var sma = new Sma(20);
|
||||
|
||||
// New bar
|
||||
sma.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
sma.Update(new TValue(time, 101), isNew: false); // Replaces 100 with 101
|
||||
```
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
@@ -135,3 +90,47 @@ This implementation makes specific trade-offs:
|
||||
## References
|
||||
|
||||
- Murphy, John J. "Technical Analysis of the Financial Markets." New York Institute of Finance, 1999.
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
var sma = new Sma(period: 20);
|
||||
|
||||
// Process each new bar
|
||||
TValue result = sma.Update(new TValue(timestamp, closePrice));
|
||||
Console.WriteLine($"SMA: {result.Value:F2}");
|
||||
|
||||
// Check if buffer is full
|
||||
if (sma.IsHot)
|
||||
{
|
||||
// Indicator is fully initialized
|
||||
}
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TSeries API
|
||||
TSeries prices = ...;
|
||||
TSeries smaValues = Sma.Batch(prices, period: 20);
|
||||
|
||||
// Span API (High Performance)
|
||||
double[] prices = new double[1000];
|
||||
double[] output = new double[1000];
|
||||
Sma.Calculate(prices.AsSpan(), output.AsSpan(), period: 20);
|
||||
```
|
||||
|
||||
### Bar Correction (isNew Parameter)
|
||||
|
||||
```csharp
|
||||
var sma = new Sma(20);
|
||||
|
||||
// New bar
|
||||
sma.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
sma.Update(new TValue(time, 101), isNew: false); // Replaces 100 with 101
|
||||
|
||||
+42
-43
@@ -46,49 +46,6 @@ Our implementation maintains the state of the trend and the trailing bands.
|
||||
| Period | 10 | ATR Lookback | 10 is standard. Shorter = more volatile ATR. |
|
||||
| Multiplier | 3.0 | Band width | 3.0 is standard. Lower (e.g., 2.0) = tighter stops, more signals. Higher (e.g., 4.0) = wider stops, fewer signals. |
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
var super = new SuperTrend(period: 10, multiplier: 3.0);
|
||||
|
||||
// Process each new bar
|
||||
TBar bar = new TBar(time, open, high, low, close, volume);
|
||||
TValue result = super.Update(bar);
|
||||
|
||||
Console.WriteLine($"SuperTrend: {result.Value:F2}");
|
||||
Console.WriteLine($"Trend: {(result.IsBullish ? "Bullish" : "Bearish")}");
|
||||
|
||||
// Check if buffer is full
|
||||
if (super.IsHot)
|
||||
{
|
||||
// Indicator is fully initialized
|
||||
}
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TBarSeries API
|
||||
TBarSeries bars = ...;
|
||||
TSeries superValues = SuperTrend.Batch(bars, period: 10, multiplier: 3.0);
|
||||
```
|
||||
|
||||
### Bar Correction (isNew Parameter)
|
||||
|
||||
```csharp
|
||||
var super = new SuperTrend(10, 3.0);
|
||||
|
||||
// New bar
|
||||
super.Update(bar, isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
super.Update(updatedBar, isNew: false); // Replaces last calculation
|
||||
```
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
@@ -131,3 +88,45 @@ This implementation makes specific trade-offs:
|
||||
## References
|
||||
|
||||
- Seban, Olivier. "Tout le monde mérite d'être riche" (Everyone Deserves to Be Rich).
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
|
||||
```csharp
|
||||
using QuanTAlib;
|
||||
|
||||
var super = new SuperTrend(period: 10, multiplier: 3.0);
|
||||
|
||||
// Process each new bar
|
||||
TBar bar = new TBar(time, open, high, low, close, volume);
|
||||
TValue result = super.Update(bar);
|
||||
|
||||
Console.WriteLine($"SuperTrend: {result.Value:F2}");
|
||||
Console.WriteLine($"Trend: {(result.IsBullish ? "Bullish" : "Bearish")}");
|
||||
|
||||
// Check if buffer is full
|
||||
if (super.IsHot)
|
||||
{
|
||||
// Indicator is fully initialized
|
||||
}
|
||||
```
|
||||
|
||||
### Batch Processing (Historical Data)
|
||||
|
||||
```csharp
|
||||
// TBarSeries API
|
||||
TBarSeries bars = ...;
|
||||
TSeries superValues = SuperTrend.Batch(bars, period: 10, multiplier: 3.0);
|
||||
```
|
||||
|
||||
### Bar Correction (isNew Parameter)
|
||||
|
||||
```csharp
|
||||
var super = new SuperTrend(10, 3.0);
|
||||
|
||||
// New bar
|
||||
super.Update(bar, isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
super.Update(updatedBar, isNew: false); // Replaces last calculation
|
||||
|
||||
+39
-40
@@ -49,6 +49,45 @@ Our implementation uses the recursive GD formula for O(1) updates.
|
||||
| Period | 14 | Smoothing period | Standard lookback. |
|
||||
| Volume Factor (v) | 0.7 | Responsiveness | 0.7 is standard. Lower (0.1-0.5) = smoother/slower. Higher (0.8-1.0) = faster/responsive. |
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
|-----------|------------|-------------------|
|
||||
| Streaming update | O(1) | 6 layers of GD calculation |
|
||||
| Bar correction | O(1) | Efficient state rollback |
|
||||
| Batch processing | O(N) | Single pass through data |
|
||||
| Memory footprint | O(1) | Stores state for 6 internal layers |
|
||||
|
||||
## Interpretation
|
||||
|
||||
### Trading Signals
|
||||
|
||||
#### Trend Identification
|
||||
|
||||
- **Smoothness:** T3 is famous for filtering out "noise" better than almost any other MA. If T3 is rising, the trend is likely real, not just a blip.
|
||||
- **Crossovers:** Price crossing T3 is a significant event due to the indicator's smoothness.
|
||||
|
||||
### When It Works Best
|
||||
|
||||
- **Noisy Markets:** T3 shines in markets with lots of wicks and erratic movement, where standard EMAs would get chopped up.
|
||||
|
||||
### When It Struggles
|
||||
|
||||
- **Lag:** Despite its clever math, applying a filter 6 times introduces lag. It will turn after the market turns, not with it.
|
||||
|
||||
## Architecture Notes
|
||||
|
||||
This implementation makes specific trade-offs:
|
||||
|
||||
### Choice: 6 Layers
|
||||
|
||||
- **Implementation:** We implement the standard "T3" which implies 6 layers of smoothing.
|
||||
- **Rationale:** While "T2" or "T4" are possible, "T3" (6 layers) is the industry standard definition.
|
||||
|
||||
## References
|
||||
|
||||
- Tillson, Tim. "Smoothing Techniques for More Accurate Signals." *Technical Analysis of Stocks & Commodities*, V. 16:1 (33-37), 1998.
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
@@ -92,43 +131,3 @@ t3.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
t3.Update(new TValue(time, 101), isNew: false); // Replaces 100 with 101
|
||||
```
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
|-----------|------------|-------------------|
|
||||
| Streaming update | O(1) | 6 layers of GD calculation |
|
||||
| Bar correction | O(1) | Efficient state rollback |
|
||||
| Batch processing | O(N) | Single pass through data |
|
||||
| Memory footprint | O(1) | Stores state for 6 internal layers |
|
||||
|
||||
## Interpretation
|
||||
|
||||
### Trading Signals
|
||||
|
||||
#### Trend Identification
|
||||
|
||||
- **Smoothness:** T3 is famous for filtering out "noise" better than almost any other MA. If T3 is rising, the trend is likely real, not just a blip.
|
||||
- **Crossovers:** Price crossing T3 is a significant event due to the indicator's smoothness.
|
||||
|
||||
### When It Works Best
|
||||
|
||||
- **Noisy Markets:** T3 shines in markets with lots of wicks and erratic movement, where standard EMAs would get chopped up.
|
||||
|
||||
### When It Struggles
|
||||
|
||||
- **Lag:** Despite its clever math, applying a filter 6 times introduces lag. It will turn after the market turns, not with it.
|
||||
|
||||
## Architecture Notes
|
||||
|
||||
This implementation makes specific trade-offs:
|
||||
|
||||
### Choice: 6 Layers
|
||||
|
||||
- **Implementation:** We implement the standard "T3" which implies 6 layers of smoothing.
|
||||
- **Rationale:** While "T2" or "T4" are possible, "T3" (6 layers) is the industry standard definition.
|
||||
|
||||
## References
|
||||
|
||||
- Tillson, Tim. "Smoothing Techniques for More Accurate Signals." *Technical Analysis of Stocks & Commodities*, V. 16:1 (33-37), 1998.
|
||||
|
||||
+42
-43
@@ -43,6 +43,48 @@ Our implementation uses three internal EMA instances.
|
||||
|-----------|---------|---------|----------------------|
|
||||
| Period | 14 | Lookback window | Short (5-10) for scalping; Medium (20-50) for swing trading. |
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
|-----------|------------|-------------------|
|
||||
| Streaming update | O(1) | 3 EMA updates + scalar math |
|
||||
| Bar correction | O(1) | Efficient state rollback |
|
||||
| Batch processing | O(N) | Single pass through data |
|
||||
| Memory footprint | O(1) | Stores state for 3 internal EMAs |
|
||||
|
||||
## Interpretation
|
||||
|
||||
### Trading Signals
|
||||
|
||||
#### Trend Direction
|
||||
|
||||
- **Fast Response:** TEMA turns much faster than SMA or EMA. A turn in TEMA often precedes a turn in price trend.
|
||||
|
||||
#### Crossovers
|
||||
|
||||
- **Price Crossover:** Because TEMA hugs price so closely, crossovers are frequent. They are best used for short-term entries in the direction of a larger trend.
|
||||
|
||||
### When It Works Best
|
||||
|
||||
- **Momentum Trading:** TEMA is excellent for capturing short-term bursts of momentum.
|
||||
|
||||
### When It Struggles
|
||||
|
||||
- **Overshoot:** In a sudden V-shaped reversal, TEMA can "overshoot" the price briefly due to the momentum of its internal calculation components.
|
||||
|
||||
## Architecture Notes
|
||||
|
||||
This implementation makes specific trade-offs:
|
||||
|
||||
### Choice: Composition
|
||||
|
||||
- **Implementation:** Composed of 3 `Ema` objects.
|
||||
- **Rationale:** Reusing the robust `Ema` class ensures consistent behavior (like initialization and NaN handling) across the library.
|
||||
|
||||
## References
|
||||
|
||||
- Mulloy, Patrick G. "Smoothing Data with Faster Moving Averages." *Technical Analysis of Stocks & Commodities*, Jan 1994.
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
@@ -86,46 +128,3 @@ tema.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
tema.Update(new TValue(time, 101), isNew: false); // Replaces 100 with 101
|
||||
```
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
|-----------|------------|-------------------|
|
||||
| Streaming update | O(1) | 3 EMA updates + scalar math |
|
||||
| Bar correction | O(1) | Efficient state rollback |
|
||||
| Batch processing | O(N) | Single pass through data |
|
||||
| Memory footprint | O(1) | Stores state for 3 internal EMAs |
|
||||
|
||||
## Interpretation
|
||||
|
||||
### Trading Signals
|
||||
|
||||
#### Trend Direction
|
||||
|
||||
- **Fast Response:** TEMA turns much faster than SMA or EMA. A turn in TEMA often precedes a turn in price trend.
|
||||
|
||||
#### Crossovers
|
||||
|
||||
- **Price Crossover:** Because TEMA hugs price so closely, crossovers are frequent. They are best used for short-term entries in the direction of a larger trend.
|
||||
|
||||
### When It Works Best
|
||||
|
||||
- **Momentum Trading:** TEMA is excellent for capturing short-term bursts of momentum.
|
||||
|
||||
### When It Struggles
|
||||
|
||||
- **Overshoot:** In a sudden V-shaped reversal, TEMA can "overshoot" the price briefly due to the momentum of its internal calculation components.
|
||||
|
||||
## Architecture Notes
|
||||
|
||||
This implementation makes specific trade-offs:
|
||||
|
||||
### Choice: Composition
|
||||
|
||||
- **Implementation:** Composed of 3 `Ema` objects.
|
||||
- **Rationale:** Reusing the robust `Ema` class ensures consistent behavior (like initialization and NaN handling) across the library.
|
||||
|
||||
## References
|
||||
|
||||
- Mulloy, Patrick G. "Smoothing Data with Faster Moving Averages." *Technical Analysis of Stocks & Commodities*, Jan 1994.
|
||||
|
||||
+38
-39
@@ -45,6 +45,44 @@ Our implementation uses the Double SMA method for O(1) efficiency.
|
||||
|-----------|---------|---------|----------------------|
|
||||
| Period | 14 | Lookback window | Standard lookback. |
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
|-----------|------------|-------------------|
|
||||
| Streaming update | O(1) | Two sliding window sums |
|
||||
| Bar correction | O(1) | Efficient state rollback |
|
||||
| Batch processing | O(N) | Single pass through data |
|
||||
| Memory footprint | O(period) | RingBuffers for the two internal SMAs |
|
||||
|
||||
## Interpretation
|
||||
|
||||
### Trading Signals
|
||||
|
||||
#### Trend Identification
|
||||
|
||||
- **Primary Trend:** TRIMA is excellent for visualizing the "major" trend. If TRIMA is rising, the long-term direction is up, regardless of short-term chops.
|
||||
|
||||
### When It Works Best
|
||||
|
||||
- **Visual Clarity:** Traders often use TRIMA not for signals, but to declutter charts and see the underlying market structure.
|
||||
|
||||
### When It Struggles
|
||||
|
||||
- **Timing Entries:** Due to its significant lag, TRIMA is poor for timing entries or exits. It is a lagging indicator, not a leading one.
|
||||
|
||||
## Architecture Notes
|
||||
|
||||
This implementation makes specific trade-offs:
|
||||
|
||||
### Choice: Double SMA Composition
|
||||
|
||||
- **Implementation:** Composed of two `Sma` objects.
|
||||
- **Rationale:** This is mathematically equivalent to the weighted sum method but allows us to reuse the O(1) optimization of the `Sma` class.
|
||||
|
||||
## References
|
||||
|
||||
- Merrill, Arthur A. "Filtered Waves." *Technical Analysis of Stocks & Commodities*.
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
@@ -88,42 +126,3 @@ trima.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
trima.Update(new TValue(time, 101), isNew: false); // Replaces 100 with 101
|
||||
```
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
|-----------|------------|-------------------|
|
||||
| Streaming update | O(1) | Two sliding window sums |
|
||||
| Bar correction | O(1) | Efficient state rollback |
|
||||
| Batch processing | O(N) | Single pass through data |
|
||||
| Memory footprint | O(period) | RingBuffers for the two internal SMAs |
|
||||
|
||||
## Interpretation
|
||||
|
||||
### Trading Signals
|
||||
|
||||
#### Trend Identification
|
||||
|
||||
- **Primary Trend:** TRIMA is excellent for visualizing the "major" trend. If TRIMA is rising, the long-term direction is up, regardless of short-term chops.
|
||||
|
||||
### When It Works Best
|
||||
|
||||
- **Visual Clarity:** Traders often use TRIMA not for signals, but to declutter charts and see the underlying market structure.
|
||||
|
||||
### When It Struggles
|
||||
|
||||
- **Timing Entries:** Due to its significant lag, TRIMA is poor for timing entries or exits. It is a lagging indicator, not a leading one.
|
||||
|
||||
## Architecture Notes
|
||||
|
||||
This implementation makes specific trade-offs:
|
||||
|
||||
### Choice: Double SMA Composition
|
||||
|
||||
- **Implementation:** Composed of two `Sma` objects.
|
||||
- **Rationale:** This is mathematically equivalent to the weighted sum method but allows us to reuse the O(1) optimization of the `Sma` class.
|
||||
|
||||
## References
|
||||
|
||||
- Merrill, Arthur A. "Filtered Waves." *Technical Analysis of Stocks & Commodities*.
|
||||
|
||||
+43
-44
@@ -44,6 +44,49 @@ Our implementation calculates CMO and VIDYA in a single pass.
|
||||
|-----------|---------|---------|----------------------|
|
||||
| Period | 14 | Lookback window | Standard lookback for both CMO and the base EMA. |
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
|-----------|------------|-------------------|
|
||||
| Streaming update | O(1) | CMO update + EMA update |
|
||||
| Bar correction | O(1) | Efficient state rollback |
|
||||
| Batch processing | O(N) | Single pass through data |
|
||||
| Memory footprint | O(period) | RingBuffer for CMO calculation |
|
||||
|
||||
## Interpretation
|
||||
|
||||
### Trading Signals
|
||||
|
||||
#### Trend Following
|
||||
|
||||
- **Support/Resistance:** VIDYA is excellent at identifying dynamic support and resistance levels because it flattens out during consolidations (providing a clear "shelf" of support) and slopes steeply during trends.
|
||||
|
||||
#### Crossovers
|
||||
|
||||
- **Price Crossover:** Price crossing VIDYA is a standard trend entry signal. Because VIDYA adapts to volatility, these signals are often more reliable than SMA crossovers in choppy markets.
|
||||
|
||||
### When It Works Best
|
||||
|
||||
- **Breakouts:** VIDYA excels at catching breakouts from low-volatility consolidations because its effective period shortens (speeds up) as soon as volatility expands.
|
||||
|
||||
### When It Struggles
|
||||
|
||||
- **Grinding Trends:** In a slow, low-volatility grind upwards, VIDYA might lag more than a standard EMA because the low volatility keeps the smoothing factor small.
|
||||
|
||||
## Architecture Notes
|
||||
|
||||
This implementation makes specific trade-offs:
|
||||
|
||||
### Choice: CMO as Volatility Index
|
||||
|
||||
- **Implementation:** Uses Chande Momentum Oscillator.
|
||||
- **Rationale:** This is the original definition by Chande. Other variants (like using Efficiency Ratio) exist but are technically different indicators (e.g., KAMA).
|
||||
|
||||
## References
|
||||
|
||||
- Chande, Tushar. "The New Technical Trader." Wiley, 1994.
|
||||
- Chande, Tushar. "Adapting Moving Averages To Market Volatility." *Technical Analysis of Stocks & Commodities*, Mar 1992.
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
@@ -87,47 +130,3 @@ vidya.Update(new TValue(time, 100), isNew: true);
|
||||
|
||||
// Intra-bar update
|
||||
vidya.Update(new TValue(time, 101), isNew: false); // Replaces 100 with 101
|
||||
```
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
|-----------|------------|-------------------|
|
||||
| Streaming update | O(1) | CMO update + EMA update |
|
||||
| Bar correction | O(1) | Efficient state rollback |
|
||||
| Batch processing | O(N) | Single pass through data |
|
||||
| Memory footprint | O(period) | RingBuffer for CMO calculation |
|
||||
|
||||
## Interpretation
|
||||
|
||||
### Trading Signals
|
||||
|
||||
#### Trend Following
|
||||
|
||||
- **Support/Resistance:** VIDYA is excellent at identifying dynamic support and resistance levels because it flattens out during consolidations (providing a clear "shelf" of support) and slopes steeply during trends.
|
||||
|
||||
#### Crossovers
|
||||
|
||||
- **Price Crossover:** Price crossing VIDYA is a standard trend entry signal. Because VIDYA adapts to volatility, these signals are often more reliable than SMA crossovers in choppy markets.
|
||||
|
||||
### When It Works Best
|
||||
|
||||
- **Breakouts:** VIDYA excels at catching breakouts from low-volatility consolidations because its effective period shortens (speeds up) as soon as volatility expands.
|
||||
|
||||
### When It Struggles
|
||||
|
||||
- **Grinding Trends:** In a slow, low-volatility grind upwards, VIDYA might lag more than a standard EMA because the low volatility keeps the smoothing factor small.
|
||||
|
||||
## Architecture Notes
|
||||
|
||||
This implementation makes specific trade-offs:
|
||||
|
||||
### Choice: CMO as Volatility Index
|
||||
|
||||
- **Implementation:** Uses Chande Momentum Oscillator.
|
||||
- **Rationale:** This is the original definition by Chande. Other variants (like using Efficiency Ratio) exist but are technically different indicators (e.g., KAMA).
|
||||
|
||||
## References
|
||||
|
||||
- Chande, Tushar. "The New Technical Trader." Wiley, 1994.
|
||||
- Chande, Tushar. "Adapting Moving Averages To Market Volatility." *Technical Analysis of Stocks & Commodities*, Mar 1992.
|
||||
|
||||
+62
-63
@@ -46,6 +46,68 @@ This reduces the calculation to two subtractions, two additions, and one multipl
|
||||
| Period | 14 | Lookback window | Shorter (5-10) = scalping/intraday; Longer (20-50) = swing/trend following |
|
||||
| Source | Close | Price input | Typical usage is Close, but HL2 or HLC3 can provide smoother inputs |
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
|-----------|------------|-------------------|
|
||||
| Streaming update | O(1) | Constant time regardless of period length |
|
||||
| Bar correction | O(1) | Efficient state rollback for real-time feeds |
|
||||
| Batch processing | O(n) | SIMD-optimized (AVX2/AVX512/Neon) for high throughput |
|
||||
| Memory footprint | O(period) | Uses a RingBuffer to store the lookback window |
|
||||
|
||||
**Note:** The batch implementation automatically selects the best available SIMD instruction set (AVX512, AVX2, or ARM Neon) for the running hardware, falling back to a scalar implementation if necessary.
|
||||
|
||||
## Interpretation
|
||||
|
||||
### Trading Signals
|
||||
|
||||
#### Trend Identification
|
||||
|
||||
- **Uptrend:** Price is consistently above the WMA, and the WMA slope is positive.
|
||||
- **Downtrend:** Price is consistently below the WMA, and the WMA slope is negative.
|
||||
|
||||
#### Crossovers
|
||||
|
||||
- **Price Crossover:** Price crossing above the WMA suggests a potential bullish reversal. Price crossing below suggests a bearish reversal.
|
||||
- **Dual WMA:** Using two WMAs (e.g., 20 and 50). Fast crossing above Slow is a "Golden Cross" (bullish). Fast crossing below Slow is a "Death Cross" (bearish).
|
||||
|
||||
### When It Works Best
|
||||
|
||||
- **Trending Markets:** WMA excels in clearly defined trends where its reduced lag allows traders to enter and exit positions earlier than with an SMA.
|
||||
- **Swing Trading:** The linear weighting aligns well with swing trading timeframes, capturing momentum shifts effectively.
|
||||
|
||||
### When It Struggles
|
||||
|
||||
- **Choppy/Sideways Markets:** Like all moving averages, WMA will generate false signals in range-bound markets.
|
||||
- **Drop-off Effect:** Because the oldest price drops off the calculation entirely (weight goes from 1 to 0), a large price spike exiting the window can cause the WMA to move counter-intuitively, though less severely than an SMA.
|
||||
|
||||
## Architecture Notes
|
||||
|
||||
This implementation makes specific trade-offs:
|
||||
|
||||
### Choice: Dual Running Sums for O(1)
|
||||
|
||||
- **Alternative:** Recalculate weighted sum every bar (O(n)).
|
||||
- **Trade-off:** Requires maintaining two state variables ($S$ and $W$) and a RingBuffer.
|
||||
- **Rationale:** Critical for performance in real-time systems monitoring thousands of assets with long periods.
|
||||
|
||||
### Choice: Periodic Resync
|
||||
|
||||
- **Alternative:** Never resync.
|
||||
- **Trade-off:** Small CPU cost every 10,000 ticks.
|
||||
- **Rationale:** Floating-point errors accumulate in running sums. Periodic recalculation ensures long-running server stability.
|
||||
|
||||
#### Choice: SIMD for Batch
|
||||
|
||||
- **Alternative:** Scalar loop.
|
||||
- **Trade-off:** Code complexity (multiple execution paths).
|
||||
- **Rationale:** Batch processing is often the bottleneck in backtesting. SIMD provides 4-8x throughput improvement.
|
||||
|
||||
## References
|
||||
|
||||
- Colby, Robert W. "The Encyclopedia of Technical Market Indicators." McGraw-Hill, 2002.
|
||||
- Murphy, John J. "Technical Analysis of the Financial Markets." New York Institute of Finance, 1999.
|
||||
|
||||
## C# Usage
|
||||
|
||||
### Streaming Updates (Single Instance)
|
||||
@@ -121,66 +183,3 @@ var wma = new Wma(14);
|
||||
wma.Update(new TValue(time, 100));
|
||||
wma.Update(new TValue(time, double.NaN)); // Uses last valid value (100)
|
||||
wma.Update(new TValue(time, 110)); // Resumes normal calculation
|
||||
```
|
||||
|
||||
## Performance Profile
|
||||
|
||||
| Operation | Complexity | Description |
|
||||
|-----------|------------|-------------------|
|
||||
| Streaming update | O(1) | Constant time regardless of period length |
|
||||
| Bar correction | O(1) | Efficient state rollback for real-time feeds |
|
||||
| Batch processing | O(n) | SIMD-optimized (AVX2/AVX512/Neon) for high throughput |
|
||||
| Memory footprint | O(period) | Uses a RingBuffer to store the lookback window |
|
||||
|
||||
**Note:** The batch implementation automatically selects the best available SIMD instruction set (AVX512, AVX2, or ARM Neon) for the running hardware, falling back to a scalar implementation if necessary.
|
||||
|
||||
## Interpretation
|
||||
|
||||
### Trading Signals
|
||||
|
||||
#### Trend Identification
|
||||
|
||||
- **Uptrend:** Price is consistently above the WMA, and the WMA slope is positive.
|
||||
- **Downtrend:** Price is consistently below the WMA, and the WMA slope is negative.
|
||||
|
||||
#### Crossovers
|
||||
|
||||
- **Price Crossover:** Price crossing above the WMA suggests a potential bullish reversal. Price crossing below suggests a bearish reversal.
|
||||
- **Dual WMA:** Using two WMAs (e.g., 20 and 50). Fast crossing above Slow is a "Golden Cross" (bullish). Fast crossing below Slow is a "Death Cross" (bearish).
|
||||
|
||||
### When It Works Best
|
||||
|
||||
- **Trending Markets:** WMA excels in clearly defined trends where its reduced lag allows traders to enter and exit positions earlier than with an SMA.
|
||||
- **Swing Trading:** The linear weighting aligns well with swing trading timeframes, capturing momentum shifts effectively.
|
||||
|
||||
### When It Struggles
|
||||
|
||||
- **Choppy/Sideways Markets:** Like all moving averages, WMA will generate false signals in range-bound markets.
|
||||
- **Drop-off Effect:** Because the oldest price drops off the calculation entirely (weight goes from 1 to 0), a large price spike exiting the window can cause the WMA to move counter-intuitively, though less severely than an SMA.
|
||||
|
||||
## Architecture Notes
|
||||
|
||||
This implementation makes specific trade-offs:
|
||||
|
||||
### Choice: Dual Running Sums for O(1)
|
||||
|
||||
- **Alternative:** Recalculate weighted sum every bar (O(n)).
|
||||
- **Trade-off:** Requires maintaining two state variables ($S$ and $W$) and a RingBuffer.
|
||||
- **Rationale:** Critical for performance in real-time systems monitoring thousands of assets with long periods.
|
||||
|
||||
### Choice: Periodic Resync
|
||||
|
||||
- **Alternative:** Never resync.
|
||||
- **Trade-off:** Small CPU cost every 10,000 ticks.
|
||||
- **Rationale:** Floating-point errors accumulate in running sums. Periodic recalculation ensures long-running server stability.
|
||||
|
||||
#### Choice: SIMD for Batch
|
||||
|
||||
- **Alternative:** Scalar loop.
|
||||
- **Trade-off:** Code complexity (multiple execution paths).
|
||||
- **Rationale:** Batch processing is often the bottleneck in backtesting. SIMD provides 4-8x throughput improvement.
|
||||
|
||||
## References
|
||||
|
||||
- Colby, Robert W. "The Encyclopedia of Technical Market Indicators." McGraw-Hill, 2002.
|
||||
- Murphy, John J. "Technical Analysis of the Financial Markets." New York Institute of Finance, 1999.
|
||||
|
||||
Reference in New Issue
Block a user