Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © ZacVaughn
- //@version=4
- study("Stoch MFI")
- //WAVETREND CROSS▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
- //hline(70, color=color.new(#ffffff, 25))
- //hline(30, color=color.new(#ffffff, 25))
- hline(50, title="Middle Line", linestyle=hline.style_dotted)
- obLevel = hline(80, title="Overbought", linestyle=hline.style_dotted, linewidth=2)
- osLevel = hline(20, title="Oversold", linestyle=hline.style_dotted, linewidth=2)
- fill(obLevel, osLevel, title="Background", color=#9915FF, transp=80)
- n1 = 9
- n2 = 12
- ap = hlc3
- esa = ema(ap, n1)
- d1 = ema(abs(ap - esa), n1)
- ci = (ap - esa) / (0.015 * d1)
- tci = ema(ci, n2)
- hline = 0
- wt1 = tci
- wt2 = sma(wt1, 4)
- wt1color = wt1 > 0 ? #00bcd4 : #e91e63
- wtcrossuppre = wt1 > wt2 and wt1[1] < wt2[1] and wt2 < -10
- wtcrossdownpre = wt1 < wt2 and wt1[1] > wt2[1] and wt2 > 10
- wtcrossup = wtcrossuppre or wtcrossuppre[1] or wtcrossuppre[2]
- wtcrossdown = wtcrossdownpre or wtcrossdownpre[1] or wtcrossdownpre[2]
- //plot(wt1, style=plot.style_areabr, color=wt1color)
- //plot(wt2, style=plot.style_areabr, color=color.new(#5d606b, 50))
- //plot(wt2, color=color.new(#000000, 50), linewidth=2)
- //plot(wtcrossuppre ? wt2 : na, title="Cross Up Circles", color=color.lime, style=plot.style_circles, linewidth=4)
- //plot(wtcrossdownpre ? wt2 : na, title="Cross down Circles", color=#e91e63, style=plot.style_circles, linewidth=4)
- /////////////-------------------------MFI-----------------------///////////////////////////
- length = input(title="Length", type=input.integer, defval=14, minval=1, maxval=2000)
- src = hlc3
- upper = sum(volume * (change(src) <= 0 ? 0 : src), length)
- lower = sum(volume * (change(src) >= 0 ? 0 : src), length)
- _rsi(upper, lower) =>
- 100.0 - (100.0 / (1.0 + upper / lower))
- mf = _rsi(upper, lower)
- plot(mf, "MF", color=color.lime, linewidth=1)
- //STOCH DIVERGENCE▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
- periodK14 = 14
- smoothK14 = 3
- periodD14 = 3
- k14 = sma(stoch(close, high, low, periodK14), smoothK14)
- d14 = sma(k14, periodD14)
- plot(k14, title="%K", linewidth=2, color=#ffeb3b)
- plot(d14, title="%D", linewidth=1, color=#ffffff)
- //h0 = hline(80, "Upper Band", linestyle=hline.style_solid, color=color.new(#787B86, 50))
- //h1 = hline(20, "Lower Band", linestyle=hline.style_solid, color=color.new(#787B86, 50))
- //fill(h0, h1, color=color.new(#00bcd4, 90), title="Background")
- //Divergence
- lbR14 = 2
- lbL14 = 6
- rangeUpper14 = 15
- rangeLower14 = 6
- plotBull14 = true
- plotHiddenBull14 = false
- plotBear14 = true
- plotHiddenBear14 = false
- bearColor14 = #e91e63
- bullColor14 = #00bcd4
- hiddenBullColor14 = #00bcd4
- hiddenBearColor14 = #e91e63
- textColor14 = color.white
- noneColor14 = color.new(color.white, 100)
- osc14 = k14
- plFound14 = na(pivotlow(osc14, lbL14, lbR14)) ? false : true
- phFound14 = na(pivothigh(osc14, lbL14, lbR14)) ? false : true
- _inRange14(cond) =>
- bars14 = barssince(cond == true)
- rangeLower14 <= bars14 and bars14 <= rangeUpper14
- //Regular Bullish
- //Osc: Higher Low
- oscHL14 = osc14[lbR14] > valuewhen(plFound14, osc14[lbR14], 1) and _inRange14(plFound14[1])
- //Price: Lower Low
- priceLL14 = low[lbR14] < valuewhen(plFound14, low[lbR14], 1)
- bullCond14 = plotBull14 and priceLL14 and oscHL14 and plFound14
- plot(plFound14 ? osc14[lbR14] : na, offset=-lbR14, title="Regular Bullish", linewidth=2, color=(bullCond14 ? bullColor14 : noneColor14))
- plotshape(bullCond14 ? osc14[lbR14] : na, offset=-lbR14, title="Regular Bullish Label", text="𝐁𝐔𝐋𝐋", style=shape.labelup, location=location.bottom, color=bullColor14, textcolor=textColor14)
- //Hidden Bullish
- //Osc: Lower Low
- oscLL14 = osc14[lbR14] < valuewhen(plFound14, osc14[lbR14], 1) and _inRange14(plFound14[1])
- //Price: Higher Low
- priceHL14 = low[lbR14] > valuewhen(plFound14, low[lbR14], 1)
- hiddenBullCond14 = plotHiddenBull14 and priceHL14 and oscLL14 and plFound14
- plot(plFound14 ? osc14[lbR14] : na, offset=-lbR14, title="Hidden Bullish", linewidth=2, color=(hiddenBullCond14 ? hiddenBullColor14 : noneColor14))
- plotshape(hiddenBullCond14 ? osc14[lbR14] : na, offset=-lbR14, title="Hidden Bullish Label", text=" H Bull ", style=shape.labelup, location=location.absolute, color=bullColor14, textcolor=textColor14)
- //Regular Bearish
- //Osc: Lower High
- oscLH14 = osc14[lbR14] < valuewhen(phFound14, osc14[lbR14], 1) and _inRange14(phFound14[1])
- //Price: Higher High
- priceHH14 = high[lbR14] > valuewhen(phFound14, high[lbR14], 1)
- bearCond14 = plotBear14 and priceHH14 and oscLH14 and phFound14
- plot(phFound14 ? osc14[lbR14] : na, offset=-lbR14, title="Regular Bearish", linewidth=2, color=(bearCond14 ? bearColor14 : noneColor14))
- plotshape(bearCond14 ? osc14[lbR14] : na, offset=-lbR14, title="Regular Bearish Label", text="𝐁𝐄𝐀𝐑", style=shape.labeldown, location=location.absolute, color=bearColor14, textcolor=textColor14)
- //Hidden Bearish
- //Osc: Higher High
- oscHH14 = osc14[lbR14] > valuewhen(phFound14, osc14[lbR14], 1) and _inRange14(phFound14[1])
- //Price: Lower High
- priceLH14 = high[lbR14] < valuewhen(phFound14, high[lbR14], 1)
- hiddenBearCond14 = plotHiddenBear14 and priceLH14 and oscHH14 and phFound14
- plot(phFound14 ? osc14[lbR14] : na, offset=-lbR14, title="Hidden Bearish", linewidth=2, color=(hiddenBearCond14 ? hiddenBearColor14 : noneColor14))
- plotshape(hiddenBearCond14 ? osc14[lbR14] : na, offset=-lbR14, title="Hidden Bearish Label", text=" H Bear ", style=shape.labeldown, location=location.absolute, color=bearColor14, textcolor=textColor14)
- bulldiv = bullCond14 or bullCond14[1] or bullCond14[2]
- beardiv = bearCond14 or bearCond14[1] or bearCond14[2]
- //PLOT STARS▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
- //plot(wtcrossup and bulldiv ? -90 : na, style=plot.style_circles, color=color.new(#ffeb3b, 50), linewidth=6)
- //plot(wtcrossup and bulldiv ? -90 : na, style=plot.style_circles, color=color.new(#ffffff, 0), linewidth=2)
- //plot(wtcrossdown and beardiv ? 110 : na, style=plot.style_circles, color=color.new(#ffeb3b, 50), linewidth=6)
- //plot(wtcrossdown and beardiv ? 110 : na, style=plot.style_circles, color=color.new(#ffffff, 0), linewidth=2)
- /////////////---------------------------//////////////////////
- xrf(values, length) =>
- r_val = float(na)
- if length >= 1
- for i = 0 to length by 1
- if na(r_val) or not na(values[i])
- r_val := values[i]
- r_val
- r_val
- xsa(src,len,wei) =>
- sumf = 0.0
- ma = 0.0
- out = 0.0
- sumf := nz(sumf[1]) - nz(src[len]) + src
- ma := na(src[len]) ? na : sumf/len
- out := na(out[1]) ? ma : (src*wei+out[1]*(len-wei))/len
- out
- //algorithm
- var2 = xrf(low,1)
- var3 = xsa(abs(low-var2),13,1)/xsa(max(low-var2,0),13,1)*100
- var4 = ema(iff(close*1.2,var3*13,var3/13),13)
- var5 = lowest(low,34)
- var6 = highest(var4,34)
- var7 = iff(lowest(low,55),1,0)
- var8 = ema(iff(low<=var5,(var4+var6*2)/2,0),3)/618*var7
- var9 = ema(close,5)
- var10 = (close-sma(close,34))/sma(close,34)*(-10)
- var11 = ema(iff(low<=var5,(var4+var6*2)/2,0),3)/618*var7*(-1)
- var12 = ema(close,5)*(-1)
- //plot sudden dump strength with yellow stick lines
- plotcandle(0,var8, 0, var8, color=var8>xrf(var8,1)?color.yellow:na)
- xl1 = sma(low,2)*0.96
- xl2 = sma(low,26)*0.85
- xl3 = xrf(xl1,1)<xl2 and xrf(xl1,1)<xl1 and xrf(xl1,1)<xrf(xl1,2)
- dump = iff(xl3,0,var8*1)
- //plot(dump,color=color.yellow, linewidth=4)
- //after a dump there are some quick chance to see a temporary bottom in lime sticks
- plotcandle(0,-var11, 0, -var11, color=var11>xrf(var11,1)?color.lime:na)
- // plot orange curve to track post-dump opportunity
- fundready = iff(var8>xrf(var8,1),0,var8)
- //plot(fundready,color=color.lime, linewidth=1)
- //use KDJ to detect long entry opportunity after a dump
- rsv = (((close - lowest(low,9)) / (highest(high,9) - lowest(low,9))) * 100)
- k = xsa(rsv,3,1)
- d = xsa(k,3,1)
- j = 3*k-2*d
- x = lowest(j,2)==lowest(j,8)
- longengry = crossover(j,xrf(j+0.01,1)) and fundready>0 and dump>0
- //bgcolor( longengry ? color.green:na, transp=40)
- buy_cond = crossover(d14,25)
- plotshape(buy_cond, color=color.lime, transp=0, location=location.bottom, style=shape.triangleup, size=size.tiny, transp=50, text="")
- sell_cond = crossunder(d14,80)
- plotshape(sell_cond, color=color.red, transp=0, location=location.top, style=shape.triangledown, size=size.tiny, transp=50, text="")
- backgroundColour = k14 > d14 ? color.green : color.red
- bgcolor(color=backgroundColour, transp=70)
Advertisement
Add Comment
Please, Sign In to add comment