xmd79

Stochastic RSI + Heikin-Ashi

Mar 11th, 2023
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 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. //This is just a fun script to give a different representation to the ever popular Stochastic RSI
  3. //Even for me over the years the stochastic has been a difficult one to use in trading mearly beause of its choppy look.
  4. //Since Heikin-Ashi Candles do such a powerful job in smoothing out the look of choppy markets,
  5. //I decided to test it out on the look of the Stochastic RSI.
  6. //From an initial visual standpoint it worked out WAY better than I thought but it seemed to need something more.
  7. //I decided to use the PineScript "Color.From_Gradient" feature to give the Stochastic a more 3 dimentional look, which really brought the "old-school" indicator to life.
  8.  
  9. // © CoffeeshopCrypto
  10.  
  11. //@version=5
  12.  
  13. indicator("Stochastic RSI + Heikin-Ashi", shorttitle="Stocashi", overlay=false)
  14.  
  15. // Calculate the Stochastic RSI
  16. src = input(close, title="Source")
  17. smoothK = input.int(8, minval=1, title="Stochastic %K Smoothing")
  18. smoothD = input.int(3, minval=1, title="Stochastic %D Smoothing")
  19. lengthRSI = input.int(14, minval=1, title="RSI Length")
  20. rsi1 = ta.rsi(src, lengthRSI)
  21. lengthStoch = input.int(14, minval=1, title="Stochastic Length")
  22. k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK) - 50
  23. d = ta.sma(k, smoothD)
  24.  
  25.  
  26. // Calculate the Stochastic Heikin-Ashi candles
  27. ha_open = (k[1] + d[1]) / 2
  28. ha_close = (k + d + d + k) / 4
  29. ha_high = math.max(k, math.max(ha_open, ha_close))
  30. ha_low = math.min(k, math.min(ha_close, ha_open))
  31.  
  32. // Plot the Heikin-Ashi Stochastic RSI
  33. down_colorbottom = input.color(#086e05, title="Bullish Move Start")
  34. down_colortop = input.color(#8dc474, title="Bullish Move End")
  35. up_color_top = input.color(#af0505, title="Bearish Move Start")
  36. up_color_bottom = input.color(#e08e8e, title="Bearish Move End")
  37.  
  38. gradientColourup = color.from_gradient(k, -50, 50, up_color_bottom, up_color_top)
  39. //gradientColouruptop = color.from_gradient(k, -50, 30, up_color, down_color)
  40. gradientColourdn = color.from_gradient(k, -50, 50, down_colorbottom, down_colortop)
  41. //gradientColourdntop = color.from_gradient(k, -30, 50, up_color, down_color)
  42. bar_color = ha_close >= ha_open ? gradientColourdn : gradientColourup
  43.  
  44. // Use the up and down colors in your script
  45. //////////////////////////////////////////////
  46. plotcandle(ha_open, ha_high, ha_low, ha_close,title= "Stochatic Heiken Ashi Gradient", color=bar_color, wickcolor = bar_color)
  47. mindline = hline(0, color=#d47305a1)
  48. line80 = hline(30, color=#d6cfc875, linestyle = hline.style_solid)
  49. linem10 = hline(-30, color=#d6cfc875, linestyle = hline.style_solid)
Advertisement
Add Comment
Please, Sign In to add comment