TradingView indicator verification

Ehlers Sine Wave indicator: cycle phase and failure cases

The Ehlers Sine Wave indicator plots the sine of an estimated market-cycle phase and a Lead Sine shifted forward by 45 degrees. It describes a fitted cycle, not a known future price path. A TradingView script must identify how it estimates that phase: different Sine Wave versions can produce different crossings. This guide uses the public fixed-window phase calculation in Ehlers' 1996 article Stay In Phase for a reproducible diagnostic, and distinguishes it from later adaptive implementations.

See the decision guide

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 blackcat1402 listing was updated April 9, 2025; its author describes a Hilbert Transform and Homodyne Discriminator implementation associated with Rocket Science for Traders. Madrid identifies a different Even Better Sinewave implementation. Neither listing establishes equality with the fixed-window diagnostic below.

ReferenceDeclared methodComparison boundary
Ehlers, Stay In Phase (1996)Correlate a price window with sine and cosine; supply its cycle lengthUsed for the calculations on this page
blackcat1402, L2 Ehlers Sine WaveAdaptive period estimation, filtering, Sine and Lead SineCompare intermediate states and the actual source version
Madrid SinewaveEven Better Sinewave, described with two cycle settingsA 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.

  • 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.
QuantityDefinition
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 Ssin(φ × π/180)
Lead Sine Lsin((φ + 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.
nPricePhaseSineLead Sine
18107.07106845°0.7071071.000000
19109.23879567.5°0.9238800.923880
20110.00000090°1.0000000.707107
2692.928932225°−0.707107−1.000000
2790.761205247.5°−0.923880−0.923880
2890.000000270°−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 caseWhat the calculation reportsMistake to avoid
16-bar cyclePhase advances 22.5° per sampleAssuming that rate will continue on future market data
Linear rise: 118, 119, 120 at n = 18, 19, 20Unchanged phase and line orderingReading Lead Sine below Sine as a fresh short on every bar
Constant input: P[n] = 100R = I = 0 mathematically; phase unavailableTreating numerical noise as a meaningful angle
A changing period or multiple oscillationsThe selected window projects only one assumed frequencyCalling 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.
Where Pineify fits

Pine Script AI Coding Agent

Draft a public phase calculation from explicit rules, request syntax checking, and compare its intermediate values against your fixtures before adding alerts.

Draft a phase diagnostic

Frequently asked questions

Educational information, not investment advice. All numerical fixtures are hypothetical diagnostics, not market backtests. Phase estimates, indicator crossings and syntax checks do not establish future returns.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.