本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// TASC Issue: December 2026
// Article: A Trend Indicator
// The Jack & Jill Indicator
// Article By: John F. Ehlers
// Language: TradingView's Pine Script® v6
// Provided By: PineCoders, for tradingview.com
//@version=6
string TITLE = "TASC 2026.12 The Jack & Jill Indicator"
string SHORTTITLE = "J&J"
indicator(TITLE, SHORTTITLE)
//#region --- Inputs ---
float periodInput = input.float(20.0, "Period", minval = 2.0)
int rmsLengthInput = input.int(81, "RMS length", minval = 1)
bool showPlotsInput = input.bool(true, "Show overlay plots")
//#endregion
//#region --- Functions ---
//@function Calculates the root mean square (RMS) of a
// series over a specified number of bars.
//@param source The series of values to process.
//@param length The number of bars in the calculation.
//@returns The RMS series.
rms(float source, int length) =>
nz(math.sqrt(ta.sma(source * source, length)))
//@function Calculates the SuperSmoother with a specified
// critical period. The SuperSmoother is a
// second-order IIR filter. Its transfer response
// includes a second-degree polynomial in the
// denominator. The filter offers significantly
// greater maximum attenuation of high frequencies,
// without a perceptibly greater amount of
// computational lag.
//@param source The series of values to process.
//@param period The filter's critical period.
//@returns The smoothed series.
superSmoother(float source, float period) =>
float w = 1.414 * math.pi / period
float q = math.exp(-w)
float c1 = 2.0 * q * math.cos(w)
float c2 = q * q
float a0 = (1.0 - c1 + c2) / 2.0
float res = source
if bar_index >= 4
res := (
a0 * (source + source[1])
+ c1 * res[1] - c2 * res[2]
)
res
//#endregion
//#region --- Calculations ---
//@variable Jack's adaptive period for the next bar.
var float jackPeriod = 20.0
//@variable Jill's contra-adaptive period for the next bar.
var float jillPeriod = 20.0
//@variable The Adaptive SuperSmoother of the `close` series.
float jack = superSmoother(close, jackPeriod)
// Calculate the normalized one-bar rate of change (ROC) for Jack's period.
float jackD = ta.change(jack)
float jackRMS = rms(jackD, rmsLengthInput)
float jackROC = jackRMS != 0.0 ? math.min(2.0, math.abs(jackD / jackRMS)) : 0.0
// Calculate the next bar's adaptive period for Jack.
float jackDM = 1.0 - 0.5 * jackROC
jackPeriod := math.max(2.0, periodInput * jackDM * jackDM)
//@variable The contra-adaptive SuperSmoother of the `close` series.
float jill = superSmoother(close, jillPeriod)
// Calculate the normalized ROC for Jill's period.
float jillD = ta.change(jill)
float jillRMS = rms(jillD, rmsLengthInput)
float jillROC = jillRMS != 0.0 ? math.min(2.0, math.abs(jillD / jillRMS)) : 0.0
// Calculate the next bar's contra-adaptive period for Jill.
float jillDM = 1.0 + 0.5 * jillROC
jillPeriod := periodInput * jillDM * jillDM
//#endregion
//#region --- Display ---
// Main chart display
plotDisplay = showPlotsInput ? display.all : display.all - display.pane
plot(jack, "Jack", color.blue, force_overlay = true, display = plotDisplay)
plot(jill, "Jill", color.red, force_overlay = true, display = plotDisplay)
// Oscillator pane display
plot(jack - jill, "Oscillator", color.blue)
hline(0, "Zero")
//#endregion