# [RS]Linear Regression Bull and Bear Power V0

‎2178‎ مشاهدة
2178
EXPERIMENTAL:
Bull and Bear power based on linear regression (this is a non lagging oscillator, the parameter are for the lookup window for the donchian extremes)
this indicator can also be used for convergence/divergence.
```//@version=2
study(title='[RS]Linear Regression Bull and Bear Power V0', shorttitle='BBP', overlay=false)
window = input(title='Lookback Window:', type=integer, defval=10)

f_exp_lr(_height, _length)=>
_ret = _height + (_height/_length)

h_value = highest(close, window)
l_value = lowest(close, window)

h_bar = n-highestbars(close, window)
l_bar = n-lowestbars(close, window)

bear = 0-f_exp_lr(h_value-close, n-h_bar)
bull = 0+f_exp_lr(close-l_value, n-l_bar)

plot(title='Bear', series=bear, style=columns, color=maroon)
plot(title='Bull', series=bull, style=columns, color=green)
```
Ricardo, just thinking out loud... would it be difficult to incorporate an accumation option into this script?

For example: sum up al bull bars (above the 0-line) and bear bars (below the 0-line) within a given time period (which would be an input).
رد
accidentjev2
its possible, ill have stab at it on the weekend
رد
RicardoSantos
done:
رد
RicardoSantos
Superb. Thanks man
رد
RicardoSantos
Ricardo, I've been playing with it and it would be very useful to make the script "multi-timeframe-able". Only I'm not succeeding in modifying it succesfully :). Could you take a last look?
رد
accidentje
> the accumulation version I mean
رد
accidentje
i can add a security() to get the values for higher timeframes, or you can use higher length values on the inputs to fit the higher timeframes.
the security is just a matter of adding 1/2 lines to the script(altho by using security its subject to repaint values when it re updates).
رد
RicardoSantos
I leave that decision up to you Ricardo since I don't fully grasp the implications. The idea is to have a view of the net bull-bear accumulation on the daily (for example), and underneath that the net accumulation on the weekly (or any higher timeframe, for example). So making the prefered timeframe an input would be ideal (preferably without having to calibrate length values). Thanks in advance!
رد
accidentje
done:
رد
RicardoSantos
Sweet, thanks again. Was indeed rather simple I now see ;)
رد