Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. //@version=3
  2. //Advanced Buy/Sell Signals with Bollinger Band with Alerts
  3. study(shorttitle="Advanced Buy/Sell Signals", title="Advanced Buy/Sell Signals", overlay=true)
  4. c = security(tickerid, "1", close, lookahead=false)
  5. //Define Bollinger Band Variables
  6. length = input(21, minval=1)
  7. src = input(close, title="Source")
  8. mult = input(2.0, minval=0.001, maxval=50)
  9. basis = ema(src, length)
  10. dev = mult * stdev(src, length)
  11. upper = basis + dev
  12. lower = basis - dev
  13. p1 = plot(upper, color=blue)
  14. p2 = plot(lower, color=blue)
  15.  
  16. //Plot Bollinger Band
  17. plot(basis, color=red)
  18. fill(p1, p2)
  19.  
  20.  
  21. //Define MACD Variables
  22. fast = 9, slow = 16
  23. fastMACD = ema(hlc3, fast)
  24. slowMACD = ema(hlc3, slow)
  25. macd = fastMACD - slowMACD
  26. signal = sma(macd, 7)
  27. hist = macd - signal
  28. currMacd = hist[0]
  29. prevMacd = hist[1]
  30. currPrice = hl2[0]
  31. prevPrice = hl2[1]
  32.  
  33. buy = currPrice > prevPrice and currMacd > prevMacd
  34. sell = currPrice < prevPrice and currMacd < prevMacd
  35. neutral = (currPrice < prevPrice and currMacd > prevMacd) or (currPrice > prevPrice and currMacd < prevMacd)
  36. //Plot Arrows
  37.  
  38. 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))
  39.  
  40.  
  41.  
  42. 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))
  43. plotshape(timetobuy, color=blue, location=location.belowbar, style=shape.arrowup)
  44. plotshape(timetosell, color=red, location=location.abovebar, style=shape.arrowdown)
  45. //plotshape(neutral, color=black, location=location.belowbar, style=shape.circle)
  46.  
  47. //Define Variables for Tack Marks
  48. a = currPrice - prevPrice
  49. b = currMacd - prevMacd
  50. yesterdaysline = ((prevMacd + close[1]) + prevPrice)/2
  51. todaysline = ((currMacd + close[1]) + currPrice)/2
  52.  
  53. //Plot Tack Marks
  54. plot(todaysline, color = blue, offset = 3, show_last = 1, linewidth = 3)
  55. plot(yesterdaysline, color = red, offset = 3, show_last = 1, linewidth = 3)
  56.  
  57. //Arrow Alerts
  58. newarrow = timetobuy == 1 or timetosell == 1
  59. alertcondition(timetosell, title='Sell Alert', message = 'Time to Sell!')
  60. alertcondition(timetobuy, title='Buy Alert', message = 'Time to Buy')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement