Advertisement
Guest User

u/ZanderDogz HA Reversal TV Script

a guest
Jun 13th, 2022
1,400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 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/ // © zander
  2. //@version=5
  3. indicator("HA Reversal", overlay = true)
  4. //RRS
  5.  
  6. comparedWithSecurity = input.symbol(title="Compare With", defval="SPY")
  7. lengths = input(title="Length", defval=12)
  8.  
  9. //##########Rolling Price Change##########
  10.  
  11. comparedClose = request.security(symbol=comparedWithSecurity, timeframe="", expression=close)
  12. comparedRollingMove = comparedClose - comparedClose[lengths]
  13. symbolRollingMove = close - close[lengths]
  14.  
  15. //##########Rolling ATR Change##########
  16.  
  17. symbolRollingATR = ta.atr(lengths)[1]
  18. comparedRollingATR = request.security (symbol=comparedWithSecurity, timeframe="", expression= ta.atr(lengths)[1])
  19.  
  20. //##########Calculations##########
  21.  
  22. powerIndex = comparedRollingMove / comparedRollingATR
  23. RRS = (symbolRollingMove - powerIndex * symbolRollingATR) / symbolRollingATR
  24.  
  25. //##########Plot##########
  26.  
  27. RealRelativeStrength = plot(RRS, "RealRelativeStrength", color=color.blue)
  28. Baseline = plot(0, "Baseline", color=color.red)
  29.  
  30. //##########Extra Stuff##########
  31.  
  32. fill(RealRelativeStrength, Baseline, color = RRS >= 0 ? color.green : color.red, title="fill")
  33. correlated = ta.correlation(close, comparedClose, lengths)
  34.  
  35. //HA Definitions
  36.  
  37. mid = (open[1] + close[1])/2
  38. currentmid = (open+high+low+close)
  39. flatBottom = mid < low
  40. flatTop = mid > high
  41. height = currentmid - mid
  42. biggerlong = height > height[1]
  43. biggershort = height < height[1]
  44.  
  45. //BBandWidth
  46.  
  47. length = input.int(10, minval=1)
  48. src = input(close, title="Source")
  49. mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
  50. basis = ta.sma(src, length)
  51. dev = mult * ta.stdev(src, length)
  52. upper = basis + dev
  53. lower = basis - dev
  54. bbw = (upper-lower)/basis
  55.  
  56. BandExp = bbw > bbw[1]
  57.  
  58. vwap = ta.vwap
  59. ema1 = ta.ema(close, 1)
  60. ema8 = ta.ema(close, 8)
  61. ema21 = ta.ema(close, 21)
  62.  
  63. bullcross = ema1>ema21
  64. bearcross = ema1<ema21
  65.  
  66. abovevwap = ema8 > vwap
  67. belowvwap = ema8 < vwap
  68.  
  69. RSLimit = input(1)
  70. RS = RRS > RSLimit
  71. RW = RRS < RSLimit*-1
  72.  
  73. longcheck = BandExp and flatBottom and biggerlong
  74. shortcheck = BandExp and flatTop and biggershort
  75. newshort = shortcheck[1] != true
  76. newlong = longcheck[1] != true
  77.  
  78. //!!!!!!!! Below: Remove "and RS" or "and RW" so that this can be used on the SPY. Remove "and bullcross" to get rid of 21ema filter. Remove "and above/belowvwap" to remove VWAP filter.
  79.  
  80. long = BandExp and flatBottom and biggerlong and newlong and abovevwap and bullcross
  81. short = BandExp and flatTop and biggershort and newshort and belowvwap and bearcross
  82. plotshape(long, title = "Buy", text = 'Buy', style = shape.labelup, location = location.belowbar, color= color.green, textcolor = color.white, size = size.tiny, offset=1)
  83. plotshape(short, title = "Sell", text = 'Sell', style = shape.labeldown, location = location.abovebar, color= color.red, textcolor = color.white, size = size.tiny, offset=1)
  84.  
  85. //plotshape(short, "Short", shape.arrowdown, location.abovebar, color=color.red, size=size.large, offset=1)
  86.  
  87. //Alerts
  88.  
  89. alertcondition(long, "HA Reversal Long", "Long")
  90. alertcondition(short, "HA Reversal Short", "Short")
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement