Kalman Filter EA
- Experts
-
Robert Davis Waweru Mugure
experienced algo trader .. 4 years of experience coding my own EAs and using them for myself. Found it wise to share some of my best EAs at a small token of appreciation .
also Washignton Accorded MECHATRONICS ENGINEER. - Versione: 4.5
- Attivazioni: 7
📈 Core Concept
This EA is a strict combining Kalman filtering, Rate of Change (ROC), Stochastic oscillator, and Triple Exponential Moving Average (TEMA) to generate high‑confidence entry signals. It works exclusively on closed candles and manages each trade independently with fixed Stop Loss and Take Profit.
🔍 How It Works (Step‑by‑Step)
-
Kalman Filter – Smooths price data to reduce market noise, producing a filtered series ( kfilt ) and its velocity.
-
Rate of Change (ROC) – Calculates the percentage change of the Kalman‑filtered price over 9 periods.
-
Stochastic (%K / %D) – Measures the current price position relative to the 14‑period high/low range; %K is smoothed with a 3‑period SMA to get %D.
-
Blended Line – Averages the ROC and the Stochastic %D to create a composite oscillator.
-
TEMA Smoothing – Applies a Triple Exponential Moving Average (period 20) to the blended line to further reduce lag and false signals.
-
Signal Generation – A buy (sell order) is triggered when the TEMA crosses above its previous value, and a sell (buy order) when it crosses below. The cross is evaluated strictly at the bar close.
Note: The EA does not close positions on opposite signals. Trades are only exited by the fixed Stop Loss or Take Profit.
⚡ Key Advantages
| Advantage | Description |
|---|---|
| Noise Reduction | Kalman filter adaptively smooths price, distinguishing genuine trends from random fluctuations. |
| Multi‑Factor Signal | Combines momentum (ROC) and mean‑reversion (Stochastic) for a balanced view of market conditions. |
| TEMA Smoothing | Triple EMA further filters the signal to avoid whipsaws common in noisy oscillators. |
| Strict Bar‑Close Execution | Evaluates only fully formed candles, avoiding intra‑bar noise and premature entries. |
| Fixed Risk per Trade | Hardcoded Stop Loss and Take Profit (in points) ensure predictable risk/reward on every position. |
| Spread Protection | Blocks trading when spread exceeds a user‑defined threshold. |
| Independent Trade Management | No conflicting logic; each trade runs its own SL/TP without interference from new signals. |
⚙️ Input Parameters
| Parameter | Default | Description |
|---|---|---|
| InpLotSize | 0.01 | Fixed position size (in lots) for every trade. |
| InpTakeProfitPts | 300 | Take Profit distance in points (e.g., 300 points = 30 pips for 5‑digit brokers). |
| InpStopLossPts | 600 | Stop Loss distance in points. Fixed SL ensures a consistent risk per trade. |
| InpMaxSpreadPts | 30 | Maximum allowable spread in points. Trades are cancelled if spread exceeds this value. |
Fixed Internal Parameters (not user‑adjustable, as per the original strategy):
| Parameter | Value | Purpose |
|---|---|---|
| Kalman Sharpness | 25.0 | Controls the filter’s responsiveness to price changes. |
| Kalman K | 1.0 | Gain factor for velocity updates. |
| ROC Length | 9 | Period used for the Rate of Change calculation. |
| Stoch %K Period | 14 | Lookback for Stochastic high/low range. |
| Stoch %D Smooth | 3 | Smoothing period for the Stochastic signal line. |
| TEMA Smooth Length | 20 | Smoothing period for the Triple EMA applied to the blended line. |
🧠 Strategy Philosophy
-
No Martingale or Grid – Each trade is a one‑off decision with fixed risk.
-
Mean‑Reversion & Momentum Fusion – ROC captures momentum, Stochastic captures overbought/oversold extremes; their average creates a more robust indicator.
-
Crossover Logic – Entry is triggered only when the smoothed blend changes direction, aiming to catch the beginning of a new move.
💡 Best Use Cases
-
Timeframe: Works well on any timeframe, but the original logic was designed for 1‑hour or 4‑hour charts.
-
Instruments: Suitable for major forex pairs, indices, or commodities with moderate volatility.
-
Market Conditions: Performs best in trending markets where filter and ROC can capture sustained moves; range‑bound markets may produce fewer signals.
⚠️ Important Notes
-
No Position Management – The EA does not track open positions; it simply sends new orders when conditions are met. Manual intervention is not required unless you wish to modify the fixed SL/TP.
-
PineScript Accuracy – Every calculation has been meticulously translated from the original PineScript code to preserve the exact logic and performance.
-
Historical Calculation – On initialization, the EA back‑fills its internal arrays to ensure the Kalman filter converges properly before the first live signal.
