RicardoSantos

Function Linear Decay V2

EXPERIMENTAL:
improved range detection (it now locks range when its last formed on the appropriate side improving readability as it doesnt auto adjust when opposite extreme moves)
סקריפט קוד פתוח

ברוח TradingView אמיתית, מחבר הסקריפט הזה פרסם אותו בקוד פתוח, כך שסוחרים יכולים להבין ולאמת אותו. כל הכבוד למחבר! אתה יכול להשתמש בו בחינם, אך שימוש חוזר בקוד זה בפרסום כפוף לכללי הבית. אתה יכול להכניס אותו למועדפים כדי להשתמש בו בגרף.

כתב ויתור

המידע והפרסומים אינם אמורים להיות, ואינם מהווים, עצות פיננסיות, השקעות, מסחר או סוגים אחרים של עצות או המלצות שסופקו או מאושרים על ידי TradingView. קרא עוד בתנאים וההגבלות.

רוצה להשתמש בסקריפ זה בגרף?
//@version=2
study(title='Function Linear Decay V2', shorttitle='F', overlay=true)
window = input(100)
exponent = input(type=float, defval=1.0)
//rate = input(0.01)
f_linear_decay(_base_rate, _event_value, _n_since_event)=>_event_value + _base_rate * _n_since_event

h_value = na(h_value[1]) ? high : high >= highest(window) ? high : h_value[1]
l_value = na(l_value[1]) ? low : low <= lowest(window) ? low : l_value[1]

h_bar = na(h_bar[1]) ? n : change(h_value) != 0 ? n : h_bar[1]
l_bar = na(l_bar[1]) ? n : change(l_value) != 0 ? n : l_bar[1]

h_range = na(h_range[1]) ? h_value-l_value : change(h_value) != 0 ? h_value-l_value : h_range[1]
l_range = na(l_range[1]) ? h_value-l_value : change(l_value) != 0 ? h_value-l_value : l_range[1]

n_h_bars = pow(n-h_bar, exponent)
n_l_bars = pow(n-l_bar, exponent)

decay01 = max(l_value, f_linear_decay(0-h_range*0.1, h_value, n_h_bars))
decay02 = max(l_value, f_linear_decay(0-h_range*0.05, h_value, n_h_bars))
decay03 = max(l_value, f_linear_decay(0-h_range*0.025, h_value, n_h_bars))
decay04 = max(l_value, f_linear_decay(0-h_range*0.01, h_value, n_h_bars))
decay05 = max(l_value, f_linear_decay(0-h_range*0.005, h_value, n_h_bars))
decay06 = max(l_value, f_linear_decay(0-h_range*0.0025, h_value, n_h_bars))
decay07 = max(l_value, f_linear_decay(0-h_range*0.001, h_value, n_h_bars))
decay08 = max(l_value, f_linear_decay(0-h_range*0.0005, h_value, n_h_bars))
decay09 = max(l_value, f_linear_decay(0-h_range*0.00025, h_value, n_h_bars))
decay10 = max(l_value, f_linear_decay(0-h_range*0.0001, h_value, n_h_bars))
growth01 = min(h_value, f_linear_decay(0+l_range*0.1, l_value, n_l_bars))
growth02 = min(h_value, f_linear_decay(0+l_range*0.05, l_value, n_l_bars))
growth03 = min(h_value, f_linear_decay(0+l_range*0.025, l_value, n_l_bars))
growth04 = min(h_value, f_linear_decay(0+l_range*0.01, l_value, n_l_bars))
growth05 = min(h_value, f_linear_decay(0+l_range*0.005, l_value, n_l_bars))
growth06 = min(h_value, f_linear_decay(0+l_range*0.0025, l_value, n_l_bars))
growth07 = min(h_value, f_linear_decay(0+l_range*0.001, l_value, n_l_bars))
growth08 = min(h_value, f_linear_decay(0+l_range*0.0005, l_value, n_l_bars))
growth09 = min(h_value, f_linear_decay(0+l_range*0.00025, l_value, n_l_bars))
growth10 = min(h_value, f_linear_decay(0+l_range*0.0001, l_value, n_l_bars))

plot(l_value, style=circles, color=lime, linewidth=1, transp=0)
plot(decay01, color=black, linewidth=1, transp=0)
plot(decay02, color=black, linewidth=1, transp=10)
plot(decay03, color=black, linewidth=1, transp=20)
plot(decay04, color=black, linewidth=1, transp=30)
plot(decay05, color=black, linewidth=1, transp=40)
plot(decay06, color=black, linewidth=1, transp=50)
plot(decay07, color=black, linewidth=1, transp=60)
plot(decay08, color=black, linewidth=1, transp=70)
plot(decay09, color=black, linewidth=1, transp=80)
plot(decay10, color=black, linewidth=1, transp=90)

plot(h_value, style=circles, color=red, linewidth=1, transp=0)
plot(growth01, color=black, linewidth=1, transp=0)
plot(growth02, color=black, linewidth=1, transp=10)
plot(growth03, color=black, linewidth=1, transp=20)
plot(growth04, color=black, linewidth=1, transp=30)
plot(growth05, color=black, linewidth=1, transp=40)
plot(growth06, color=black, linewidth=1, transp=50)
plot(growth07, color=black, linewidth=1, transp=60)
plot(growth08, color=black, linewidth=1, transp=70)
plot(growth09, color=black, linewidth=1, transp=80)
plot(growth10, color=black, linewidth=1, transp=90)

plot(h_value-h_range, color=red)
plot(l_value+l_range, color=lime)