xmd79

Stoch MFI

Jan 24th, 2023
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.30 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. // © ZacVaughn
  3.  
  4. //@version=5
  5. indicator('Stoch MFI')
  6.  
  7.  
  8.  
  9.  
  10.  
  11. //WAVETREND CROSS▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
  12.  
  13. //hline(70, color=color.new(#ffffff, 25))
  14. //hline(30, color=color.new(#ffffff, 25))
  15. hline(50, title='Middle Line', linestyle=hline.style_dotted)
  16. obLevel = hline(80, title='Overbought', linestyle=hline.style_dotted, linewidth=2)
  17. osLevel = hline(20, title='Oversold', linestyle=hline.style_dotted, linewidth=2)
  18. fill(obLevel, osLevel, title='Background', color=color.new(#9915FF, 80))
  19.  
  20. n1 = 9
  21. n2 = 12
  22. ap = hlc3
  23. esa = ta.ema(ap, n1)
  24. d1 = ta.ema(math.abs(ap - esa), n1)
  25. ci = (ap - esa) / (0.015 * d1)
  26. tci = ta.ema(ci, n2)
  27. hline = 0
  28. wt1 = tci
  29. wt2 = ta.sma(wt1, 4)
  30.  
  31. wt1color = wt1 > 0 ? #00bcd4 : #e91e63
  32. wtcrossuppre = wt1 > wt2 and wt1[1] < wt2[1] and wt2 < -10
  33. wtcrossdownpre = wt1 < wt2 and wt1[1] > wt2[1] and wt2 > 10
  34. wtcrossup = wtcrossuppre or wtcrossuppre[1] or wtcrossuppre[2]
  35. wtcrossdown = wtcrossdownpre or wtcrossdownpre[1] or wtcrossdownpre[2]
  36.  
  37. //plot(wt1, style=plot.style_areabr, color=wt1color)
  38. //plot(wt2, style=plot.style_areabr, color=color.new(#5d606b, 50))
  39. //plot(wt2, color=color.new(#000000, 50), linewidth=2)
  40. //plot(wtcrossuppre ? wt2 : na, title="Cross Up Circles", color=color.lime, style=plot.style_circles, linewidth=4)
  41. //plot(wtcrossdownpre ? wt2 : na, title="Cross down Circles", color=#e91e63, style=plot.style_circles, linewidth=4)
  42.  
  43. /////////////-------------------------MFI-----------------------///////////////////////////
  44.  
  45. length = input.int(title='Length', defval=14, minval=1, maxval=2000)
  46. src = hlc3
  47. upper = math.sum(volume * (ta.change(src) <= 0 ? 0 : src), length)
  48. lower = math.sum(volume * (ta.change(src) >= 0 ? 0 : src), length)
  49. _rsi(upper, lower) =>
  50. 100.0 - 100.0 / (1.0 + upper / lower)
  51. mf = _rsi(upper, lower)
  52. plot(mf, 'MF', color=color.new(color.lime, 0), linewidth=1)
  53.  
  54.  
  55.  
  56. //STOCH DIVERGENCE▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
  57.  
  58. periodK14 = 14
  59. smoothK14 = 3
  60. periodD14 = 3
  61. k14 = ta.sma(ta.stoch(close, high, low, periodK14), smoothK14)
  62. d14 = ta.sma(k14, periodD14)
  63. plot(k14, title='%K', linewidth=2, color=color.new(#ffeb3b, 0))
  64. plot(d14, title='%D', linewidth=1, color=color.new(#ffffff, 0))
  65. //h0 = hline(80, "Upper Band", linestyle=hline.style_solid, color=color.new(#787B86, 50))
  66. //h1 = hline(20, "Lower Band", linestyle=hline.style_solid, color=color.new(#787B86, 50))
  67. //fill(h0, h1, color=color.new(#00bcd4, 90), title="Background")
  68.  
  69. //Divergence
  70. lbR14 = 2
  71. lbL14 = 6
  72. rangeUpper14 = 15
  73. rangeLower14 = 6
  74. plotBull14 = true
  75. plotHiddenBull14 = false
  76. plotBear14 = true
  77. plotHiddenBear14 = false
  78.  
  79. bearColor14 = #e91e63
  80. bullColor14 = #00bcd4
  81. hiddenBullColor14 = #00bcd4
  82. hiddenBearColor14 = #e91e63
  83. textColor14 = color.white
  84. noneColor14 = color.new(color.white, 100)
  85.  
  86. osc14 = k14
  87.  
  88. plFound14 = na(ta.pivotlow(osc14, lbL14, lbR14)) ? false : true
  89. phFound14 = na(ta.pivothigh(osc14, lbL14, lbR14)) ? false : true
  90.  
  91. _inRange14(cond) =>
  92. bars14 = ta.barssince(cond == true)
  93. rangeLower14 <= bars14 and bars14 <= rangeUpper14
  94.  
  95. //Regular Bullish
  96.  
  97. //Osc: Higher Low
  98. oscHL14 = osc14[lbR14] > ta.valuewhen(plFound14, osc14[lbR14], 1) and _inRange14(plFound14[1])
  99.  
  100. //Price: Lower Low
  101. priceLL14 = low[lbR14] < ta.valuewhen(plFound14, low[lbR14], 1)
  102.  
  103. bullCond14 = plotBull14 and priceLL14 and oscHL14 and plFound14
  104. plot(plFound14 ? osc14[lbR14] : na, offset=-lbR14, title='Regular Bullish', linewidth=2, color=bullCond14 ? bullColor14 : noneColor14)
  105. plotshape(bullCond14 ? osc14[lbR14] : na, offset=-lbR14, title='Regular Bullish Label', text='𝐁𝐔𝐋𝐋', style=shape.labelup, location=location.bottom, color=color.new(bullColor14, 0), textcolor=color.new(textColor14, 0))
  106.  
  107. //Hidden Bullish
  108.  
  109. //Osc: Lower Low
  110. oscLL14 = osc14[lbR14] < ta.valuewhen(plFound14, osc14[lbR14], 1) and _inRange14(plFound14[1])
  111.  
  112. //Price: Higher Low
  113. priceHL14 = low[lbR14] > ta.valuewhen(plFound14, low[lbR14], 1)
  114.  
  115. hiddenBullCond14 = plotHiddenBull14 and priceHL14 and oscLL14 and plFound14
  116. plot(plFound14 ? osc14[lbR14] : na, offset=-lbR14, title='Hidden Bullish', linewidth=2, color=hiddenBullCond14 ? hiddenBullColor14 : noneColor14)
  117. plotshape(hiddenBullCond14 ? osc14[lbR14] : na, offset=-lbR14, title='Hidden Bullish Label', text=' H Bull ', style=shape.labelup, location=location.absolute, color=color.new(bullColor14, 0), textcolor=color.new(textColor14, 0))
  118.  
  119. //Regular Bearish
  120.  
  121.  
  122. //Osc: Lower High
  123. oscLH14 = osc14[lbR14] < ta.valuewhen(phFound14, osc14[lbR14], 1) and _inRange14(phFound14[1])
  124.  
  125. //Price: Higher High
  126. priceHH14 = high[lbR14] > ta.valuewhen(phFound14, high[lbR14], 1)
  127.  
  128. bearCond14 = plotBear14 and priceHH14 and oscLH14 and phFound14
  129. plot(phFound14 ? osc14[lbR14] : na, offset=-lbR14, title='Regular Bearish', linewidth=2, color=bearCond14 ? bearColor14 : noneColor14)
  130. plotshape(bearCond14 ? osc14[lbR14] : na, offset=-lbR14, title='Regular Bearish Label', text='𝐁𝐄𝐀𝐑', style=shape.labeldown, location=location.absolute, color=color.new(bearColor14, 0), textcolor=color.new(textColor14, 0))
  131.  
  132. //Hidden Bearish
  133.  
  134. //Osc: Higher High
  135. oscHH14 = osc14[lbR14] > ta.valuewhen(phFound14, osc14[lbR14], 1) and _inRange14(phFound14[1])
  136.  
  137. //Price: Lower High
  138. priceLH14 = high[lbR14] < ta.valuewhen(phFound14, high[lbR14], 1)
  139.  
  140. hiddenBearCond14 = plotHiddenBear14 and priceLH14 and oscHH14 and phFound14
  141. plot(phFound14 ? osc14[lbR14] : na, offset=-lbR14, title='Hidden Bearish', linewidth=2, color=hiddenBearCond14 ? hiddenBearColor14 : noneColor14)
  142. plotshape(hiddenBearCond14 ? osc14[lbR14] : na, offset=-lbR14, title='Hidden Bearish Label', text=' H Bear ', style=shape.labeldown, location=location.absolute, color=color.new(bearColor14, 0), textcolor=color.new(textColor14, 0))
  143.  
  144. bulldiv = bullCond14 or bullCond14[1] or bullCond14[2]
  145. beardiv = bearCond14 or bearCond14[1] or bearCond14[2]
  146.  
  147.  
  148. //PLOT STARS▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
  149.  
  150. //plot(wtcrossup and bulldiv ? -90 : na, style=plot.style_circles, color=color.new(#ffeb3b, 50), linewidth=6)
  151. //plot(wtcrossup and bulldiv ? -90 : na, style=plot.style_circles, color=color.new(#ffffff, 0), linewidth=2)
  152. //plot(wtcrossdown and beardiv ? 110 : na, style=plot.style_circles, color=color.new(#ffeb3b, 50), linewidth=6)
  153. //plot(wtcrossdown and beardiv ? 110 : na, style=plot.style_circles, color=color.new(#ffffff, 0), linewidth=2)
  154.  
  155.  
  156.  
  157.  
  158.  
  159. /////////////---------------------------//////////////////////
  160.  
  161.  
  162. xrf(values, length) =>
  163. r_val = float(na)
  164. if length >= 1
  165. for i = 0 to length by 1
  166. if na(r_val) or not na(values[i])
  167. r_val := values[i]
  168. r_val
  169. r_val
  170. xsa(src, len, wei) =>
  171. sumf = 0.0
  172. ma = 0.0
  173. out = 0.0
  174. sumf := nz(sumf[1]) - nz(src[len]) + src
  175. ma := na(src[len]) ? na : sumf / len
  176. out := na(out[1]) ? ma : (src * wei + out[1] * (len - wei)) / len
  177. out
  178. //algorithm
  179. var2 = xrf(low, 1)
  180. var3 = xsa(math.abs(low - var2), 13, 1) / xsa(math.max(low - var2, 0), 13, 1) * 100
  181. var4 = ta.ema(close * 1.2 ? var3 * 13 : var3 / 13, 13)
  182. var5 = ta.lowest(low, 34)
  183. var6 = ta.highest(var4, 34)
  184. lowest_1 = ta.lowest(low, 55)
  185. var7 = lowest_1 ? 1 : 0
  186. var8 = ta.ema(low <= var5 ? (var4 + var6 * 2) / 2 : 0, 3) / 618 * var7
  187. var9 = ta.ema(close, 5)
  188. var10 = (close - ta.sma(close, 34)) / ta.sma(close, 34) * -10
  189. var11 = ta.ema(low <= var5 ? (var4 + var6 * 2) / 2 : 0, 3) / 618 * var7 * -1
  190. var12 = ta.ema(close, 5) * -1
  191.  
  192. //plot sudden dump strength with yellow stick lines
  193. plotcandle(0, var8, 0, var8, color=var8 > xrf(var8, 1) ? color.yellow : na)
  194. xl1 = ta.sma(low, 2) * 0.96
  195. xl2 = ta.sma(low, 26) * 0.85
  196. xl3 = xrf(xl1, 1) < xl2 and xrf(xl1, 1) < xl1 and xrf(xl1, 1) < xrf(xl1, 2)
  197. dump = xl3 ? 0 : var8 * 1
  198. //plot(dump,color=color.yellow, linewidth=4)
  199. //after a dump there are some quick chance to see a temporary bottom in lime sticks
  200. plotcandle(0, -var11, 0, -var11, color=var11 > xrf(var11, 1) ? color.lime : na)
  201. // plot orange curve to track post-dump opportunity
  202. xrf_1 = xrf(var8, 1)
  203. fundready = var8 > xrf_1 ? 0 : var8
  204. //plot(fundready,color=color.lime, linewidth=1)
  205.  
  206. //use KDJ to detect long entry opportunity after a dump
  207. rsv = (close - ta.lowest(low, 9)) / (ta.highest(high, 9) - ta.lowest(low, 9)) * 100
  208. k = xsa(rsv, 3, 1)
  209. d = xsa(k, 3, 1)
  210. j = 3 * k - 2 * d
  211. x = ta.lowest(j, 2) == ta.lowest(j, 8)
  212. longengry = ta.crossover(j, xrf(j + 0.01, 1)) and fundready > 0 and dump > 0
  213. //bgcolor( longengry ? color.green:na, transp=40)
  214.  
  215.  
  216.  
  217.  
  218. buy_cond = ta.crossover(d14, 25)
  219. plotshape(buy_cond, color=color.new(color.lime, 0), location=location.bottom, style=shape.triangleup, size=size.tiny, text='')
  220.  
  221. sell_cond = ta.crossunder(d14, 80)
  222. plotshape(sell_cond, color=color.new(color.red, 0), location=location.top, style=shape.triangledown, size=size.tiny, text='')
  223.  
  224.  
  225. backgroundColour = k14 > d14 ? color.green : color.red
  226. bgcolor(color=backgroundColour, transp=70)
  227.  
  228.  
  229.  
Advertisement
Add Comment
Please, Sign In to add comment