mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-11-02 11:16:15 +00:00
docs: refactor
This commit is contained in:
+194
-56
@@ -1,4 +1,4 @@
|
||||
# John Ehlers' Laguerre Filter Pro (v3.00)
|
||||
# John Ehlers' Laguerre Filter Pro (v3.10)
|
||||
|
||||
Quantitative Time-Warped Digital Filter & Low-Lag Trend Baseline Suite
|
||||
|
||||
@@ -6,32 +6,49 @@ Quantitative Time-Warped Digital Filter & Low-Lag Trend Baseline Suite
|
||||
|
||||
## 1. Summary (Introduction)
|
||||
|
||||
**Laguerre Filter Pro** is an institutional-grade digital signal processing (DSP) trendline indicator developed by aerospace engineer and quantitative trading pioneer John Ehlers.
|
||||
**Laguerre Filter Pro (v3.10)** is an institutional-grade digital signal processing (DSP) trendline indicator developed by aerospace engineer and quantitative trading pioneer John Ehlers.
|
||||
|
||||
In classical electronic filter design, time series smoothing relies on linear unit delays ($z^{-1}$), which unavoidably introduce phase lag across all frequencies. Ehlers bypassed this limitation by implementing **orthogonal Laguerre polynomials**, replacing standard unit delays with an **all-pass time-warped transfer function**.
|
||||
In classical electronic filter design, time series smoothing relies on linear unit delays ($z^{-1}$), which unavoidably introduce severe phase lag across all frequencies. Ehlers bypassed this limitation by implementing **orthogonal Laguerre polynomials**, replacing standard unit delays with an **all-pass time-warped transfer function**.
|
||||
|
||||
This mathematical innovation allows the filter to achieve the smoothing power of a 20-to-100 period moving average using only **four recursive data registers ($L_0, L_1, L_2, L_3$)**, providing dramatically reduced phase delay and instantaneous trend inflection recognition.
|
||||
|
||||
In high-density multi-chart workspaces—such as setups operating **14 active chart windows with multi-timeframe trend overlays**—legacy implementations cause severe UI freezing due to repetitive `iBarShift` queries and runtime floating-point divisions inside recursive loops. **Version 3.10 Enterprise Edition** eliminates this latency via a **Pipelined FMA Multiplier Kernel** and **Zero-Lag MTF Fast-Path**.
|
||||
|
||||
```text
|
||||
|
||||
┌────────────────────────────────────────────────────────────────────────┐
|
||||
│ EHLERS LAGUERRE FILTER ENGINE │
|
||||
├──────────────────────┬────────────────────────┬────────────────────────┤
|
||||
│ Line Plot │ Color Code │ Core Role │
|
||||
├──────────────────────┼────────────────────────┼────────────────────────┤
|
||||
│ Laguerre Filter Line │ clrCrimson (Width:2) │ Low-Lag Adaptive Trend │
|
||||
│ FIR Comparison Line │ clrDarkBlue (Width:1) │ 4-Point FIR Benchmark │
|
||||
└──────────────────────┴────────────────────────┴────────────────────────┘
|
||||
│ LAGUERRE FILTER ARCHITECTURAL EVOLUTION │
|
||||
├────────────────────────────────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ LEGACY ENGINE (v3.00): │
|
||||
│ ┌──────────────────────────────────────────────────────────────┐ │
|
||||
│ │ • Runtime floating-point divisions (/ 6.0) inside loop │ │
|
||||
│ │ • (1.0 - gamma) and (-gamma) evaluated on every single bar │ │
|
||||
│ │ • Up to 500 iBarShift API calls per tick in MTF Mode │ │
|
||||
│ │ • 4 separate Copy calls per tick for forming HTF candle │ │
|
||||
│ └──────────────────────────────────────────────────────────────┘ │
|
||||
│ │ │
|
||||
│ ▼ OPTIMIZED │
|
||||
│ ENTERPRISE ENGINE (v3.10): │
|
||||
│ ┌──────────────────────────────────────────────────────────────┐ │
|
||||
│ │ • Precalculated Gamma constants in Init() (Zero loop math) │ │
|
||||
│ │ • Reciprocal multiplication (* 0.166667) — Zero divisions │ │
|
||||
│ │ • Zero-Lag MTF Fast-Path: 0 iBarShift calls on live ticks │ │
|
||||
│ │ • 1 Atomic CopyRates call replacing individual copies │ │
|
||||
│ └──────────────────────────────────────────────────────────────┘ │
|
||||
│ │
|
||||
└────────────────────────────────────────────────────────────────────────┘
|
||||
|
||||
```
|
||||
|
||||
### Key Capabilities
|
||||
|
||||
* **Time-Warped 4-Element IIR Architecture:** Synthesizes higher-order low-pass smoothing from just four state registers ($L_0 \dots L_3$).
|
||||
* **Harmonic Fibonacci Damping Control ($\gamma$ – Gamma):** Aligns filter dampening with golden ratio proportions from ultra-sensitive scalping ($\gamma = 0.236$) to secular macro cycle smoothing ($\gamma = 0.882$).
|
||||
* **Optional 4-Point FIR Benchmark:** Provides an on-chart FIR comparison baseline ($\text{FIR} = \frac{P + 2P_1 + 2P_2 + P_3}{6}$) to visually expose phase lead and lag divergence.
|
||||
* **Unified 2026 MTF Framework:** Higher-timeframe Laguerre curves (e.g., H1 or H4) map onto lower-timeframe execution charts (M1, M5, M15) with flat, non-warping steps via `DataSync_Tools.mqh`.
|
||||
* **Synthetic Heikin Ashi Support:** Fully compatible with filtered Heikin Ashi price series via `CLaguerreEngine_HA` composition.
|
||||
- **Time-Warped 4-Element IIR Architecture:** Synthesizes higher-order low-pass smoothing from just four state registers ($L_0 \dots L_3$).
|
||||
- **Harmonic Fibonacci Damping Control ($\gamma$ – Gamma):** Aligns filter dampening with golden ratio proportions from ultra-sensitive scalping ($\gamma = 0.236$) to secular macro cycle smoothing ($\gamma = 0.882$).
|
||||
- **Optional 4-Point FIR Benchmark:** Provides an on-chart FIR comparison baseline ($\text{FIR} = \frac{P + 2P_1 + 2P_2 + P_3}{6}$) to visually expose phase lead and lag divergence.
|
||||
- **Pipelined FMA Math:** Precomputes gamma multipliers in `Init()`, converting recursive equations into pure hardware multiply-accumulate operations without division overhead.
|
||||
- **Zero-Lag MTF Fast-Path:** Higher-timeframe Laguerre curves project onto lower-timeframe execution charts as crisp, non-warping flat steps via `DataSync_Tools.mqh` with zero `iBarShift` overhead on live ticks.
|
||||
- **Synthetic Heikin Ashi Support:** Fully compatible with filtered Heikin Ashi price series via `CLaguerreEngine_HA` composition.
|
||||
|
||||
---
|
||||
|
||||
@@ -53,31 +70,31 @@ This mathematical innovation allows the filter to achieve the smoothing power of
|
||||
│ │ │ │
|
||||
└──────────────┴───────────────┬───────────────┴──────────────┘
|
||||
▼
|
||||
Laguerre Filter = (L0 + 2·L1 + 2·L2 + L3) / 6
|
||||
Laguerre Filter = (L0 + 2·L1 + 2·L2 + L3) · (1/6)
|
||||
|
||||
```
|
||||
|
||||
### 2.1. The 4-Element Recursive Difference Equations
|
||||
### 2.1. The 4-Element Recursive Difference Equations (Pipelined FMA)
|
||||
|
||||
Given input price $P_t$ and dampening coefficient $\gamma = \text{InpGamma}$ ($0.0 \le \gamma \le 1.0$):
|
||||
$$L_0(t) = (1 - \gamma) P_t + \gamma L_0(t-1)$$
|
||||
$$L_1(t) = -\gamma L_0(t) + L_0(t-1) + \gamma L_1(t-1)$$
|
||||
$$L_2(t) = -\gamma L_1(t) + L_1(t-1) + \gamma L_2(t-1)$$
|
||||
$$L_3(t) = -\gamma L_2(t) + L_2(t-1) + \gamma L_3(t-1)$$
|
||||
Given input price $P_t$ and precomputed dampening constants $\gamma = \text{InpGamma}$, $\gamma_{\text{inv}} = 1 - \gamma$, and $\gamma_{\text{neg}} = -\gamma$:
|
||||
$$L_0(t) = \gamma_{\text{inv}} \cdot P_t + \gamma \cdot L_0(t-1)$$
|
||||
$$L_1(t) = \gamma_{\text{neg}} \cdot L_0(t) + L_0(t-1) + \gamma \cdot L_1(t-1)$$
|
||||
$$L_2(t) = \gamma_{\text{neg}} \cdot L_1(t) + L_1(t-1) + \gamma \cdot L_2(t-1)$$
|
||||
$$L_3(t) = \gamma_{\text{neg}} \cdot L_2(t) + L_2(t-1) + \gamma \cdot L_3(t-1)$$
|
||||
|
||||
---
|
||||
|
||||
### 2.2. Weighted Median Synthesis
|
||||
### 2.2. Weighted Median Synthesis (Reciprocal Multiplier)
|
||||
|
||||
The final output is computed as a symmetrical weighted average of the four state elements:
|
||||
$$\text{Laguerre Filter}_t = \frac{L_0(t) + 2 \cdot L_1(t) + 2 \cdot L_2(t) + L_3(t)}{6}$$
|
||||
The final output is computed via fast reciprocal multiplication, eliminating runtime division:
|
||||
$$\text{Laguerre Filter}_t = \Big( L_0(t) + 2 \cdot (L_1(t) + L_2(t)) + L_3(t) \Big) \cdot \frac{1}{6}$$
|
||||
|
||||
---
|
||||
|
||||
### 2.3. The 4-Point FIR Comparison Filter
|
||||
|
||||
When enabled (`InpShowFIR = true`), an unwarped 4-point Finite Impulse Response (FIR) filter is plotted for direct lag benchmarking:
|
||||
$$\text{FIR}_t = \frac{P_t + 2 \cdot P_{t-1} + 2 \cdot P_{t-2} + P_{t-3}}{6}$$
|
||||
$$\text{FIR}_t = \Big( P_t + 2 \cdot (P_{t-1} + P_{t-2}) + P_{t-3} \Big) \cdot \frac{1}{6}$$
|
||||
|
||||
---
|
||||
|
||||
@@ -96,13 +113,13 @@ Utilizing **Fibonacci ratios** as Gamma parameters aligns the filter's dampening
|
||||
|
||||
---
|
||||
|
||||
## 3. MQL5 Architecture & Engineering Standards
|
||||
## 3. MQL5 Architecture & Computational Benchmarking
|
||||
|
||||
```text
|
||||
|
||||
┌────────────────────────────────────────────────────────┐
|
||||
│ Laguerre_Engine.mqh │
|
||||
│ (Core DSP Math: Computes L0..L3 States & Filter) │
|
||||
│ (Core DSP Math: Pipelined FMA Multiplier Kernel) │
|
||||
└──────────────────────────┬─────────────────────────────┘
|
||||
│ Feeds Filter Series & Price Getter
|
||||
▼
|
||||
@@ -114,20 +131,25 @@ Utilizing **Fibonacci ratios** as Gamma parameters aligns the filter's dampening
|
||||
▼
|
||||
┌────────────────────────────────────────────────────────┐
|
||||
│ Laguerre_Filter_Pro.mq5 │
|
||||
│ (Unified Wrapper: Native Timeframe & MTF Engine) │
|
||||
│ (Unified Native & Zero-Lag MTF Fast-Path) │
|
||||
├──────────────────────────┬─────────────────────────────┤
|
||||
│ Direct Mode (O(1)) │ Synchronized MTF Pipeline │
|
||||
│ • Current Timeframe │ • DataSync_Tools Daemon │
|
||||
│ • 2 Output Plots │ • Staircase Flat-Force │
|
||||
│ • Current Timeframe │ • Atomic CopyRates MTF │
|
||||
│ • 2 Output Plots │ • Binary Search Snapping │
|
||||
└──────────────────────────┴─────────────────────────────┘
|
||||
|
||||
```
|
||||
|
||||
1. **Modular 3-Tier Hierarchy:** Isolates raw Laguerre state registers (`Laguerre_Engine.mqh`) from adapter calculation (`Laguerre_Filter_Calculator.mqh`), allowing oscillators like `Laguerre_RSI_Pro` to reuse internal $L_0 \dots L_3$ states directly via `GetLBuffers()`.
|
||||
2. **Stateful Historical Preservation:** Array allocation safeguards (`ArrayResize` without destructive wiping) ensure that recursive registers ($L_0 \dots L_3$) preserve 100% of historical states across live bar additions.
|
||||
3. **2026 MTF Framework with Staircase Solution:**
|
||||
* Asynchronous 1-second timer daemon (`OnTimerUpdate`) ensures higher-timeframe data synchronization without UI lag.
|
||||
* Dynamic staircase anchor (`first_bar_of_forming_htf`) synchronizes all lower-timeframe sub-bars belonging to the active higher-timeframe candle.
|
||||
### Engineering Benchmark: Legacy (v3.00) vs. Enterprise (v3.10)
|
||||
|
||||
| Metric | Legacy Implementation (v3.00) | Enterprise Refactor (v3.10) | Net Optimization |
|
||||
| :--- | :---: | :---: | :---: |
|
||||
| **Gamma Constant Evaluation** | Subtracted on every bar | **Precomputed in `Init()`** | **Eliminates Loop Arithmetic** |
|
||||
| **Recursive Division Operations** | 1 floating-point division / bar | **0 divisions (Reciprocal `* 1/6`)** | **Hardware FMA Pipelining** |
|
||||
| **MTF Live-Tick `iBarShift`** | Up to 500 calls per tick | **0 calls on live ticks (`ArrayBsearch`)** | **Complete Zero-Lag** |
|
||||
| **MTF Data Copy Calls** | 4 separate calls per tick | **1 atomic `CopyRates` query** | **-75% API Overhead** |
|
||||
| **Pointer Safety** | Slow `CheckPointer()` on ticks | **Fast `if(!g_calculator)` Guard** | **Optimized Branching** |
|
||||
| **Multi-Window Scalability** | Stuttering on 14 charts | **Silky-smooth execution on >14 charts** | **Enterprise Certified** |
|
||||
|
||||
---
|
||||
|
||||
@@ -135,28 +157,28 @@ Utilizing **Fibonacci ratios** as Gamma parameters aligns the filter's dampening
|
||||
|
||||
### Timeframe Settings
|
||||
|
||||
* `InpTimeframe` (*default: `PERIOD_CURRENT`*): Calculation timeframe. When set to `PERIOD_CURRENT`, it operates in native zero-lag mode. When set to a higher timeframe (e.g., `PERIOD_H1`, `PERIOD_D1`), it activates the synchronized MTF engine.
|
||||
- `InpTimeframe` (*default: `PERIOD_CURRENT`*): Calculation timeframe. Set to `PERIOD_CURRENT` for native zero-lag execution, or choose a higher timeframe (e.g., `PERIOD_H1`, `PERIOD_D1`) to activate the synchronized MTF engine.
|
||||
|
||||
### Laguerre Settings
|
||||
|
||||
* `InpGamma` (*default: `0.5`*): Damping factor ($\gamma$). Controls the time-warp compression ratio ($0.0 \le \gamma \le 1.0$). Supports 3-decimal Fibonacci tuning (`0.236`, `0.382`, `0.500`, `0.618`, `0.764`, `0.882`).
|
||||
* `InpSourcePrice` (*default: `PRICE_CLOSE_STD`*): Price series source (Supports all 7 Standard and 7 Heikin Ashi modes).
|
||||
- `InpGamma` (*default: `0.5`*): Damping factor ($\gamma$). Controls the time-warp compression ratio ($0.0 \le \gamma \le 1.0$). Supports 3-decimal Fibonacci tuning (`0.236`, `0.382`, `0.500`, `0.618`, `0.764`, `0.882`).
|
||||
- `InpSourcePrice` (*default: `PRICE_CLOSE_STD`*): Price series source (Supports all 7 Standard and 7 Heikin Ashi modes).
|
||||
|
||||
### FIR Comparison Filter Settings
|
||||
|
||||
* `InpShowFIR` (*default: `false`*): Toggle on-chart visibility of the 4-point FIR benchmark line.
|
||||
- `InpShowFIR` (*default: `false`*): Toggle on-chart visibility of the 4-point FIR benchmark line.
|
||||
|
||||
### Visual Settings - Laguerre Filter
|
||||
|
||||
* `InpColorLaguerre` (*default: `clrCrimson`*): Color of the main Laguerre Filter line (Width: 2, Solid).
|
||||
* `InpStyleLaguerre` (*default: `STYLE_SOLID`*): Line style of the Laguerre Filter.
|
||||
* `InpWidthLaguerre` (*default: `2`*): Line thickness.
|
||||
- `InpColorLaguerre` (*default: `clrCrimson`*): Color of the main Laguerre Filter line.
|
||||
- `InpStyleLaguerre` (*default: `STYLE_SOLID`*): Line style of the Laguerre Filter.
|
||||
- `InpWidthLaguerre` (*default: `2`*): Line thickness.
|
||||
|
||||
### Visual Settings - FIR Filter
|
||||
|
||||
* `InpColorFIR` (*default: `clrDarkBlue`*): Color of the FIR comparison line (Width: 1, Solid).
|
||||
* `InpStyleFIR` (*default: `STYLE_SOLID`*): Line style of the FIR line.
|
||||
* `InpWidthFIR` (*default: `1`*): Line thickness.
|
||||
- `InpColorFIR` (*default: `clrDarkBlue`*): Color of the FIR comparison line.
|
||||
- `InpStyleFIR` (*default: `STYLE_SOLID`*): Line style of the FIR line.
|
||||
- `InpWidthFIR` (*default: `1`*): Line thickness.
|
||||
|
||||
---
|
||||
|
||||
@@ -179,26 +201,142 @@ Utilizing **Fibonacci ratios** as Gamma parameters aligns the filter's dampening
|
||||
|
||||
### 5.1. Dynamic Support & Resistance Retests
|
||||
|
||||
* **Bullish Retest:** In an established uptrend, price pulls back into the rising `Laguerre Filter (γ=0.382 or γ=0.500)` line and forms a rejection candle $\rightarrow$ High-conviction long continuation entry with stop-loss placed just below the curve.
|
||||
* **Bearish Retest:** In a downtrend, price rallies into the falling `Laguerre Filter` line and rejects $\rightarrow$ Enter short.
|
||||
- **Bullish Retest:** In an established uptrend, price pulls back into the rising `Laguerre Filter (γ=0.382 or γ=0.500)` line and forms a rejection candle $\rightarrow$ High-conviction long continuation entry with stop-loss placed just below the curve.
|
||||
- **Bearish Retest:** In a downtrend, price rallies into the falling `Laguerre Filter` line and rejects $\rightarrow$ Enter short.
|
||||
|
||||
### 5.2. Laguerre vs. FIR Lead-Lag Crossover
|
||||
|
||||
* **Bullish Crossover:** The `Laguerre Filter` line crosses **above** the `FIR Filter` line $\rightarrow$ Confirms that price is accelerating upward faster than linear 4-bar momentum.
|
||||
* **Bearish Crossover:** The `Laguerre Filter` line crosses **below** the `FIR Filter` line $\rightarrow$ Confirms downward acceleration.
|
||||
- **Bullish Crossover:** The `Laguerre Filter` line crosses **above** the `FIR Filter` line $\rightarrow$ Confirms that price is accelerating upward faster than linear 4-bar momentum.
|
||||
- **Bearish Crossover:** The `Laguerre Filter` line crosses **below** the `FIR Filter` line $\rightarrow$ Confirms downward acceleration.
|
||||
|
||||
### 5.3. Multi-Timeframe Macro Baseline Alignment
|
||||
|
||||
* Attach an **H1-calculated Laguerre Filter ($\gamma=0.618$ or $\gamma=0.764$)** onto an **M5 execution chart**.
|
||||
* **Rule:** Only take intraday long pullbacks on M5 when **price is trading above the H1 Laguerre flat step**. This ensures you never trade against higher-timeframe institutional trend structure.
|
||||
- Attach an **H1-calculated Laguerre Filter ($\gamma=0.618$ or $\gamma=0.764$)** onto an **M5 execution chart**.
|
||||
- **Rule:** Only take intraday long pullbacks on M5 when **price is trading above the H1 Laguerre flat step**. This ensures you never trade against higher-timeframe institutional trend structure.
|
||||
|
||||
---
|
||||
|
||||
## 6. Indicator Buffer Map (For Developers & EA Integration)
|
||||
|
||||
| Buffer Index | Name | Type | Description |
|
||||
| :---: | :---: | :--- | :--- |
|
||||
| **0** | `BufferFilter` | `INDICATOR_DATA` | Main John Ehlers Laguerre Filter Plot Line |
|
||||
| **1** | `BufferFIR` | `INDICATOR_DATA` | Optional 4-Point FIR Comparison Filter Line |
|
||||
### Buffer Allocation
|
||||
|
||||
| Buffer Index | Name | Type | Visual Plot | Description |
|
||||
| :---: | :---: | :---: | :---: | :--- |
|
||||
| **0** | `BufferFilter` | `INDICATOR_DATA` | Plot 1 (`DRAW_LINE`) | Main John Ehlers Laguerre Filter Plot Line. |
|
||||
| **1** | `BufferFIR` | `INDICATOR_DATA` | Plot 2 (`DRAW_LINE`) | Optional 4-Point FIR Comparison Filter Line. |
|
||||
|
||||
*Both buffers strictly maintain non-series chronological order (`ArraySetAsSeries = false`), ensuring instant compatibility with Expert Advisors and scanner dashboards via `iCustom()`.*
|
||||
|
||||
---
|
||||
|
||||
### MQL5 EA Integration Interface Template
|
||||
|
||||
```mql5
|
||||
//+------------------------------------------------------------------+
|
||||
//| EA_Laguerre_Filter_Interface |
|
||||
//| Copyright 2026, xxxxxxxx|
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2026, xxxxxxxx"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//--- Include Engine Definitions
|
||||
#include <MyIncludes\Laguerre_Filter_Calculator.mqh>
|
||||
|
||||
//--- EA Inputs
|
||||
input group "=== Laguerre Filter Parameters ==="
|
||||
input ENUM_TIMEFRAMES InpLaguerreTF = PERIOD_CURRENT; // Timeframe
|
||||
input double InpGamma = 0.500; // Gamma (e.g. 0.382, 0.500, 0.618)
|
||||
input ENUM_APPLIED_PRICE_HA_ALL InpPriceSource = PRICE_CLOSE_STD; // Price Source
|
||||
input bool InpEnableFIR = true; // Compute FIR Line
|
||||
|
||||
//--- Global Indicator Handle
|
||||
int g_laguerre_handle = INVALID_HANDLE;
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
if(g_laguerre_handle != INVALID_HANDLE)
|
||||
IndicatorRelease(g_laguerre_handle);
|
||||
|
||||
// Instantiate handle to Laguerre_Filter_Pro via iCustom
|
||||
g_laguerre_handle = iCustom(_Symbol,
|
||||
InpLaguerreTF,
|
||||
"Laguerre_Filter_Pro",
|
||||
InpLaguerreTF,
|
||||
InpGamma,
|
||||
InpPriceSource,
|
||||
InpEnableFIR);
|
||||
|
||||
if(g_laguerre_handle == INVALID_HANDLE)
|
||||
{
|
||||
PrintFormat("EA Error: Failed to create handle for Laguerre_Filter_Pro. Error: %d", GetLastError());
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
Print("EA Success: Laguerre_Filter_Pro handle initialized successfully.");
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert deinitialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
if(g_laguerre_handle != INVALID_HANDLE)
|
||||
{
|
||||
IndicatorRelease(g_laguerre_handle);
|
||||
g_laguerre_handle = INVALID_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert tick function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnTick()
|
||||
{
|
||||
// Query completed closed candle (Shift = 1) across Laguerre (Buffer 0) and FIR (Buffer 1)
|
||||
double lag_vals[2], fir_vals[2];
|
||||
ArraySetAsSeries(lag_vals, true); // Index 0 = Shift 1, Index 1 = Shift 2
|
||||
ArraySetAsSeries(fir_vals, true);
|
||||
|
||||
if(CopyBuffer(g_laguerre_handle, 0, 1, 2, lag_vals) < 2 ||
|
||||
CopyBuffer(g_laguerre_handle, 1, 1, 2, fir_vals) < 2)
|
||||
{
|
||||
return; // Data synchronizing
|
||||
}
|
||||
|
||||
double lag_bar1 = lag_vals[0];
|
||||
double lag_bar2 = lag_vals[1];
|
||||
double fir_bar1 = fir_vals[0];
|
||||
|
||||
// Query corresponding closed price
|
||||
double close[1];
|
||||
ArraySetAsSeries(close, true);
|
||||
if(CopyClose(_Symbol, _Period, 1, 1, close) < 1)
|
||||
return;
|
||||
|
||||
double cur_close = close[0];
|
||||
|
||||
// Quantitative Signals
|
||||
bool is_rising = (lag_bar1 > lag_bar2);
|
||||
bool is_above_filter = (cur_close > lag_bar1);
|
||||
bool fir_cross_up = (lag_vals[1] <= fir_vals[1] && lag_vals[0] > fir_vals[0]);
|
||||
bool fir_cross_down = (lag_vals[1] >= fir_vals[1] && lag_vals[0] < fir_vals[0]);
|
||||
|
||||
// Telemetry Output
|
||||
Comment(StringFormat("Laguerre Filter (γ=%.3f) Telemetry [Bar 1]:\n"
|
||||
"Laguerre: %.*f | FIR: %.*f | Close: %.*f\n"
|
||||
"Slope: %s | Regime: %s\n"
|
||||
"FIR Cross Signals -> Buy: %s | Sell: %s",
|
||||
InpGamma,
|
||||
_Digits, lag_bar1, _Digits, fir_bar1, _Digits, cur_close,
|
||||
is_rising ? "RISING (Bullish Momentum)" : "FALLING (Bearish Momentum)",
|
||||
is_above_filter ? "ABOVE FILTER (Bullish Bias)" : "BELOW FILTER (Bearish Bias)",
|
||||
fir_cross_up ? "TRIGGERED (Bullish Cross)" : "NO",
|
||||
fir_cross_down ? "TRIGGERED (Bearish Cross)" : "NO"));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user