xmd79

Linear Regression Fan [LUX]

Oct 11th, 2021
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. // 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/
  2. // © LuxAlgo
  3.  
  4. //@version=4
  5. study("Linear Regression Fan [LUX]",overlay=true,max_bars_back=2000,max_lines_count=500)
  6. length = input(100)
  7. mult = input(2.)
  8. N = input(4,'Lines Per Side')
  9. src = input(close)
  10. //----
  11. up_col = input(#2157f3,'Fan Colors',inline='color')
  12. mid_col = input(#ff5d00,'',inline='color')
  13. dn_col = input(#ff1100,'',inline='color')
  14. //------------------------------------------------------------------------------
  15. var L1 = array.new_line(0)
  16. var L2 = array.new_line(0)
  17. if barstate.isfirst
  18. for i = 0 to N-1
  19. array.push(L1,line.new(na,na,na,na))
  20. array.push(L2,line.new(na,na,na,na))
  21. //------------------------------------------------------------------------------
  22. n = bar_index
  23. wma = wma(src,length)
  24. sma = sma(src,length)
  25. a = 4*sma-3*wma
  26. b = 3*wma-2*sma
  27. //------------------------------------------------------------------------------
  28. v = variance(src,length)
  29. array.from(0.236,0.382,0.5,0.618,0.786,1.)
  30. dev = sqrt(v - v*pow(correlation(src,n,length),2))*mult
  31. //------------------------------------------------------------------------------
  32. if barstate.islast
  33. line.delete(line.new(n-length+1,a+dev,n,b+dev,color=up_col,style=line.style_dashed)[1])
  34. line.delete(line.new(n-length+1,a,n,b,color=mid_col)[1])
  35. line.delete(line.new(n-length+1,a-dev,n,b-dev,color=dn_col,style=line.style_dashed)[1])
  36. k = 0.
  37. for i = 0 to N-1
  38. k += 1/N
  39.  
  40. l1 = array.get(L1,i)
  41. line.set_xy1(l1,n-length+1,a)
  42. line.set_xy2(l1,n,b+k*dev)
  43. line.set_color(l1,up_col)
  44.  
  45. l2 = array.get(L2,i)
  46. line.set_xy1(l2,n-length+1,a)
  47. line.set_xy2(l2,n,b-k*dev)
  48. line.set_color(l2,dn_col)
Advertisement
Add Comment
Please, Sign In to add comment