Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
- // © LuxAlgo
- //@version=4
- study("Linear Regression Fan [LUX]",overlay=true,max_bars_back=2000,max_lines_count=500)
- length = input(100)
- mult = input(2.)
- N = input(4,'Lines Per Side')
- src = input(close)
- //----
- up_col = input(#2157f3,'Fan Colors',inline='color')
- mid_col = input(#ff5d00,'',inline='color')
- dn_col = input(#ff1100,'',inline='color')
- //------------------------------------------------------------------------------
- var L1 = array.new_line(0)
- var L2 = array.new_line(0)
- if barstate.isfirst
- for i = 0 to N-1
- array.push(L1,line.new(na,na,na,na))
- array.push(L2,line.new(na,na,na,na))
- //------------------------------------------------------------------------------
- n = bar_index
- wma = wma(src,length)
- sma = sma(src,length)
- a = 4*sma-3*wma
- b = 3*wma-2*sma
- //------------------------------------------------------------------------------
- v = variance(src,length)
- array.from(0.236,0.382,0.5,0.618,0.786,1.)
- dev = sqrt(v - v*pow(correlation(src,n,length),2))*mult
- //------------------------------------------------------------------------------
- if barstate.islast
- line.delete(line.new(n-length+1,a+dev,n,b+dev,color=up_col,style=line.style_dashed)[1])
- line.delete(line.new(n-length+1,a,n,b,color=mid_col)[1])
- line.delete(line.new(n-length+1,a-dev,n,b-dev,color=dn_col,style=line.style_dashed)[1])
- k = 0.
- for i = 0 to N-1
- k += 1/N
- l1 = array.get(L1,i)
- line.set_xy1(l1,n-length+1,a)
- line.set_xy2(l1,n,b+k*dev)
- line.set_color(l1,up_col)
- l2 = array.get(L2,i)
- line.set_xy1(l2,n-length+1,a)
- line.set_xy2(l2,n,b-k*dev)
- line.set_color(l2,dn_col)
Advertisement
Add Comment
Please, Sign In to add comment