Hi, everyone, I've benefited greatly from many posts here, so wanted to share this that I created from the TASC article by John Ehlers. He calls it the Precision Trend Indicator.
John Ehlers introduces this method that uses two filters to remove unwanted "noise" from price data. These filters react very quickly to price changes, meaning the trend indicator they create closely follows the ups and downs of the market. When the indicator is above zero, it signals an uptrend, and when it's below zero, it indicates a downtrend. This makes it a helpful tool for spotting changes in market direction.
I have always been fascinated by Ehlers' work, especially the decycler and supersmoother. If anyone has ideas on how to use this indicator, please share. I'm not sure how useful it will be but it wasn't coded up in the TASC so I figured I'd take a try at it. [NOTE EDITED AS I MISPASTED THE FIRST VERSION!!!]
John Ehlers introduces this method that uses two filters to remove unwanted "noise" from price data. These filters react very quickly to price changes, meaning the trend indicator they create closely follows the ups and downs of the market. When the indicator is above zero, it signals an uptrend, and when it's below zero, it indicates a downtrend. This makes it a helpful tool for spotting changes in market direction.
I have always been fascinated by Ehlers' work, especially the decycler and supersmoother. If anyone has ideas on how to use this indicator, please share. I'm not sure how useful it will be but it wasn't coded up in the TASC so I figured I'd take a try at it. [NOTE EDITED AS I MISPASTED THE FIRST VERSION!!!]
Ruby:
# TASC 2024.09 Precision Trend Analysis
# Converted to ThinkScript for thinkorswim
# Original by John F. Ehlers
declare lower;
input length01 = 250;
input length02 = 40;
def PI = 3.14159265359;
# High-pass filter calculations
def a1 = Exp(-1.414 * PI / length01);
def b1 = 2 * a1 * Cos(1.414 * PI / length01);
def c2 = b1;
def c3 = -a1 * a1;
def c1 = (1.0 + c2 - c3) * 0.25;
rec HP1 = if BarNumber() >= 4 then
c1 * (close - 2 * close[1] + close[2]) + c2 * HP1[1] + c3 * HP1[2]
else
0;
def a2 = Exp(-1.414 * PI / length02);
def b2 = 2 * a2 * Cos(1.414 * PI / length02);
def c22 = b2;
def c33 = -a2 * a2;
def c11 = (1.0 + c22 - c33) * 0.25;
rec HP2 = if BarNumber() >= 4 then
c11 * (close - 2 * close[1] + close[2]) + c22 * HP2[1] + c33 * HP2[2]
else
0;
def Trend = HP1 - HP2;
def ROC = (length02 / 6.28) * (Trend - Trend[1]);
plot TrendLine = Trend;
plot ROCLine = ROC;
plot ZeroLine = 0;
TrendLine.SetDefaultColor(GetColor(1));
TrendLine.SetLineWeight(2);
ROCLine.SetDefaultColor(GetColor(5));
ROCLine.SetLineWeight(2);
ZeroLine.SetDefaultColor(GetColor(0));
def Peak = if ROC crosses below 0 and Trend < 0 then ROC else Double.NaN;
def Valley = if ROC crosses above 0 and Trend > 0 then ROC else Double.NaN;
plot PeakMarker = Peak;
plot ValleyMarker = Valley;
PeakMarker.SetPaintingStrategy(PaintingStrategy.POINTS);
PeakMarker.SetLineWeight(3);
PeakMarker.SetDefaultColor(GetColor(1));
ValleyMarker.SetPaintingStrategy(PaintingStrategy.POINTS);
ValleyMarker.SetLineWeight(3);
ValleyMarker.SetDefaultColor(GetColor(2));
# Dynamic coloring
TrendLine.AssignValueColor(if Trend > 0 then Color.GREEN else Color.RED);
#AssignPriceColor(if Trend > 0 then Color.GREEN else Color.RED);
Last edited by a moderator: