Segment Regression

A trick used is to restart the new inference segment
- from the maximum reached in the previous trend, when positive (slope>0)
- from the minimum reached in the previous trend, when negative (slope<0)
The result can in my opinion be easily used to build strategies.
added a line to determine a channel, not considering a fixed number of bars to avoid the obvious impact of the last lines before the breakout
The study presented here extends the classic 'linear regression' to that of 'segmental linear regression'.
The linreg() tool is therefore assumed to be known, which is initially applied without any variation, with the starting point equal to the first bar of the graph and with a minimum number of bars equal to those expected.
At each subsequent frame, then:
1) the percentage distance between the real value and the one inferred with the current regression segment is evaluated
2) if this calculated percentage distance is lower than the desired one or if it has the same sign as the slope of the current regression segment, nothing is done
3) if this percentage distance is higher than the desired one in the opposite direction to the slope of the regression segment, the starting point of the new regression segment is updated with
3.1) the point where the previous graph touched the minimum, if the slope of the previous inference segment was negative
3.2) the point where the previous graph touched the maximum, if the slope of the previous inference segment was positive
Please note that in the moments in which the graph is lateral, the slope of the regression segment can change sign even without activating point 3) above.
Ultimately, you get an indicator that is able to follow the graph in a much more adequate way than an ordinary linear regression.
It is my opinion that with this indicator as a starting point, good strategies can be implemented.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda — ketahui lebih lanjut di sini.
Penafian
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda — ketahui lebih lanjut di sini.