LINEAR REGRESSION CENTERLINE EXCURSION
A Very Fast Directional Indicator[link]http://tos.mx/567RIwO[/link]
DESCRIPTION
This indicator works as a moving average crossover, plotting the difference between the linear regression curve of the CLOSE price and the curve of the HL2 (HIGH + LOW / 2) curve of the same length.
While the indicator can be very good at picking changes in direction, it -- like all moving average crossovers -- can whipsaw. There is a smoothing option added which will apply the smoothing of your choice to the indicator signal. If you are using it alone to enter or exit, adjusting the smoothing may help avoid whipsaws. If you are using it as confirmation, it is faster without smoothing. I use lengths between 20 and 30 for the linear regression normally and find them very fast and also fairly reliable.
USAGE
Enter when the indicator crosses above zero and exit when it goes below. There are some screen shots below somewhere.
Code:
####################################################
#
# LINEAR REGRESSION CENTERLINE EXCURSION
#
# A very fast directional indicator
# with optional smoothing
#
# by mashume for the usethinkscript.com community
#
# 2022.03.28
#
# Released the MIT License as open source
# (c) mashume 2022
#
####################################################
declare lower;
input length = 20;
input smoothed = {default "no", "yes"};
input smoothing = AverageType.SIMPLE;
input smooth_length = 3;
def base;
def signal;
switch (smoothed) {
CASE "no":
base = Inertia(HL2, length);
signal = Inertia(CLOSE, length);
CASE "yes":
base = MovingAverage(averageType = smoothing, length = smooth_length, data = Inertia(HL2, length));
signal = MovingAverage(averageType = smoothing, length = smooth_length, data = Inertia(CLOSE, length));
}
plot indicator = signal - base;
indicator.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
indicator.AssignValueColor( if indicator >= 0 then color.green else color.red);
plot zero = 0;
EYE CANDY AND DESCRIPTION
This is not investment advice.Several new indicators are included in this screen shot. But I'm lazy and only did one write up. You can find the other threads somewhere on usethinkscript.com
A
The LINEAR REGRESSION CENTERLINE EXCURSION indicator shows a clear enter signal which lasts nicely through the bulk of the upward movement.
B
The PRICE ACTION within LINEAR REGRESSION CHANNEL indicator shows a squeeze and a bounce off the lower line which corresponds nicely with a move upward in the price chart.
C
The LINEAR REGRESSION CENTERLINE EXCURSION indicator shows a good short signal, though the signal does not last as long as the downward trend.
D
Fourier RMS shows an increase in short term energy as a proportion of the total energy (the blue line rises and the red falls).
E
Fourier RMS shows an dramatic decrease in the short term (blue) line and a distinct rise in the long term (red).