OPEN-SOURCE SCRIPT

Frequency Domain Predictor

4 261
This indicator identifies the dominant repeating cycle within price movement by first suppressing long-term trend components with a high-pass filter, then isolating a single clean wavelength using an octave-wide band-pass filter built from a high-pass and SuperSmoother combination; it then generates a phase-advanced forecast of that cycle by creating a quadrature (Hilbert transform) version of the filtered wave and blending it with the original at an adjustable phase angle, producing a predictive "lead" line that anticipates the cycle's next turn rather than merely reporting where it has already been, with a companion multi-timeframe table scoring trend alignment across the hourly, daily, weekly, and monthly charts (weighted 1/2/3/4 respectively, for a maximum combined score of ±10) to show whether shorter and longer-term rhythms are confirming or conflicting with one another.

The basic idea
This code is based on the technician  John Ehlers' article  "A New Look at Prediction"

Imagine the stock market moves in waves, kind of like ocean tides. Prices don't just go up and down randomly — they tend to swing in rhythms, some short (like a few days), some longer (like a few weeks or months). This indicator tries to spot those rhythms and, once it "learns" the rhythm, make a good guess about where the wave is heading next — a little bit like watching a swing go back and forth and being able to predict when it'll reach the top, just from watching its motion.
The two lines on the chart
Think of price movements like music, made up of layered sounds Imagine the stock's price history is actually a piece of music playing many notes at once — some very deep, slow bass notes (the big, months-long trends), and some quick, high-pitched notes (the short daily jitters). They're all playing on top of each other at the same time, which is why raw price charts look like noisy scribbles. Step 1: Turn down the bass The first move is like taking an equalizer and turning way down on the deep bass notes — the slow, long-term drift in price. Doing this strongly enough lets the shorter, quicker rhythms come through clearly, the way turning down the bass on a stereo lets you suddenly hear the higher notes much better. Step 2: Tune in to one specific note Once the bass is turned down, the indicator tunes in like a radio dial to one particular rhythm — not too broad, not too narrow, just wide enough to catch one clean "note" (a repeating cycle of a certain length, like a monthly wave) without picking up static from neighboring notes. That's the "dominant cycle" — the main heartbeat the indicator has decided to track. Step 3: Make a copy that's a quarter-beat ahead Here's the clever part. Once it has that clean rhythmic note, the indicator makes a second version of it that's shifted slightly ahead in time — like clapping just a fraction of a second before the beat instead of on the beat. It does this with simple math (comparing the note's value now versus a couple of moments ago), which naturally produces something that leads the original by a quarter-cycle. Step 4: Blend the two into a custom forecast Now it has two versions of the same rhythm: the "on-beat" version and the "ahead-of-beat" version. By blending these two together in different proportions, it can dial in exactly how far ahead it wants to lean — a little ahead, or a lot ahead, like adjusting how early you want your alarm clock to go off. The result That blended, forward-leaning version is the forecast line (the blue line on the chart). It's the indicator's best attempt at saying "if this rhythm keeps behaving the way it has been, here's roughly where it's about to go next" — a few days or weeks before the rhythm actually gets there. The red line shows the wave the indicator has identified in the price — it's smoothing out all the noisy zigzags into one clean, readable rhythm.
The blue line is the indicator's forecast. It's designed to move slightly ahead of the red line — like a weather forecaster trying to predict tomorrow's temperature based on today's trend, rather than just reporting today's temperature after the fact.

When the blue line is above the red line and rising, that's the indicator's way of saying "I think this rhythm is about to turn upward." When it dips below and falls, it's leaning the other way.
The table on the right
Since one rhythm on one time scale (say, hourly) doesn't tell the whole story, the table checks the same wave-reading logic across four different "zoom levels" — hourly, daily, weekly, and monthly — like checking the tide at four different distances from shore.
Each one gets scored based on whether it's pointing up or down, but longer time frames count more, because a monthly trend is a much bigger, more meaningful signal than an hourly blip:

Monthly: worth 4 points
Weekly: worth 3 points
Daily: worth 2 points
Hourly: worth 1 point

Add them all up, and you get a score from -10 to +10. A +10 means every single time scale agrees the trend is up — about as strong an "all clear" signal as this tool can give. A -10 means everything agrees it's heading down. Anything in between means the different time scales disagree with each other — like the tide near the shore going one way while the tide further out is doing something else — which usually means it's a more uncertain, choppy moment to be reading too much into any single signal.
The honest caveat
This is a forecasting tool, not a crystal ball — it's built on the assumption that recent rhythms will continue a little longer, which is often true but not always. Think of it like a weather forecast: helpful for leaning one way or another, but not a guarantee.

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.