#### BenTen

##### Administrative

**Staff**

**VIP**

Onset Trend Detector is an indicator for ThinkorSwim that will give buy and sell signals. This script was developed by John F. Ehlers.

thinkScript Code

Shareable Link

https://tos.mx/aQbyVg

>Configure two lower studies

>[1] cutoffLength = 20 / k = 0.8

>[2] cutoffLength = 20 / k = 0.4

>Rules:

>[1] Buy when the first 30-period QT with K = 0.8 crosses 0 from below

>[2] Sell the position when the second 30-period QT with K = 0.4 crosses 0 from above

thinkScript Code

Rich (BB code):

```
declare lower;
input price = close;
input cutoffLength = 10;
input k = .8;
def alpha1 = (Cos(Sqrt(2) * Double.Pi / 100) + Sin (Sqrt(2) * Double.Pi / 100) - 1) / Cos(Sqrt(2) * Double.Pi / 100);
def highpass = if IsNaN(price + price[1] + price[2]) then highpass[1] else Sqr(1 - alpha1 / 2) * (price - 2 * price[1] + price[2]) + 2 * (1 - alpha1) * highpass[1] - Sqr(1 - alpha1) * highpass[2];
def filt = reference EhlersSuperSmootherFilter(highpass, cutoffLength);
def peak = if AbsValue(filt) > peak[1] * .991 then AbsValue(filt) else peak[1] * .991;
plot NormRoofingFilter = filt / peak;
plot Quotient = (NormRoofingFilter + k) / (k * NormRoofingFilter + 1);
plot ZeroLine = 0;
NormRoofingFilter.SetDefaultColor(GetColor(1));
Quotient.SetDefaultColor(GetColor(2));
ZeroLine.SetDefaultColor(GetColor(7));
```

Shareable Link

https://tos.mx/aQbyVg

Last edited: