Advertisement
xmd79

[KVA]K Stochastic Indicator

Nov 18th, 2023
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 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. // © Kamvia
  3.  
  4. //@version=5
  5. indicator(title='[KVA]K Stochastic Indicator', shorttitle='KStochastic', overlay=false)
  6.  
  7. // Input parameters
  8. length = input(14, 'Length')
  9. smoothK = input(1, 'Smooth K')
  10. smoothD = input(3, 'Smooth D')
  11. smoothF = input(21, 'Smooth F')
  12.  
  13. _src = input.source(close,title="Source")
  14.  
  15.  
  16. sma_signal = input.string(title="Stochastic MA Type", defval="EMA", options=["SMA","WMA", "EMA","DEMA"])
  17. // Calculate %K
  18. lowestLow = ta.lowest(_src, length)
  19. highestHigh = ta.highest(_src, length)
  20. k = 100 * (_src - lowestLow) / (highestHigh - lowestLow)
  21.  
  22. dema(src, length)=>
  23. e1 = ta.ema(src, length)
  24. e2 = ta.ema(e1, length)
  25. ret = 2 * e1 - e2
  26. ret
  27. ma(source, length, type) =>
  28. switch type
  29. "SMA" => ta.sma(source, length)
  30. "DEMA" => dema(source, length)
  31. "EMA" => ta.ema(source, length)
  32.  
  33. "WMA" => ta.wma(source, length)
  34. "VWMA" => ta.vwma(source, length)
  35. // Smooth %K with simple moving average
  36. sk = ma(k, smoothK,sma_signal)
  37.  
  38. // Smooth %K with simple moving average to calculate %D
  39. sd =ma(sk, smoothD,sma_signal)
  40. sf = ma(sk, smoothF,sma_signal)
  41. // Plotting
  42. plot(sk, color=color.new(color.blue, 0), title='%K')
  43. plot(sd, color=color.new(color.red, 0), title='%D')
  44. plot(sf, color=color.new(color.black, 0), title='%F')
  45. h0 = hline(80, "Upper Band", color=#787B86)
  46. hline(50, "Middle Band", color=color.new(#787B86, 50))
  47. h1 = hline(20, "Lower Band", color=#787B86)
  48. fill(h0, h1, color=color.rgb(33, 150, 243, 90), title="Background")
  49.  
  50.  
  51. stRD = sk ==100
  52. stGD = sk == 0
  53. stOBOS = true
  54. plot(stOBOS ? stRD ? sk : na:na, color=color.red, style=plot.style_circles, linewidth=3)
  55. plot(stOBOS ? stGD ? sk : na:na, color=color.green, style=plot.style_circles, linewidth=3)
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement