Détection range & trend
One heuristic approach:
1. fit a simple linear model to prices from t0…t1.
2. Find the times tmax where max(p(t)-fit(t)) and tmin where min(p(t)-fit(t)). So the times where we have maximum residual.
3. split the trend into 3 seperate trends
t0….tmin…tmax…t1 or t0….tmax…tmin…t1
depending whether tmin<tmax or vice versa.
4. So we split the long term trend t0…t1 with prices P(t0)..P(t1) into 3 trends. Based on the latest trend tmin…t1 or tmax…t1, fit prices in this window (with the same granularity or with based on more high-freq data). From the OLS regression, we obtain std(residuals) of last trend. You can use this std as an indicator for deciding if we are still in the range of last trend or breaking the range and moving to a new trend.
5. We even can go deeper, by using the maximum residuals of this last trend…etc and goto step 3 until max(residual)<stopping criteria
This method can also be used for compression of the timeseries