Editors' picks
OPEN-SOURCE SCRIPT
Updated

TASC 2026.04 A Synthetic Oscillator

14 564
█ Overview

This script implements a Synthetic Oscillator as presented by John F. Ehlers in the April 2026 TASC Traders' Tips article "Avoiding Whipsaw Trades". The indicator aims to provide a smooth, low-lag oscillator for timely trading signals by dynamically mapping a sine wave to price data.


█ CONCEPTS

"Whipsaw" trades are a common issue in algorithmic trading. They occur when the market quickly moves against a position, causing the trader/trading system to reverse their position at a loss, and then the market reverses again and continues in the original direction. Such trades occur because the trading system is attempting to react quickly to market moves instead of focusing on broader market cycles.

A typical solution for reducing whipsaw trades is to apply linear filters to smooth the data and emphasize specific cycles. However, linear filters cannot have both a smooth response and a low computational lag. Therefore, strategy designs utilizing linear filters require a tradeoff between smoothness and lag.

Ehlers proposes a nonlinear indicator as a solution to bridge the gap and achieve a smooth, timely response while reducing whipsaw trades.

The Synthetic oscillator adapts to market conditions by calculating a dynamic sine wave from the estimated instantaneous dominant cycle over a range of periods.

The process to calculate the indicator is as follows:

  1. Smooth the price data with a 12-bar Hann Window filter to reduce high-frequency noise, which can affect dominant cycle estimates.

  2. Band-pass filter the windowed data with a two-pole high-pass filter and a SuperSmoother filter to focus on the range of cycles between a specified lower bound and upper bound, and normalize the result using the filter's 100-bar root mean square (RMS).

  3. Calculate the one-bar rate of change (ROC) in the oscillator from step 2, and normalize the ROC using its 100-bar RMS.

  4. Estimate the instantaneous dominant cycle from the oscillators in steps 2 and 3 by treating the series as a complex waveform, where the first oscillator represents the waveform's band-limited "real" component ("I"), and the second represents the band-limited "imaginary" component ("Q").

  5. Cumulatively sum the reciprocal of the dominant cycle (i.e., the dominant frequency) to obtain the phase angle of the sine wave.

  6. To reduce cumulative errors and lag in the phase angle calculation, compute a secondary band-bass filter from a high-pass filter and the UltimateSmoother, and reset the angle to 0 or 180 degrees when that filter crosses above or below 0.

  7. Calculate the Synthetic Oscillator as the sine of the final phase angle.



█ USAGE

snapshot

This indicator displays the Synthetic Oscillator and a horizontal zero line in a separate pane. Users can analyze the crossings between the oscillator value and 0, or the behavior of the oscillator as it reaches 1 or -1, to derive potential timely trading signals.

Ehlers notes in the article that the peaks and valleys of the Synthetic Oscillator can provide signals a little too early, depending on the settings and context. Therefore, he recommends applying another smoother to the oscillator, such as a Hann Window filter with an optimizable length, to adjust timing as necessary.

█ INPUTS

This indicator uses multiple hardcoded parameters based on the implementation in Ehlers' article. However, users can customize the source series and the upper and lower bounds of the calculations:

  • Source Series: The series of values to process.
  • Lower Bound: The smallest cycle in the passband of the filters, and the lower limit of the dominant cycle estimate.
  • Upper Bound: The largest cycle in the passband of the filters, and the upper limit of the dominant cycle estimate.
Release Notes
Bug Fix
Release Notes
Bug Fix: Hann Filter Corrected

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.