Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///@version=2
- study(title="candleswissknife", shorttitle="candleswissknife",overlay=false)
- res = input(title="Heikin Ashi Candle Time Frame", type=resolution, defval="60")
- hshift = input(1,title="Heikin Ashi Candle Time Frame Shift")
- res1 = input(title="Heikin Ashi EMA Time Frame", type=resolution, defval="1440")
- mhshift = input(0,title="Heikin Ashi EMA Time Frame Shift")
- fama = input(1,"Heikin Ashi EMA Period")
- test = input(1,"Heikin Ashi EMA Shift")
- sloma = input(30,"Slow EMA Period")
- slomas = input(1,"Slow EMA Shift")
- macdf = input(false,title="With MACD filter")
- res2 = input(title="MACD Time Frame", type=resolution, defval="15")
- macds = input(1,title="MACD Shift")
- //Heikin Ashi Open/Close Price
- ha_t = heikinashi(tickerid)
- ha_open = security(ha_t, res, open[hshift])
- ha_close = security(ha_t, res, close[hshift])
- mha_close = security(ha_t, res1, close[mhshift])
- //macd
- [macdLine, signalLine, histLine] = macd(close, 12, 26, 9)
- macdl = security(ha_t,res2,macdLine[macds])
- macdsl= security(ha_t,res2,signalLine[macds])
- //Moving Average
- fma = ema(mha_close[test],fama)
- sma = ema(ha_close[slomas],sloma)
- // SETTING UP VARIABLES //
- src = input(title="Data Source",type=source,defval=ohlc4)
- // RSI //
- rsiprd = input(title="RSI period",type=integer,defval=5)
- rv = rsi(src,rsiprd)
- ob = input(title="Overbought Level", type=integer, defval=70)
- os = input(title="Oversold Level", type=integer, defval=30)
- // look back periods //
- x = input(title = "short lookback period",type=integer,defval=5)
- z = input(title = "long lookback period",type=integer,defval=25)
- revatr = input(title="ATR Reversal multiplier", type=float, defval=1.618)*atr(rsiprd)
- alert = input(title="Alert period", type=integer, defval=25)
- // END SETUP //
- ////////////////////////
- // BULLISH DIVERGENCE //
- ////////////////////////
- // define lower low in price //
- srcLL = src > lowest(src,x)+revatr and lowest(src,x)<lowest(src,z)[x]
- // define higher low in rsi //
- rsiHL = rv>lowest(rv,x) and lowest(rv,x) > lowest(rv,z)[x] and lowest(rv,x)<os
- BullishDiv = srcLL and rsiHL
- BullishDivAlert = iff(barssince(BullishDiv)<alert,10,0)+50
- ////////////////////////
- // BEARISH DIVERGENCE //
- ////////////////////////
- // define higher high in price //
- srcHH = src < highest(src,x)-revatr and highest(src,x)>highest(src,z)[x]
- // define lower high in RSI //
- rsiLH = rv<highest(rv,x) and highest(rv,x) < highest(rv,z)[x] and highest(rv,x)>ob
- BearishDiv = srcHH and rsiLH
- BearishDivAlert = iff(barssince(BearishDiv)<alert,-10,0)+50
- zero = plot(50)
- osl = plot(30)
- obl = plot(70)
- BULLD = plot(BullishDivAlert, color = green)
- BEARD = plot(BearishDivAlert, color = red)
- fill(BULLD,zero,color=green, transp=90)
- fill(zero,BEARD,color=red, transp=90)
- plot(rv, color = white, linewidth = 2)
- oslv = plot(rv<30 ? 20 : 30, color = gray)
- oblv = plot(rv>70 ? 80 : 70, color = gray)
- fill(osl,oslv, color=blue, transp=90)
- fill(oblv,obl, color=red, transp=90)
- ///DIRECTIONAL MOVEMENT INDEX///
- len3 = input(5, minval=1, title="DI Length")
- lensig3 = input(5, title="ADX Smoothing", minval=1, maxval=50)
- up3 = change(high)
- down3 = -change(low)
- plusDM3 = na(up3) ? na : (up3 > down3 and up3 > 0 ? up3 : 0)
- minusDM3 = na(down3) ? na : (down3 > up3 and down3 > 0 ? down3 : 0)
- trur3 = rma(tr, len3)
- plus3 = fixnan(100 * rma(plusDM3, len3) / trur3)
- minus3 = fixnan(100 * rma(minusDM3, len3) / trur3)
- sum3 = plus3 + minus3
- adx3 = 100 * rma(abs(plus3 - minus3) / (sum3 == 0 ? 1 : sum3), lensig3)
- plot(plus3, color=white, style=line, linewidth=2, title="+DI")
- plot(minus3, color=white, style=line, linewidth=2, title="-DI")
- plot(adx3, color=white, style=line, linewidth=3, title="ADX")
- // Wells Wilders MA
- wwma(l,p) =>
- wwma = (nz(wwma[1]) * (l - 1) + p) / l
- // Inputs
- DMIlength = input(10)
- Stolength = input(3)
- // DMI Osc Calc
- hiDiff = high - high[1]
- loDiff = low[1] - low
- plusDM = (hiDiff > loDiff) and (hiDiff > 0) ? hiDiff : 0
- minusDM = (loDiff > hiDiff) and (loDiff > 0) ? loDiff : 0
- ATR = wwma(DMIlength, tr)
- PlusDI = 100 * wwma(DMIlength,plusDM) / ATR
- MinusDI = 100 * wwma(DMIlength,minusDM) / ATR
- osc = PlusDI - MinusDI
- // DMI Stochastic Calc
- hi = highest(osc, Stolength)
- lo = lowest(osc, Stolength)
- Stoch = sum((osc-lo),Stolength) / sum((hi-lo),Stolength) *100
- plot(Stoch, color = white, title = 'Stochastic', linewidth = 2, style = line)
- p0 = 0
- p1 = 5
- p2 = 80
- p3 = 20
- crossUp = Stoch[1] < 10 and Stoch >10 ? 1 : 0
- crossDown = Stoch[1] > 90 and Stoch < 90 ? 1 : 0
- //crossP3 = cross(Stoch,p3)
- //circleYPosition = crossP3
- //circleYPosition = p3
- //circleYPosition_l = p2
- plot (p3, color = red, linewidth = 1, title = 'Over Bought')
- plot (p2, color = green, linewidth = 1, title = 'Over Sold')
- //plot(crossUp and crossP3 ? circleYPosition : na, color = green, style = cross, linewidth = 4, title='Long')
- //plot(crossUp ? circleYPosition : na, color = green, style = cross, linewidth = 4, title='Long', offset=-1)
- //plot(sd and cross_down and cross(sma(ac, 1), achm) ? circleYPosition : na,style=cross, linewidth=6, color=fuchsia)
- //plot(crossDown ? circleYPosition_l : na,style=cross, linewidth=6, color=fuchsia, offset=-1)
- //plot(cross(Stoch,p2) ? Stoch : na, color = Stoch < p2 ? red : na, style = cross, linewidth = 4, title='Short')
- plotchar(crossUp, title="i", char='B', location=location.bottom, color=green, transp=0, offset=0)
- plotchar(crossDown, title="Gann Swing Low Plots-Triangles Up Bottom of Screen",char='S', offset=0, location=location.top, color=red, transp=0)
- p = input(120,title="Length")
- //scale
- hh = highest(high,p)
- ll = lowest(low,p)
- scale = hh-ll
- //dynamic OHLC
- dyno = ((open-ll)/scale)*100
- dynl = ((low-ll)/scale)*100
- dynh = ((high-ll)/scale)*100
- dync = ((close-ll)/scale)*100
- //candle color
- color=close>open?1:0
- //drawcandle
- hline(78.6)
- hline(61.8)
- hline(50)
- hline(38.2)
- hline(23.6)
- plotcandle(dyno,dynh,dynl,dync,title="Candle",color=color==1?green:red)
- plot(10,color=green)
- plot(30,color=red)
- plot(80,color=black)
- plot(90,color=red)
- //Alert
- up = dync<70 and crossover(fma,sma) and (macdl > macdsl or macdf == false) ? 1:0
- down = crossunder(fma,sma) and (macdl < macdsl or macdf == false ) ? -1:0
- plot(up,"Go Long",color=lime,linewidth=20,style=histogram)
- plot(down,"Go Short",color=red,linewidth=20,style=histogram)
- up1 = minus3>20 and crossover(dync,p3)
- down1 = crossunder(rv,p2) and dync>80
- plot(up1,"Go Long1",color=blue,linewidth=20,style=histogram)
- plot(down1,"Go Short1",color=gray,linewidth=20,style=histogram)
- up2 = crossover(dync,p1) and rv<10
- down2 = crossunder(rv,p2) and dync>80
- plot(up2,"Go Long2",color=green,linewidth=20,style=histogram)
- plot(down2,"Go Short2",color=gray,linewidth=20,style=histogram)
- alertcondition(up, title='go long', message='go long')
- alertcondition(up1, title='go long1', message='go long1')
- alertcondition(up2, title='go long2', message='go long2')
- alertcondition(down, title='go short', message='go go short')
- alertcondition(down1, title='go short1', message='go short1')
- bgcolor(down2 > 0 ? red : na, transp=90)
- bgcolor(up2 > 0 ? green : na, transp=50)
- bgcolor(up1 > 0 ? blue : na, transp=90)
- bgcolor(down < 0 ? red : na, transp=50)
- bgcolor(up > 0 ? lime : na, transp=50)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement