xmd79

Stoch MFI

Feb 23rd, 2022
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.89 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=4
  5. study("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=#9915FF, transp=80)
  19.  
  20. n1 = 9
  21. n2 = 12
  22. ap = hlc3
  23. esa = ema(ap, n1)
  24. d1 = ema(abs(ap - esa), n1)
  25. ci = (ap - esa) / (0.015 * d1)
  26. tci = ema(ci, n2)
  27. hline = 0
  28. wt1 = tci
  29. wt2 = 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(title="Length", type=input.integer, defval=14, minval=1, maxval=2000)
  46. src = hlc3
  47. upper = sum(volume * (change(src) <= 0 ? 0 : src), length)
  48. lower = sum(volume * (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.lime, linewidth=1)
  53.  
  54.  
  55.  
  56. //STOCH DIVERGENCE▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
  57.  
  58. periodK14 = 14
  59. smoothK14 = 3
  60. periodD14 = 3
  61. k14 = sma(stoch(close, high, low, periodK14), smoothK14)
  62. d14 = sma(k14, periodD14)
  63. plot(k14, title="%K", linewidth=2, color=#ffeb3b)
  64. plot(d14, title="%D", linewidth=1, color=#ffffff)
  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(pivotlow(osc14, lbL14, lbR14)) ? false : true
  89. phFound14 = na(pivothigh(osc14, lbL14, lbR14)) ? false : true
  90.  
  91. _inRange14(cond) =>
  92. bars14 = barssince(cond == true)
  93. rangeLower14 <= bars14 and bars14 <= rangeUpper14
  94.  
  95. //Regular Bullish
  96.  
  97. //Osc: Higher Low
  98. oscHL14 = osc14[lbR14] > valuewhen(plFound14, osc14[lbR14], 1) and _inRange14(plFound14[1])
  99.  
  100. //Price: Lower Low
  101. priceLL14 = low[lbR14] < 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=bullColor14, textcolor=textColor14)
  106.  
  107. //Hidden Bullish
  108.  
  109. //Osc: Lower Low
  110. oscLL14 = osc14[lbR14] < valuewhen(plFound14, osc14[lbR14], 1) and _inRange14(plFound14[1])
  111.  
  112. //Price: Higher Low
  113. priceHL14 = low[lbR14] > 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=bullColor14, textcolor=textColor14)
  118.  
  119. //Regular Bearish
  120.  
  121.  
  122. //Osc: Lower High
  123. oscLH14 = osc14[lbR14] < valuewhen(phFound14, osc14[lbR14], 1) and _inRange14(phFound14[1])
  124.  
  125. //Price: Higher High
  126. priceHH14 = high[lbR14] > 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=bearColor14, textcolor=textColor14)
  131.  
  132. //Hidden Bearish
  133.  
  134. //Osc: Higher High
  135. oscHH14 = osc14[lbR14] > valuewhen(phFound14, osc14[lbR14], 1) and _inRange14(phFound14[1])
  136.  
  137. //Price: Lower High
  138. priceLH14 = high[lbR14] < 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=bearColor14, textcolor=textColor14)
  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(abs(low-var2),13,1)/xsa(max(low-var2,0),13,1)*100
  181. var4 = ema(iff(close*1.2,var3*13,var3/13),13)
  182. var5 = lowest(low,34)
  183. var6 = highest(var4,34)
  184. var7 = iff(lowest(low,55),1,0)
  185. var8 = ema(iff(low<=var5,(var4+var6*2)/2,0),3)/618*var7
  186. var9 = ema(close,5)
  187. var10 = (close-sma(close,34))/sma(close,34)*(-10)
  188. var11 = ema(iff(low<=var5,(var4+var6*2)/2,0),3)/618*var7*(-1)
  189. var12 = ema(close,5)*(-1)
  190.  
  191. //plot sudden dump strength with yellow stick lines
  192. plotcandle(0,var8, 0, var8, color=var8>xrf(var8,1)?color.yellow:na)
  193. xl1 = sma(low,2)*0.96
  194. xl2 = sma(low,26)*0.85
  195. xl3 = xrf(xl1,1)<xl2 and xrf(xl1,1)<xl1 and xrf(xl1,1)<xrf(xl1,2)
  196. dump = iff(xl3,0,var8*1)
  197. //plot(dump,color=color.yellow, linewidth=4)
  198. //after a dump there are some quick chance to see a temporary bottom in lime sticks
  199. plotcandle(0,-var11, 0, -var11, color=var11>xrf(var11,1)?color.lime:na)
  200. // plot orange curve to track post-dump opportunity
  201. fundready = iff(var8>xrf(var8,1),0,var8)
  202. //plot(fundready,color=color.lime, linewidth=1)
  203.  
  204. //use KDJ to detect long entry opportunity after a dump
  205. rsv = (((close - lowest(low,9)) / (highest(high,9) - lowest(low,9))) * 100)
  206. k = xsa(rsv,3,1)
  207. d = xsa(k,3,1)
  208. j = 3*k-2*d
  209. x = lowest(j,2)==lowest(j,8)
  210. longengry = crossover(j,xrf(j+0.01,1)) and fundready>0 and dump>0
  211. //bgcolor( longengry ? color.green:na, transp=40)
  212.  
  213.  
  214.  
  215.  
  216. buy_cond = crossover(d14,25)
  217. plotshape(buy_cond, color=color.lime, transp=0, location=location.bottom, style=shape.triangleup, size=size.tiny, transp=50, text="")
  218.  
  219. sell_cond = crossunder(d14,80)
  220. plotshape(sell_cond, color=color.red, transp=0, location=location.top, style=shape.triangledown, size=size.tiny, transp=50, text="")
  221.  
  222.  
  223. backgroundColour = k14 > d14 ? color.green : color.red
  224. bgcolor(color=backgroundColour, transp=70)
  225.  
  226.  
Advertisement
Add Comment
Please, Sign In to add comment