xmd79

Jurik-Smoothed CCI w/ MA Deviation [Loxx]

Jul 6th, 2022
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.29 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. // © loxx
  3.  
  4. //@version=5
  5. indicator("Jurik-Smoothed CCI w/ MA Deviation [Loxx]",
  6. shorttitle="JSCCIMAD [Loxx]",
  7. overlay = false,
  8. timeframe="",
  9. timeframe_gaps = true)
  10.  
  11. import loxx/loxxmas/1
  12. import loxx/loxxjuriktools/1
  13.  
  14. greencolor = #2DD204
  15. redcolor = #D2042D
  16.  
  17.  
  18. maintype = input.string("Exponential Moving Average - EMA", "Deviation MA Type", options = ["ADXvma - Average Directional Volatility Moving Average", "Ahrens Moving Average"
  19. , "Alexander Moving Average - ALXMA", "Double Exponential Moving Average - DEMA", "Double Smoothed Exponential Moving Average - DSEMA"
  20. , "Exponential Moving Average - EMA", "Fast Exponential Moving Average - FEMA", "Fractal Adaptive Moving Average - FRAMA"
  21. , "Hull Moving Average - HMA", "IE/2 - Early T3 by Tim Tilson", "Integral of Linear Regression Slope - ILRS"
  22. , "Instantaneous Trendline", "Laguerre Filter", "Leader Exponential Moving Average", "Linear Regression Value - LSMA (Least Squares Moving Average)"
  23. , "Linear Weighted Moving Average - LWMA", "McGinley Dynamic", "McNicholl EMA", "Non-Lag Moving Average", "Parabolic Weighted Moving Average"
  24. , "Recursive Moving Trendline", "Simple Moving Average - SMA", "Sine Weighted Moving Average", "Smoothed Moving Average - SMMA"
  25. , "Smoother", "Super Smoother", "Three-pole Ehlers Butterworth", "Three-pole Ehlers Smoother"
  26. , "Triangular Moving Average - TMA", "Triple Exponential Moving Average - TEMA", "Two-pole Ehlers Butterworth", "Two-pole Ehlers smoother"
  27. , "Volume Weighted EMA - VEMA", "Zero-Lag DEMA - Zero Lag Double Exponential Moving Average", "Zero-Lag Moving Average"
  28. , "Zero Lag TEMA - Zero Lag Triple Exponential Moving Average"],
  29. group = "Basic Settings")
  30.  
  31. ccisrc = input.source(hlc3, "CCI Source", group = "Basic Settings")
  32. cciper = input.int(32, "CCI Period", group = "Basic Settings")
  33. jsmth = input.int(32, "Jurik Smoothing Period", group = "Basic Settings")
  34. phs = input.float(0, "Jurik Phase", group = "Basic Settings")
  35.  
  36. inpLevelUp = input.int(100, "Overbought Level", group = "Basic Settings")
  37. inpLevelDown = input.int(-100, "Oversold Level", group = "Basic Settings")
  38. colorbars = input.bool(false, "Color bars?", group = "UI Options")
  39.  
  40. frama_FC = input.int(defval=1, title="* Fractal Adjusted (FRAMA) Only - FC", group = "Moving Average Inputs")
  41. frama_SC = input.int(defval=200, title="* Fractal Adjusted (FRAMA) Only - SC", group = "Moving Average Inputs")
  42. instantaneous_alpha = input.float(defval=0.07, minval = 0, title="* Instantaneous Trendline (INSTANT) Only - Alpha", group = "Moving Average Inputs")
  43. _laguerre_alpha = input.float(title='* Laguerre Filter (LF) Only - Alpha', minval=0, maxval=1, step=0.1, defval=0.7, group = "Moving Average Inputs")
  44. lsma_offset = input.int(defval=0, title="* Least Squares Moving Average (LSMA) Only - Offset", group = "Moving Average Inputs")
  45. _pwma_pwr = input.int(2, '* Parabolic Weighted Moving Average (PWMA) Only - Power', minval=0, group = "Moving Average Inputs")
  46. kfl=input.float(0.666, title="* Kaufman's Adaptive MA (KAMA) Only - Fast End", group = "Moving Average Inputs")
  47. ksl=input.float(0.0645, title="* Kaufman's Adaptive MA (KAMA) Only - Slow End", group = "Moving Average Inputs")
  48. amafl = input.int(2, title="* Adaptive Moving Average (AMA) Only - Fast", group = "Moving Average Inputs")
  49. amasl = input.int(30, title="* Adaptive Moving Average (AMA) Only - Slow", group = "Moving Average Inputs")
  50.  
  51. variant(type, src, len) =>
  52. sig = 0.0
  53. trig = 0.0
  54. special = false
  55. if type == "ADXvma - Average Directional Volatility Moving Average"
  56. [t, s, b] = loxxmas.adxvma(src, len)
  57. sig := s
  58. trig := t
  59. special := b
  60. else if type == "Ahrens Moving Average"
  61. [t, s, b] = loxxmas.ahrma(src, len)
  62. sig := s
  63. trig := t
  64. special := b
  65. else if type == "Alexander Moving Average - ALXMA"
  66. [t, s, b] = loxxmas.alxma(src, len)
  67. sig := s
  68. trig := t
  69. special := b
  70. else if type == "Double Exponential Moving Average - DEMA"
  71. [t, s, b] = loxxmas.dema(src, len)
  72. sig := s
  73. trig := t
  74. special := b
  75. else if type == "Double Smoothed Exponential Moving Average - DSEMA"
  76. [t, s, b] = loxxmas.dsema(src, len)
  77. sig := s
  78. trig := t
  79. special := b
  80. else if type == "Exponential Moving Average - EMA"
  81. [t, s, b] = loxxmas.ema(src, len)
  82. sig := s
  83. trig := t
  84. special := b
  85. else if type == "Fast Exponential Moving Average - FEMA"
  86. [t, s, b] = loxxmas.fema(src, len)
  87. sig := s
  88. trig := t
  89. special := b
  90. else if type == "Fractal Adaptive Moving Average - FRAMA"
  91. [t, s, b] = loxxmas.frama(src, len, frama_FC, frama_SC)
  92. sig := s
  93. trig := t
  94. special := b
  95. else if type == "Hull Moving Average - HMA"
  96. [t, s, b] = loxxmas.hma(src, len)
  97. sig := s
  98. trig := t
  99. special := b
  100. else if type == "IE/2 - Early T3 by Tim Tilson"
  101. [t, s, b] = loxxmas.ie2(src, len)
  102. sig := s
  103. trig := t
  104. special := b
  105. else if type == "Integral of Linear Regression Slope - ILRS"
  106. [t, s, b] = loxxmas.ilrs(src, len)
  107. sig := s
  108. trig := t
  109. special := b
  110. else if type == "Instantaneous Trendline"
  111. [t, s, b] = loxxmas.instant(src, instantaneous_alpha)
  112. sig := s
  113. trig := t
  114. special := b
  115. else if type == "Laguerre Filter"
  116. [t, s, b] = loxxmas.laguerre(src, _laguerre_alpha)
  117. sig := s
  118. trig := t
  119. special := b
  120. else if type == "Leader Exponential Moving Average"
  121. [t, s, b] = loxxmas.leader(src, len)
  122. sig := s
  123. trig := t
  124. special := b
  125. else if type == "Linear Regression Value - LSMA (Least Squares Moving Average)"
  126. [t, s, b] = loxxmas.lsma(src, len, lsma_offset)
  127. sig := s
  128. trig := t
  129. special := b
  130. else if type == "Linear Weighted Moving Average - LWMA"
  131. [t, s, b] = loxxmas.lwma(src, len)
  132. sig := s
  133. trig := t
  134. special := b
  135. else if type == "McGinley Dynamic"
  136. [t, s, b] = loxxmas.mcginley(src, len)
  137. sig := s
  138. trig := t
  139. special := b
  140. else if type == "McNicholl EMA"
  141. [t, s, b] = loxxmas.mcNicholl(src, len)
  142. sig := s
  143. trig := t
  144. special := b
  145. else if type == "Non-Lag Moving Average"
  146. [t, s, b] = loxxmas.nonlagma(src, len)
  147. sig := s
  148. trig := t
  149. special := b
  150. else if type == "Parabolic Weighted Moving Average"
  151. [t, s, b] = loxxmas.pwma(src, len, _pwma_pwr)
  152. sig := s
  153. trig := t
  154. special := b
  155. else if type == "Recursive Moving Trendline"
  156. [t, s, b] = loxxmas.rmta(src, len)
  157. sig := s
  158. trig := t
  159. special := b
  160. else if type == "Simple Moving Average - SMA"
  161. [t, s, b] = loxxmas.sma(src, len)
  162. sig := s
  163. trig := t
  164. special := b
  165. else if type == "Sine Weighted Moving Average"
  166. [t, s, b] = loxxmas.swma(src, len)
  167. sig := s
  168. trig := t
  169. special := b
  170. else if type == "Smoothed Moving Average - SMMA"
  171. [t, s, b] = loxxmas.smma(src, len)
  172. sig := s
  173. trig := t
  174. special := b
  175. else if type == "Smoother"
  176. [t, s, b] = loxxmas.smoother(src, len)
  177. sig := s
  178. trig := t
  179. special := b
  180. else if type == "Super Smoother"
  181. [t, s, b] = loxxmas.super(src, len)
  182. sig := s
  183. trig := t
  184. special := b
  185. else if type == "Three-pole Ehlers Butterworth"
  186. [t, s, b] = loxxmas.threepolebuttfilt(src, len)
  187. sig := s
  188. trig := t
  189. special := b
  190. else if type == "Three-pole Ehlers Smoother"
  191. [t, s, b] = loxxmas.threepolesss(src, len)
  192. sig := s
  193. trig := t
  194. special := b
  195. else if type == "Triangular Moving Average - TMA"
  196. [t, s, b] = loxxmas.tma(src, len)
  197. sig := s
  198. trig := t
  199. special := b
  200. else if type == "Triple Exponential Moving Average - TEMA"
  201. [t, s, b] = loxxmas.tema(src, len)
  202. sig := s
  203. trig := t
  204. special := b
  205. else if type == "Two-pole Ehlers Butterworth"
  206. [t, s, b] = loxxmas.twopolebutter(src, len)
  207. sig := s
  208. trig := t
  209. special := b
  210. else if type == "Two-pole Ehlers smoother"
  211. [t, s, b] = loxxmas.twopoless(src, len)
  212. sig := s
  213. trig := t
  214. special := b
  215. else if type == "Volume Weighted EMA - VEMA"
  216. [t, s, b] = loxxmas.vwema(src, len)
  217. sig := s
  218. trig := t
  219. special := b
  220. else if type == "Zero-Lag DEMA - Zero Lag Double Exponential Moving Average"
  221. [t, s, b] = loxxmas.zlagdema(src, len)
  222. sig := s
  223. trig := t
  224. special := b
  225. else if type == "Zero-Lag Moving Average"
  226. [t, s, b] = loxxmas.zlagma(src, len)
  227. sig := s
  228. trig := t
  229. special := b
  230. else if type == "Zero Lag TEMA - Zero Lag Triple Exponential Moving Average"
  231. [t, s, b] = loxxmas.zlagtema(src, len)
  232. sig := s
  233. trig := t
  234. special := b
  235. trig
  236.  
  237.  
  238. _emaDev(type, price, period)=>
  239. alpha = 2.0/(1.0+period)
  240. wEMAdev0 = price, wEMAdev1 = price
  241. wEMAdev0 := variant(type, price, period)
  242. wEMAdev1 := variant(type, price*price, period)
  243. out = math.sqrt(period*(wEMAdev1 - wEMAdev0 * wEMAdev0) / math.max(period-1, 1))
  244. out
  245.  
  246. _cci(type, src, len, smth, phase)=>
  247. price = loxxjuriktools.jurik_filt(src, smth, phase)
  248. avg = loxxjuriktools.jurik_filt(price, len, phase)
  249. dev = math.max(_emaDev(type, price, len), -2e10)
  250. val = (dev!=0) ? (price - avg) / (0.015 * dev) : 0.
  251. val
  252.  
  253. middle = 0.
  254.  
  255. cci = _cci(maintype, ccisrc, cciper, jsmth, phs)
  256.  
  257. colorout =
  258. cci > middle ? greencolor : redcolor
  259.  
  260.  
  261. plot(inpLevelUp, color = bar_index % 2 ? color.gray : na)
  262. plot(inpLevelDown, color = bar_index % 2 ? color.gray : na)
  263. plot(middle, color = bar_index % 2 ? color.gray : na)
  264.  
  265. plot(cci, color = colorout, style = plot.style_line, linewidth = 2)
  266.  
  267. barcolor(colorbars ? colorout : na)
  268.  
Advertisement
Add Comment
Please, Sign In to add comment