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.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Per un accesso rapido a un grafico, aggiungi questo script ai tuoi preferiti: per saperne di più clicca qui.
Declinazione di responsabilità
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Per un accesso rapido a un grafico, aggiungi questo script ai tuoi preferiti: per saperne di più clicca qui.