// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © PineCodersTASC // TASC Issue: September 2024 // Article: Precision Trend Analysis. // A New Way To Pinpoint Trend. // Article By: John F. Ehlers // Language: TradingView's Pine Script™ v5 // Provided By: PineCoders, for tradingview.com //@version=5 title ="TASC 2024.09 Precision Trend Analysis" stitle = "Trend Analysis" indicator(title, stitle, false) // --- Inputs --- int length01 = input.int(250, "Length 1:") int length02 = input.int( 40, "Length 2:") // --- Functions --- // Highpass Filter highPass(float Price, float Period) => float a1 = math.exp(-1.414 * math.pi / Period) float b1 = 2 * a1 * math.cos(1.414 * math.pi / Period) float c2 = b1 float c3 = -a1 * a1 float c1 = (1 + c2 - c3) / 4 float hp = 0.0 if bar_index >= 4 hp := c1 * (Price - 2 * Price[1] + Price[2]) + c2 * nz(hp[1]) + c3 * nz(hp[2]) hp // --- Calculations --- float HP1 = highPass(close, length01) float HP2 = highPass(close, length02) float Trend = HP1 - HP2 float ROC = (length02 / 6.28) * ta.change(Trend) bool upROC = ta.crossunder(ROC, 0) and Trend < 0 bool dwROC = ta.crossover(ROC, 0) and Trend > 0 // --- Visuals --- color colTrend = Trend > 0 ? #4daf4a : #e41a1c plot(Trend, "Trend Indicator", colTrend, 2) plot(ROC, "ROC", #377eb8, 2, plot.style_histogram) hline(0.0, "Zero Point") plotshape(upROC ? ROC : na, "Peak", shape.triangledown, location.absolute, #e41a1c, size = size.tiny) plotshape(dwROC ? ROC : na, "Valley", shape.triangleup, location.absolute, #4daf4a, size = size.tiny) barcolor(colTrend, editable = true)