Indicator · Pine Script v5 · Own pane

John F. Ehlers - Convolution

by palitojendthen

Implements John F.

View on GitHub

GitHub stars20on the repository
Pine versionv5runs as is
Lines of code170
Settings2inputs
LicenceNone statedfile: MPL-2.0
Last update1 year ago12 Jul 2025

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

170 lines of Pine Script v5 from indicator/convolution.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

convolution.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © palitoj_endthen

//@version=5
indicator(title = 'John F. Ehlers - Convolution', shorttitle = 'convolution', overlay = false)

// input
src = input.source(defval = ohlc4, title = 'Source', group = 'Options', tooltip = 'Determines the source of input data', inline = 'f')
apply_hp = input.bool(defval = false, title = 'High-Pass Filter', group = 'Options', tooltip = 'Determines whether to apply High-Pass filter', inline = 'f')


// variable
shortest_period = 40
longest_period = 80
alpha1 = 0.00
hp = 0.00
a1 = 0.00
b1 = 0.00
c1 = 0.00
c2 = 0.00
c3 = 0.00
filt = 0.00
x = 0.00
y = 0.00
sx = 0.00
sy = 0.00
sxx = 0.00
syy = 0.00
sxy = 0.00


// array
var corr = array.new_float(50)
var slope = array.new_float(50)
var convolution = array.new_float(50)


// convolution
// high-pass filter cyclic components whose periods are shorter than 48 bars
alpha1 := (math.cos(1.414*360/longest_period)+math.sin(1.414*360/longest_period)-1)/math.cos(1.414*360/longest_period)
hp := (1-alpha1/2)*(1-alpha1/2)*(src-2*src[1]+src[2])+2*(1-alpha1)*nz(hp[1])-(1-alpha1)*(1-alpha1)*nz(hp[2])

// smooth with super smoother filter
pi = 2*math.asin(1)
a1 := math.exp(-1.414*pi/shortest_period)
b1 := 2*a1*math.cos(1.414*180/shortest_period)
c2 := b1
c3 := -a1*a1
c1 := 1-c2-c3
filt := c1*((apply_hp?hp:src)+(apply_hp?hp[1]:src[1]))/2+c2*nz(filt[1])+c3*nz(filt[2])

// convolution
for i = 1 to 48
    sx := 0.0
    sy := 0.0
    sxx := 0.0
    syy := 0.0
    sxy := 0.0
    for ii = 1 to i
        x := filt[ii-1]
        y := filt[i-ii]
        sx := sx+x
        sy := sy+y
        sxx := sxx+x*x
        sxy := sxy+x*y
        syy := syy+y*y
    if (i*sxx-sx*sx)*(i*syy-sy*sy) > 0
        array.set(corr, i, ((i*sxy-sx*sy) /math.sqrt((i*sxx-sx*sx)*(i*syy-sy*sy))))
    array.set(slope, i, 1)
    if filt[.5*i] < filt
        array.set(slope, i, -1)
    array.set(convolution, i, (1+math.exp(3*nz(array.get(corr, i))))-1/(math.exp(3*nz(array.get(corr, i))-1))/2)


// visualize as heatmap
// color condition
col(n)=>
    if array.get(slope, n) > 0
        color.rgb((255*array.get(convolution, n)), 0, 0)
    else if array.get(slope, n) < 0
        color.rgb(0, (255*array.get(convolution, n)), 0)

// plot
n = 0
n := 2
plot(n, title = 'n2', color = col(n), linewidth = 8)

n := 3
plot(n, title = 'n3', color = col(n), linewidth = 8)

n := 4
plot(n, title = 'n4', color = col(n), linewidth = 8)

n := 6
plot(n, title = 'n6', color = col(n), linewidth = 8)

n := 8
plot(n, title = 'n8', color = col(n), linewidth = 8)

n := 10
plot(n, title = 'n10', color = col(n), linewidth = 8)

n := 11
plot(n, title = 'n11', color = col(n), linewidth = 8)

n := 12
plot(n, title = 'n12', color = col(n), linewidth = 8)

n := 14
plot(n, title = 'n14', color = col(n), linewidth = 8)

n := 16
plot(n, title = 'n16', color = col(n), linewidth = 8)

n := 18
plot(n, title = 'n18', color = col(n), linewidth = 8)

n := 20
plot(n, title = 'n20', color = col(n), linewidth = 8)

n := 21
plot(n, title = 'n21', color = col(n), linewidth = 8)

n := 22
plot(n, title = 'n22', color = col(n), linewidth = 8)

n := 24
plot(n, title = 'n24', color = col(n), linewidth = 8)

n := 26
plot(n, title = 'n26', color = col(n), linewidth = 8)

n := 28
plot(n, title = 'n28', color = col(n), linewidth = 8)

n := 30
plot(n, title = 'n30', color = col(n), linewidth = 8)

n := 31
plot(n, title = 'n31', color = col(n), linewidth = 8)

n := 32
plot(n, title = 'n32', color = col(n), linewidth = 8)

n := 34
plot(n, title = 'n34', color = col(n), linewidth = 8)

n := 36
plot(n, title = 'n36', color = col(n), linewidth = 8)

n := 38
plot(n, title = 'n38', color = col(n), linewidth = 8)

n := 40
plot(n, title = 'n40', color = col(n), linewidth = 8)

n := 41
plot(n, title = 'n41', color = col(n), linewidth = 8)

n := 42
plot(n, title = 'n42', color = col(n), linewidth = 8)

n := 44
plot(n, title = 'n44', color = col(n), linewidth = 8)

n := 46
plot(n, title = 'n46', color = col(n), linewidth = 8)

n := 48
plot(n, title = 'n48', color = col(n), linewidth = 8)

Overview

Ehlers' convolution algorithm to detect cyclic components across multiple periods. The script processes price data using a SuperSmoother filter with an optional high-pass filter to remove low-frequency trends. It computes cross-correlations across up to 48 lookback bars and renders the output as a multi-tier heatmap in a separate pane, where red and green intensities reflect convolution magnitude and directional slope.

Details

Published by

palitojendthen on GitHub

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Oscillators & momentum, Trend

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

indicatortechnical-analysispinescripttrading-algorithms

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Sourcesourceohlc4src
High-Pass Filterboolfalseapply_hp
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Schaff Trend Cycle

by everget
948 stars

This indicator plots the Schaff Trend Cycle in a separate pane. It subtracts a slow exponential moving average from a fast one, applies a stochastic cycle twice, and smooths each result to form a 0–100 oscillator. Line color follows the slope, or the upper and

Indicator v4 Oscillators & momentumTrend
Updated 10 days ago · GPL-3.0 GitHub repository of Schaff Trend Cycle

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop

[RS]Standardized Trend Map

by ricardosantos79
261 stars

Standardized Trend Map calculates series momentum relative to active price range across 40 distinct lookback periods ranging from 2 to 80 bars on an exponential moving average source. Each standardized calculation rounds to an integer values of -1, 0, or 1 to

Indicator v4 TrendOscillators & momentum
Updated 4 years ago · None stated GitHub repository of [RS]Standardized Trend Map

ADX Histogram

by harryguiacorn
219 stars

This indicator calculates and displays the Average Directional Index (ADX) as a column histogram in a separate pane. It evaluates market trend strength by calculating directional movement metrics based on specified smoothing and DI length inputs. When the ADX

Indicator v5 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of ADX Histogram
218 stars

Multi-Timeframe Analysis Suite calculates trend direction and momentum conditions across five user-selected timeframes using moving averages, RSI, and Stochastic oscillators. It evaluates moving average slope and oscillator levels to compute trend alignment, m

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers