Advertisement
xmd79

Back to the Future

Jan 10th, 2023
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // Β© RafaelZioni
  3.  
  4. //@version=5
  5. indicator(title='Back to the Future', overlay=true)
  6. //INPUTS
  7. //
  8. len = input.int(100, minval=1)
  9. off = 0
  10. dev = input(2, 'Deviation')
  11. len1 = input.int(30, minval=1)
  12. off1 = 0
  13. dev1 = input(2, 'Deviation1')
  14. c1 = close
  15.  
  16. lreg1 = ta.linreg(c1, len, off)
  17. lreg_x1 = ta.linreg(c1, len, off + 1)
  18. b1 = bar_index
  19. s1 = lreg1 - lreg_x1
  20. intr1 = lreg1 - b1 * s1
  21. dS1 = 0.0
  22. for i1 = 0 to len - 1 by 1
  23. dS1 += math.pow(c1[i1] - (s1 * (b1 - i1) + intr1), 2)
  24. dS1
  25. de1 = math.sqrt(dS1 / len)
  26. up1 = -de1 * dev + lreg1
  27. down1 = de1 * dev + lreg1
  28. //
  29.  
  30. //
  31. t1 = 0
  32. x11 = bar_index - len
  33. x21 = bar_index
  34. y11 = s1 * (bar_index - len) + intr1
  35. y21 = lreg1
  36. u1 = t1 <= 0 or bar_index < t1
  37. if u1
  38. line pr1 = line.new(x11, y11, x21, y21, xloc.bar_index, extend.right, color.red, width=2)
  39. line.delete(pr1[1])
  40. line px1 = line.new(x11, de1 * dev + y11, x21, de1 * dev + y21, xloc.bar_index, extend.right, width=2)
  41. line.delete(px1[1])
  42. line pz1 = line.new(x11, -de1 * dev + y11, x21, -de1 * dev + y21, xloc.bar_index, extend.right, width=2)
  43. line.delete(pz1[1])
  44.  
  45. //
  46. c = close[len1]
  47.  
  48. lreg = ta.linreg(c, len1, off1)
  49. lreg_x = ta.linreg(c, len1, off1 + 1)
  50. b = bar_index
  51. s = lreg - lreg_x
  52. intr = lreg - b * s
  53. dS = 0.0
  54. for i = 0 to len1 - 1 by 1
  55. dS += math.pow(c[i] - (s * (b - i) + intr), 2)
  56. dS
  57. de = math.sqrt(dS / len1)
  58. up = -de * dev + lreg
  59. down = de * dev + lreg
  60. //
  61.  
  62. t = 0
  63. x1 = bar_index - len
  64. x2 = bar_index
  65. y1 = s * (bar_index - len) + intr
  66. y2 = lreg
  67. u = t <= 0 or bar_index < t
  68. if u
  69. line pr = line.new(x1, y1, x2, y2, xloc.bar_index, extend.right, color.red, style=line.style_dashed, width=2)
  70. line.delete(pr[1])
  71. line px = line.new(x1, de * dev + y1, x2, de * dev + y2, xloc.bar_index, extend.right, style=line.style_dashed, width=2)
  72. line.delete(px[1])
  73. line pz = line.new(x1, -de * dev + y1, x2, -de * dev + y2, xloc.bar_index, extend.right, style=line.style_dashed, width=2)
  74. line.delete(pz[1])
  75.  
  76.  
  77. //
  78. bu = ta.crossover(close, lreg)
  79. sz = ta.crossunder(close, lreg)
  80. bu1 = ta.crossover(close, up)
  81. sz1 = ta.crossunder(close, up)
  82. bu2 = ta.crossover(close, down)
  83. sz2 = ta.crossunder(close, down)
  84. plotshape(sz, style=shape.triangledown, location=location.abovebar, color=color.new(color.orange, 0), size=size.tiny)
  85. plotshape(bu, style=shape.triangleup, location=location.belowbar, color=color.new(color.blue, 0), size=size.tiny)
  86. plotshape(sz1, style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), size=size.tiny)
  87. plotshape(bu1, style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), size=size.tiny)
  88. plotshape(sz2, style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), size=size.tiny)
  89. plotshape(bu2, style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), size=size.tiny)
  90.  
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement