RicardoSantos

[RS]Linear Regression Bull and Bear Power Accumulation V1

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.
(accidentjev2) added multi timeframe support (indicator may repaint values)
สคริปต์โอเพนซอร์ซ

ด้วยจิตวิญญาณของ TradingView อย่างแท้จริง ผู้เขียนสคริปต์นี้ได้เผยแพร่เป็นโอเพนซอร์ส เพื่อให้ผู้ค้าสามารถเข้าใจและตรวจสอบได้ ไชโยให้กับผู้เขียน! คุณสามารถใช้ได้ฟรี แต่การใช้รหัสนี้ซ้ำในสิ่งพิมพ์อยู่ภายใต้กฎระเบียบการใช้งาน คุณสามารถตั้งเป็นรายการโปรดเพื่อใช้บนชาร์ตได้

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมที่ เงื่อนไขการใช้บริการ

ต้องการที่จะใช้สคริปต์นี้บนชาร์ตใช่ไหม?
//@version=2
study(title='[RS]Linear Regression Bull and Bear Power Accumulation V1', shorttitle='BBPa', overlay=false)
SHOW_REM = input(title='Show as (bull-bear)?', type=bool, defval=false)
SHOW_ACC = input(title='Show as accumulation?', type=bool, defval=true)
window = input(title='Lookback Window:', type=integer, defval=10)
smoothing = input(title='Smoothing Length:', type=integer, defval=4)
acc_length = input(title='Accumulation Length:', type=integer, defval=100)
USE_ALT_TF = input(title='Use alternative timeframe?', type=bool, defval=false)
alt_tf = input(title='Alternative timeframe:', type=string, defval='D', confirm=false)

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)

bear_acc = sum(nz(bear, 0), acc_length)
bull_acc = sum(nz(bull, 0), acc_length)

rem = SHOW_ACC ? bull_acc-abs(bear_acc) : bull - abs(bear)
rem_bull = rem > 0 ? rem : 0
rem_bear = rem < 0 ? rem : 0

bear_output = USE_ALT_TF ? security(tickerid, alt_tf, SHOW_REM?rem_bear:SHOW_ACC?bear_acc:bear) : SHOW_REM?rem_bear:SHOW_ACC?bear_acc:bear
bull_output = USE_ALT_TF ? security(tickerid, alt_tf, SHOW_REM?rem_bull:SHOW_ACC?bull_acc:bull) : SHOW_REM?rem_bull:SHOW_ACC?bull_acc:bull

plot(title='Bear', series=bear_output, style=columns, color=maroon)
plot(title='Bull', series=bull_output, style=columns, color=green)