mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-24 13:38:05 +00:00
docs: remove C# Implementation Considerations sections, clean up temp scripts, reorganize test files
- Remove 'C# Implementation Considerations' sections from 34 indicator .md files - Delete 29 temp PowerShell scripts (_fix_mojibake.ps1, _hex_scan.ps1, etc.) - Move test files into tests/ subdirectories for consistent project structure - Add trader-focused bullet points to indicator documentation
This commit is contained in:
@@ -122,103 +122,6 @@ FRAMA is not implemented in the common TA libraries used by QuanTAlib. Validatio
|
||||
| **Ooples** | N/A | Not implemented |
|
||||
| **PineScript** | ✅ | Matches `lib/trends_IIR/frama/frama.pine` |
|
||||
|
||||
## C# Implementation Considerations
|
||||
|
||||
### State Management
|
||||
|
||||
FRAMA uses a compact State struct with dual RingBuffer tracking:
|
||||
|
||||
```csharp
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct State
|
||||
{
|
||||
public double Frama;
|
||||
public double LastHigh;
|
||||
public double LastLow;
|
||||
public int Bars;
|
||||
public bool HasValue;
|
||||
}
|
||||
```
|
||||
|
||||
Bar correction requires coordinated rollback of state and both ring buffers:
|
||||
|
||||
```csharp
|
||||
if (isNew) { _p_state = _state; _highs.Snapshot(); _lows.Snapshot(); }
|
||||
else { _state = _p_state; _highs.Restore(); _lows.Restore(); }
|
||||
```
|
||||
|
||||
### Dual RingBuffer Architecture
|
||||
|
||||
FRAMA maintains separate High and Low buffers for fractal dimension calculation:
|
||||
|
||||
```csharp
|
||||
private readonly RingBuffer _highs;
|
||||
private readonly RingBuffer _lows;
|
||||
```
|
||||
|
||||
The `GetMax` and `GetMin` helper methods scan these buffers for range calculations, supporting both recent-half and full-window lookups via `startOffset` parameter.
|
||||
|
||||
### Precomputed Constants
|
||||
|
||||
Constructor enforces even period and precalculates half-period:
|
||||
|
||||
```csharp
|
||||
int pe = (period % 2 == 0) ? period : period + 1;
|
||||
_periodEven = pe;
|
||||
_half = pe / 2;
|
||||
```
|
||||
|
||||
Alpha bounds are compile-time constants:
|
||||
|
||||
```csharp
|
||||
private const double AlphaFloor = 0.01;
|
||||
private const double AlphaCeil = 1.0;
|
||||
private const double Log2 = 0.693147180559945309417232121458176568;
|
||||
```
|
||||
|
||||
### FMA Usage
|
||||
|
||||
The final EMA update uses FusedMultiplyAdd:
|
||||
|
||||
```csharp
|
||||
double result = Math.FusedMultiplyAdd(prev, 1.0 - alpha, alpha * price);
|
||||
```
|
||||
|
||||
### TBar Input Support
|
||||
|
||||
FRAMA accepts TBar input for proper High/Low access, with TValue fallback:
|
||||
|
||||
```csharp
|
||||
public TValue Update(TValue input, bool isNew = true)
|
||||
{
|
||||
return Update(new TBar(input.Time, input.Value, input.Value,
|
||||
input.Value, input.Value, 0), isNew);
|
||||
}
|
||||
```
|
||||
|
||||
### Memory Layout
|
||||
|
||||
| Field | Type | Size | Purpose |
|
||||
| :--- | :--- | :---: | :--- |
|
||||
| `_periodEven` | int | 4B | Even-adjusted period |
|
||||
| `_half` | int | 4B | Half period for ranges |
|
||||
| `_highs` | RingBuffer | ~8B+period×8B | High values buffer |
|
||||
| `_lows` | RingBuffer | ~8B+period×8B | Low values buffer |
|
||||
| `_state` | State | ~32B | Current calculation state |
|
||||
| `_p_state` | State | ~32B | Previous state for rollback |
|
||||
| **Total** | | **~88B + 2×period×8B** | Per indicator instance |
|
||||
|
||||
### Range Scan Implementation
|
||||
|
||||
The `GetMax`/`GetMin` methods perform O(N) linear scans with modular indexing:
|
||||
|
||||
```csharp
|
||||
int idx = start + offset + i;
|
||||
if (idx >= capacity) idx -= capacity;
|
||||
```
|
||||
|
||||
This approach is simple and cache-friendly for typical periods (10-50). Monotonic deque optimization would reduce to O(1) amortized but adds complexity.
|
||||
|
||||
## Common Pitfalls
|
||||
|
||||
1. **Period parity**: The algorithm requires even `N`. Odd values are rounded up.
|
||||
|
||||
Reference in New Issue
Block a user