Last active
February 9, 2018 08:15
-
-
Save nntoan/5dc424e29f577b82c2b03771a9b0d0d7 to your computer and use it in GitHub Desktop.
Trading View BB Signals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@version=3 | |
//Signals with Bollinger Band with Alerts | |
study(shorttitle="ToanNguyenSignals", title="ToanNguyenSignals", overlay=true) | |
//Define Bollinger Band Variables | |
length = input(20, minval=1) | |
src = input(close, title="Source") | |
mult = input(2.0, minval=0.001, maxval=50) | |
basis = sma(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 = 10, slow = 20 | |
fastMACD = ema(hlc3, fast) | |
slowMACD = ema(hlc3, slow) | |
macd = fastMACD - slowMACD | |
signal = sma(macd, 5) | |
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 = 'SELL SELL SELL!!! Time to Sell!') | |
alertcondition(timetobuy, title='Buy Alert', message = 'Time to Buy') | |
alertcondition(newarrow, title='New Arrow', message = 'New Arrow!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment