Three versions that should not share one numerical benchmark
The name Sine Wave does not identify one TradingView implementation. Save the publication URL, author, update date and inputs. The April 9, 2025 release notes for blackcat1402 describe a Hilbert Transform and Homodyne Discriminator implementation; the original description associates it with Rocket Science for Traders. Check subsequent revisions before comparing values. Madrid identifies a different Even Better Sinewave implementation. Neither listing establishes equality with the fixed-window diagnostic below.
| Reference | Declared method | Comparison boundary |
|---|
| Ehlers, Stay In Phase (1996) | Correlate a price window with sine and cosine; supply its cycle length | Used for the calculations on this page |
| blackcat1402, L2 Ehlers Sine Wave | Adaptive period estimation, filtering, Sine and Lead Sine | Compare intermediate states and the actual source version |
| Madrid Sinewave | Even Better Sinewave, described with two cycle settings | A separate algorithm; do not expect the same phase or crossings |
Define a phase calculation that can be reproduced
For the fixed-window diagnostic, let P[n] be price and N an integer window length of at least three bars. Sum j from 0 through N − 1. The quadrant-aware angle atan2(I, R), followed by a 90-degree offset, matches the phase convention used here. Convert radians to degrees before adding degree offsets. If both sums are zero, phase is undefined.
- Require N valid observations before calculating. Do not replace missing prices with zero. This finite-window diagnostic needs no recursive seed; an adaptive filter does, and its warm-up must be checked separately.
- When √(R² + I²) is zero, phase is undefined. For floating-point calculations, declare a scale-aware near-zero tolerance. The numerical fixtures below use 0.000000001 because their prices are around 100; that is not a universal market setting.
- A phase reading of 359 degrees followed by 1 degree can represent a forward move of 2 degrees. Raw subtraction gives −358 and would corrupt a phase-speed test. Conversely, wrapping every negative change forward can hide a real backward estimate; define the continuity rule.
| Quantity | Definition |
|---|
| Real component R | Σ P[n − j] × cos(2πj/N) |
| Imaginary component I | Σ P[n − j] × sin(2πj/N) |
| Phase φ | (atan2(I, R) × 180/π + 90) modulo 360 |
| Sine S | sin(φ × π/180) |
| Lead Sine L | sin((φ + 45) × π/180) |
Recalculate a 16-bar cycle and its crossing timing
Use the hypothetical input P[n] = 100 + 10 sin(2πn/16), N = 16, and at least 16 valid samples. Applying the sums gives R = 80 sin(2πn/16) and I = −80 cos(2πn/16). These are calculated fixtures, not TradingView observations or trading results. Displayed values are rounded to six decimals.
- Solving sin(φ + 45°) = sin(φ) gives φ = 67.5° or 247.5° modulo 360°. Each intersection is 22.5° before the corresponding sine extremum: 1/16 of a cycle, or one bar when the period is 16. The Lead Sine line itself has a 45° phase lead; these are different measurements.
- For increasing phase, Lead Sine moves from above Sine to below at the upper intersection; it moves from below to above at the lower intersection. This describes turning candidates only under the selected phase convention.
- A strict Lead Sine crossunder requires L < S now and L ≥ S on the preceding observation. At n = 19 the mathematical lines are equal, so that strict event first occurs at n = 20, the sampled price peak. Similarly, the strict upward event occurs at n = 28. Floating-point rounding near equality needs an explicit comparison policy.
- The one-bar theoretical lead is therefore not a promise of a one-bar executable lead. Sampling, estimator delay, confirmation and execution timing all affect an alert or trade.
| n | Price | Phase | Sine | Lead Sine |
|---|
| 18 | 107.071068 | 45° | 0.707107 | 1.000000 |
| 19 | 109.238795 | 67.5° | 0.923880 | 0.923880 |
| 20 | 110.000000 | 90° | 1.000000 | 0.707107 |
| 26 | 92.928932 | 225° | −0.707107 | −1.000000 |
| 27 | 90.761205 | 247.5° | −0.923880 | −0.923880 |
| 28 | 90.000000 | 270° | −1.000000 | −0.707107 |
A rising trend can have a stationary phase
Replace the wave with P[n] = 100 + n and retain N = 16. Direct summation gives R = 8 and I = 8 cot(π/16) = 40.218716 on every full window. Phase stays at 168.75°, Sine at 0.195090 and Lead Sine at −0.555570 while prices continue rising. This exact discrete result is specific to the stated window and convention.
- Detrending changes the question. Consider P[n] = 100 + 2n + 2 sin(2πn/16). Every sampled price increase exceeds 1.2, so this series rises throughout. If a diagnostic removes the exact linear component, its remaining wave still has alternating upper and lower crossings. Those crossings describe the residual, not reversals of the total price.
- For that constructed series, prices at n = 19, 20 and 21 are 139.847759, 142.000000 and 143.847759. A downward residual-cycle signal near n = 20 would occur during an uninterrupted price rise. This is an illustrative exact detrending operation, not a claim that a named community script removes trends perfectly.
- Near zero amplitude, small perturbations can move the estimated angle substantially. Rejecting weak components can reduce such events but also excludes observations; choose the rule before evaluating a later sample.
| Input case | What the calculation reports | Mistake to avoid |
|---|
| 16-bar cycle | Phase advances 22.5° per sample | Assuming that rate will continue on future market data |
| Linear rise: 118, 119, 120 at n = 18, 19, 20 | Unchanged phase and line ordering | Reading Lead Sine below Sine as a fresh short on every bar |
| Constant input: P[n] = 100 | R = I = 0 mathematically; phase unavailable | Treating numerical noise as a meaningful angle |
| A changing period or multiple oscillations | The selected window projects only one assumed frequency | Calling the fitted phase the unique phase of price |
Compare TradingView values before enabling alerts
Start with the exact script and its accessible calculation. For a fixed-window port, reproduce the tables first. For an adaptive version, inspect its source to identify the price smoother, period limits, period rounding, phase offsets and initialization. Substituting the fixed window above is a diagnostic comparison, not an adaptive replica.
- Use the same symbol feed, standard candles, source, session, timeframe and completed timestamps. Compare the input first, then the cycle period and phase, then the two plotted lines.
- Load extra earlier history and compare the same later timestamps. If recursive states still differ, record the warm-up sensitivity rather than hiding it with a universal bar count.
- A developing candle changes its price input. Require confirmed chart bars for a close-based rule; higher-timeframe inputs need their own confirmation policy. Bar-close confirmation does not fix future-data access, a wrong formula or mismatched initialization.
- Test a cycle window, a sustained trend and a quiet window separately. Record phase jumps, repeated crossings and missed turns without selecting only the clean example. This page has not certified numerical parity with either community publication.
Give Pineify the estimator and the acceptance cases
Ask the Pine Script AI Coding Agent to draft the public fixed-window diagnostic with N = 16, the stated phase convention, a missing-value gate, a declared amplitude tolerance and confirmed-bar crossing conditions. Require intermediate R, I and phase values in the Data Window. Explicitly request a syntax check, then compare the numerical output before creating TradingView alerts.
- Include the cycle, linear-rise and constant-input fixtures above. Preserve the unavailable result for flat data and define how equality is handled at the crossing.
- For an adaptive port, supply an authorized source and its initialization details. Do not ask the agent to infer protected internals from a plot or label a different algorithm as an exact copy.
- Syntax checking verifies language errors; it does not establish phase accuracy, TradingView parity or profitable trading rules.