Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=3
- //Advanced Buy/Sell Signals with Bollinger Band with Alerts
- study(shorttitle="Advanced Buy/Sell Signals", title="Advanced Buy/Sell Signals", overlay=true)
- c = security(tickerid, "1", close, lookahead=false)
- //Define Bollinger Band Variables
- length = input(21, minval=1)
- src = input(close, title="Source")
- mult = input(2.0, minval=0.001, maxval=50)
- basis = ema(src, length)
- dev = mult * stdev(src, length)
- upper = basis + dev
- lower = basis - dev
- p1 = plot(upper, color=blue)
- p2 = plot(lower, color=blue)
- //Plot Bollinger Band
- plot(basis, color=red)
- fill(p1, p2)
- //Define MACD Variables
- fast = 9, slow = 16
- fastMACD = ema(hlc3, fast)
- slowMACD = ema(hlc3, slow)
- macd = fastMACD - slowMACD
- signal = sma(macd, 7)
- hist = macd - signal
- currMacd = hist[0]
- prevMacd = hist[1]
- currPrice = hl2[0]
- prevPrice = hl2[1]
- buy = currPrice > prevPrice and currMacd > prevMacd
- sell = currPrice < prevPrice and currMacd < prevMacd
- neutral = (currPrice < prevPrice and currMacd > prevMacd) or (currPrice > prevPrice and currMacd < prevMacd)
- //Plot Arrows
- timetobuy = buy==1 and (sell[1]==1 or (neutral[1]==1 and sell[2]==1) or (neutral[1]==1 and neutral[2]==1 and sell[3]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and sell[4]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and neutral[4]==1 and sell[5]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and neutral[4]==1 and neutral[5]==1 and sell[6]==1))
- timetosell = sell==1 and (buy[1]==1 or (neutral[1]==1 and buy[2]==1) or (neutral[1]==1 and neutral[2]==1 and buy[3]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and buy[4]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and neutral[4]==1 and buy[5]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and neutral[4]==1 and neutral[5]==1 and buy[6]==1))
- plotshape(timetobuy, color=blue, location=location.belowbar, style=shape.arrowup)
- plotshape(timetosell, color=red, location=location.abovebar, style=shape.arrowdown)
- //plotshape(neutral, color=black, location=location.belowbar, style=shape.circle)
- //Define Variables for Tack Marks
- a = currPrice - prevPrice
- b = currMacd - prevMacd
- yesterdaysline = ((prevMacd + close[1]) + prevPrice)/2
- todaysline = ((currMacd + close[1]) + currPrice)/2
- //Plot Tack Marks
- plot(todaysline, color = blue, offset = 3, show_last = 1, linewidth = 3)
- plot(yesterdaysline, color = red, offset = 3, show_last = 1, linewidth = 3)
- //Arrow Alerts
- newarrow = timetobuy == 1 or timetosell == 1
- alertcondition(timetosell, title='Sell Alert', message = 'Time to Sell!')
- alertcondition(timetobuy, title='Buy Alert', message = 'Time to Buy')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement