refactor: Added optional Noise Elimination Technology (NET)

This commit is contained in:
Toh4iem9
2025-10-21 10:57:57 +02:00
parent e63abd36fb
commit 589b3f00f0
+37 -38
View File
@@ -1,74 +1,73 @@
# RSIH Professional (RSI with Hann Windowing)
# RSIH Professional (RSI with Hann Windowing & NET)
## 1. Summary (Introduction)
The RSIH, or "RSI with Hann Windowing," is John Ehlers' innovative take on the classic Relative Strength Index. It introduces two fundamental improvements to address what Ehlers considered shortcomings of the original RSI: its lack of a zero-mean and its inherent noisiness.
The RSIH, or "RSI with Hann Windowing," is John Ehlers' innovative take on the classic Relative Strength Index. It introduces two fundamental improvements: a **zero-mean (-1 to +1) scale** for clearer momentum analysis, and a **Hann windowing function** for intrinsic smoothing.
The RSIH modifies the standard RSI in two key ways:
This version is further enhanced with Ehlers' **Noise Elimination Technology (NET)**, a non-lagging filter based on Kendall correlation. The indicator plots two lines:
1. **Zero-Mean Scaling:** The output is mathematically transformed from the traditional 0-100 scale to a **-1 to +1 scale**. On this new scale, +1 represents maximum bullish momentum, -1 represents maximum bearish momentum, and 0 is the point of perfect equilibrium.
2. **Hann Windowing:** Instead of a simple summation of price changes (like a Simple Moving Average), the RSIH uses a **Hann windowing function** to calculate the "Closes Up" (CU) and "Closes Down" (CD) components. This is a cosine-based weighting method that gives more importance to the data in the middle of the lookback period and less to the newest and oldest data.
1. **RSIH Line (dotted gray):** The base, Hann-smoothed RSI. It is faster but can be noisy.
2. **NET Line (solid blue):** The NET-filtered version of the RSIH. This line is significantly smoother, clarifying the underlying momentum state without adding the lag of traditional moving averages.
The result is an oscillator that is significantly **smoother** than the classic RSI, with the smoothing being an intrinsic part of the calculation itself, rather than an afterthought.
The result is a comprehensive, two-line oscillator system that provides both a fast signal and a smoothed, reliable confirmation.
## 2. Mathematical Foundations and Calculation Logic
The RSIH is a Finite Impulse Response (FIR) filter applied to price changes, which is then scaled to a bipolar output.
The indicator uses a multi-stage process, first calculating the RSIH and then optionally applying the NET filter.
### Required Components
* **Period (N):** The lookback period for the calculation.
* **RSI Period (N):** The lookback period for the RSIH calculation.
* **NET Period (M):** The lookback period for the NET calculation.
* **Source Price (P):** The price series used for the calculation.
### Calculation Steps (Algorithm)
For each bar, the indicator looks back over the last `N` periods.
1. **Calculate Price Differences:** For each bar within the `N`-period window, calculate the difference from the previous bar: $\text{diff} = P_i - P_{i-1}$.
2. **Calculate Hann Window Weight:** For each position `j` within the window (from 1 to N), calculate the corresponding Hann weight:
$W_j = 1 - \cos\left(\frac{2\pi \times j}{N+1}\right)$
3. **Calculate Weighted CU and CD:** Sum the positive and negative price differences, multiplied by their respective Hann weights.
* $\text{CU} = \sum_{j=1}^{N} (\text{if diff}_j > 0, \text{diff}_j \times W_j, \text{else } 0)$
* $\text{CD} = \sum_{j=1}^{N} (\text{if diff}_j < 0, |\text{diff}_j| \times W_j, \text{else } 0)$
4. **Calculate Final RSIH Value:** Apply Ehlers' zero-mean transformation:
1. **Calculate Weighted CU and CD:** For each bar, the indicator calculates the "Closes Up" (CU) and "Closes Down" (CD) over the last `N` periods. Each price difference is weighted using a **Hann windowing function**, which gives more importance to the data in the middle of the period.
2. **Calculate RSIH Value:** Apply Ehlers' zero-mean transformation:
$\text{RSIH} = \frac{\text{CU} - \text{CD}}{\text{CU} + \text{CD}}$
3. **Apply NET Filter (Optional):** The calculated RSIH values are then processed by the NET algorithm.
* The NET calculates the **Kendall rank correlation** between the last `M` values of the RSIH and a perfectly linear trend.
* It essentially measures the "directional consistency" of the RSIH. If the RSIH is moving smoothly up or down, the correlation is high (near +1 or -1). If it's choppy, the correlation is low (near 0).
* The result is a smoothed version of the RSIH where the "noise" (inconsistent movements) has been stripped out.
## 3. MQL5 Implementation Details
* **Self-Contained Calculator (`RSIH_Calculator.mqh`):** The entire calculation, including the Hann-windowed summation, is encapsulated within a dedicated, reusable calculator class.
* **Heikin Ashi Integration:** An inherited `_HA` class allows the calculation to be performed seamlessly on smoothed Heikin Ashi data.
* **FIR-based Logic:** Unlike the classic Wilder's RSI which uses a recursive (IIR) smoothing, the RSIH is a non-recursive (FIR) filter. This means its calculation at any given bar depends only on the last `N` price changes, giving it a finite "memory."
* **Unified Calculator (`RSIH_Calculator.mqh`):** The entire calculation for both RSIH and NET is encapsulated within a single, dedicated calculator class.
* **Heikin Ashi Integration:** An inherited `_HA` class allows all calculations to be performed seamlessly on smoothed Heikin Ashi data.
* **FIR-based Logic:** The RSIH calculation is a non-recursive (FIR) filter. The NET calculation is a statistical correlation, also non-recursive. This gives the indicator a finite "memory."
* **Stability via Full Recalculation:** The indicator employs a full recalculation on every `OnCalculate` call to ensure stability and accuracy.
## 4. Parameters
* **RSI Period (`InpPeriodRSI`):** The lookback period (`N`) for the calculation.
* Ehlers notes that due to the nature of Hann windowing, a **longer period** may be required to achieve the same level of smoothing as a traditional RSI. A good starting point is **14**, but experimenting with longer periods (e.g., 21 or 28) can yield a smoother, clearer signal.
* **Applied Price (`InpSourcePrice`):** The source price for the calculation. This unified dropdown menu allows you to select from all standard and Heikin Ashi price types.
* **RSI Period (`InpPeriodRSI`):** The lookback period (`N`) for the base RSIH calculation.
* **NET Period (`InpPeriodNET`):** The lookback period (`M`) for the Noise Elimination Technology filter.
* **Apply NET (`InpApplyNET`):** Toggles the visibility and calculation of the NET line. If `false`, only the base RSIH line will be shown as a solid line.
* **Applied Price (`InpSourcePrice`):** The source price for the calculation.
**Note on Period Sensitivity:** Due to the FIR-based nature of the calculations, this indicator is **highly sensitive to period length**. A small change in `InpPeriodRSI` or `InpPeriodNET` can significantly alter the shape of the output. Users are encouraged to experiment to find the optimal "tuning" for their specific instrument and timeframe. Ehlers uses `14` as a starting point in his articles.
## 5. Usage and Interpretation
The RSIH is used in a similar way to a traditional RSI, but its signals are often cleaner and its zero-mean nature provides a clear momentum baseline.
The RSIH indicator with NET is a two-line system designed for signal confirmation. Use the **blue NET line** to determine the overall momentum bias and the **gray RSIH line** for timing signals.
### **1. Overbought / Oversold Zones**
### **1. NET Line as a Momentum Filter (Primary Strategy)**
Instead of 70/30, the key levels are on the -1 to +1 scale. Common levels are **+0.5 / -0.5** or, for more extreme signals, **+0.8 / -0.8**.
The blue NET line provides a very clear, smoothed view of the market's momentum state.
* **Buy Signal:** The indicator line crosses up from below the oversold level (e.g., -0.5).
* **Sell Signal:** The indicator line crosses down from above the overbought level (e.g., +0.5).
* **Best Use:** This strategy works best in **ranging or consolidating markets**.
* **Bullish Bias (NET > 0):** When the blue NET line is above the zero line, the underlying momentum is bullish. In this state, primarily look for **buy signals** on the gray RSIH line.
* **Bearish Bias (NET < 0):** When the blue NET line is below the zero line, the underlying momentum is bearish. In this state, primarily look for **sell signals** on the gray RSIH line.
### **2. Zero-Line Crossover (Trend Filter)**
### **2. RSIH for Entry Signals**
The zero line is the equilibrium point.
Once the bias is determined by the NET line, use the faster, gray RSIH line for timing entries.
* **Bullish Momentum:** When the RSIH is **above 0**, momentum is considered bullish.
* **Bearish Momentum:** When the RSIH is **below 0**, momentum is considered bearish.
* A cross of the zero line can be used as a confirmation of a change in the short-term trend.
* **Buy Signal:** While the **blue NET line is above 0**, wait for the **gray RSIH line** to dip into the oversold zone (e.g., below -0.5) and then cross back up. This signals a pullback entry in an ongoing uptrend.
* **Sell Signal:** While the **blue NET line is below 0**, wait for the **gray RSIH line** to rise into the overbought zone (e.g., above +0.5) and then cross back down. This signals a rally entry in an ongoing downtrend.
### **3. Divergence**
### **3. Crossover Signals**
Due to its smoothness, divergences can be easier to spot on the RSIH than on a classic RSI.
The crossover of the two lines can be used as a confirmation signal, though it will have more lag.
* **Bullish Divergence:** Price makes a **new lower low**, but the RSIH makes a **higher low**. This indicates weakening sell pressure.
* **Bearish Divergence:** Price makes a **new higher high**, but the RSIH makes a **lower high**. This indicates weakening buy pressure.
* **Buy Confirmation:** The gray RSIH line crosses above the blue NET line.
* **Sell Confirmation:** The gray RSIH line crosses below the blue NET line.