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:
@@ -146,89 +146,6 @@ TEMA is inherently recursive due to cascaded EMAs. SIMD parallelization across b
|
||||
| **Tulip** | ✅ | Matches `tema` exactly. |
|
||||
| **Ooples** | ❌ | Diverges significantly due to initialization logic. |
|
||||
|
||||
## C# Implementation Considerations
|
||||
|
||||
### State Management
|
||||
|
||||
TEMA maintains six EmaState instances—three current, three previous—enabling atomic rollback on bar corrections:
|
||||
|
||||
```csharp
|
||||
private record struct EmaState(double Ema, double E, bool IsHot, bool IsCompensated);
|
||||
|
||||
private EmaState _state1, _state2, _state3;
|
||||
private EmaState _p_state1, _p_state2, _p_state3;
|
||||
```
|
||||
|
||||
The `E` field tracks bias compensation factor for each EMA stage independently. Each state auto-transitions via `IsCompensated` flag when bias becomes negligible.
|
||||
|
||||
### Precomputed Constants
|
||||
|
||||
Constructor calculates smoothing constants once:
|
||||
|
||||
```csharp
|
||||
_alpha = 2.0 / (period + 1);
|
||||
_decay = 1 - _alpha;
|
||||
```
|
||||
|
||||
These constants are reused across all three EMA stages, avoiding repeated division.
|
||||
|
||||
### FMA Usage
|
||||
|
||||
Each EMA update uses FusedMultiplyAdd for the standard EMA formula:
|
||||
|
||||
```csharp
|
||||
double newEma = Math.FusedMultiplyAdd(state.Ema, _decay, _alpha * input);
|
||||
```
|
||||
|
||||
The final TEMA combination `3*e1 - 3*e2 + e3` could use FMA but the coefficients (3, -3, 1) make chained FMA marginal; current implementation uses direct arithmetic.
|
||||
|
||||
### Bar Correction Pattern
|
||||
|
||||
TEMA's cascaded structure requires coordinated state rollback:
|
||||
|
||||
```csharp
|
||||
if (isNew)
|
||||
{
|
||||
_p_state1 = _state1;
|
||||
_p_state2 = _state2;
|
||||
_p_state3 = _state3;
|
||||
}
|
||||
else
|
||||
{
|
||||
_state1 = _p_state1;
|
||||
_state2 = _p_state2;
|
||||
_state3 = _p_state3;
|
||||
}
|
||||
```
|
||||
|
||||
All three stages rollback atomically, ensuring consistent cascade state when `isNew=false`.
|
||||
|
||||
### Memory Layout
|
||||
|
||||
| Field | Type | Size | Purpose |
|
||||
| :--- | :--- | :---: | :--- |
|
||||
| `_alpha` | double | 8B | Smoothing constant |
|
||||
| `_decay` | double | 8B | 1 - alpha |
|
||||
| `_state1` | EmaState | 24B | First EMA state |
|
||||
| `_state2` | EmaState | 24B | Second EMA state |
|
||||
| `_state3` | EmaState | 24B | Third EMA state |
|
||||
| `_p_state1` | EmaState | 24B | Previous state 1 |
|
||||
| `_p_state2` | EmaState | 24B | Previous state 2 |
|
||||
| `_p_state3` | EmaState | 24B | Previous state 3 |
|
||||
| **Total** | | **160B** | Per indicator instance |
|
||||
|
||||
Each EmaState contains: Ema (8B), E (8B), IsHot (1B), IsCompensated (1B) + padding (~6B) = ~24B.
|
||||
|
||||
### Common Pitfalls
|
||||
|
||||
1. **Overshoot**: TEMA is so responsive it can overshoot price turns, creating a "whiplash" effect in volatile markets.
|
||||
2. **Noise**: By reducing lag, TEMA sacrifices some noise suppression. It is "nervous" compared to an SMA.
|
||||
3. **Identity Crisis**: Often confused with T3 (Tillson). T3 is a generalized version; TEMA is specifically T3 with $v=1$.
|
||||
4. **Warmup period**: Requires 3× period bars before producing valid output; premature signals are unreliable.
|
||||
5. **Parameter sensitivity**: Small period values (< 10) create excessive noise; large values (> 50) reduce responsiveness.
|
||||
6. **False signals**: In choppy, sideways markets, frequent crossovers generate misleading signals.
|
||||
7. **Computational cost**: 4× more expensive than simple EMA due to cascaded calculations.
|
||||
|
||||
## FAQ
|
||||
|
||||
**Q: How does TEMA differ from a triple-smoothed EMA?**
|
||||
|
||||
Reference in New Issue
Block a user