# Function Linear Decay V0

EXPERIMENTAL:
simple function for linear decay.

Skript med en öppen källkod

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Frånsägelse av ansvar

Vill du använda det här skriptet i ett diagram?
```//@version=2
study(title='Function Linear Decay V0', shorttitle='F', overlay=true)
window = input(100)
//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]

range = h_value - l_value

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

plot(l_value, style=circles, color=gray, 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=gray, 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)
```