Advertisement
Guest User

Untitled

a guest
May 25th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. //@version=3
  2. study(title='M', overlay=true)
  3.  
  4. //titles
  5. tf1DString = '1D'
  6.  
  7. sma9String = '9 SMA '
  8. sma20String = '20 SMA '
  9. sma30String = '30 SMA '
  10. sma50String = '50 SMA '
  11.  
  12. //colors
  13. color9SMA = color(aqua, 0)
  14. color20SMA = color(yellow, 0)
  15. color30SMA = color(blue, 0)
  16. color50SMA = color(lime, 0)
  17.  
  18. //mas
  19. lengthSMA9 = input(defval=9, title=sma9String)
  20. lengthSMA20 = input(defval=20, title=sma20String)
  21. lengthSMA30 = input(defval=30, title=sma30String)
  22. lengthSMA50 = input(defval=50, title=sma50String)
  23.  
  24. //timeframes
  25. tf1D = input(defval=1440, title=tf1DString)
  26.  
  27. //resolution
  28. chartResolution = interval
  29. if isdaily
  30. chartResolution := 24*60*interval
  31. if isweekly
  32. chartResolution := 24*60*7*interval
  33.  
  34. //visibility
  35. showSMA9 = lengthSMA9
  36. showSMA20 = lengthSMA20
  37. showSMA30 = lengthSMA30
  38. showSMA50 = lengthSMA50
  39.  
  40. //default
  41. sma9 = sma(close, showSMA9 ? lengthSMA9 : 1)
  42. sma20 = sma(close, showSMA20 ? lengthSMA20 : 1)
  43. sma30 = sma(close, showSMA30 ? lengthSMA30 : 1)
  44. sma50 = sma(close, showSMA50 ? lengthSMA50 : 1)
  45. smaEmpty = sma(open, 1)
  46.  
  47. showtf1D = chartResolution
  48.  
  49. //functions
  50. timeframeToString(timeframe) => timeframe == 0 ? 'D' : timeframe == 1440 ? "1D" : tostring(timeframe)
  51.  
  52. maPlot(maSeries) => not na(maSeries) and (abs(maSeries[0] - close[0])/close[0]) ? maSeries : na
  53.  
  54. getMaPlot(timeframe, show, ma) => show ? maPlot(security(tickerid, timeframeToString(timeframe), ma)) : na
  55.  
  56. //smas
  57. plot(getMaPlot(tf1D, showSMA9 and showtf1D, sma9), color=color9SMA, transp=0, linewidth=3, title=sma9String + tf1DString)
  58. plot(getMaPlot(tf1D, showSMA20 and showtf1D, sma20), color=color20SMA, transp=0, linewidth=3, title=sma20String + tf1DString)
  59. plot(getMaPlot(tf1D, showSMA30 and showtf1D, sma30), color=color30SMA, transp=0, linewidth=3, title=sma30String + tf1DString)
  60. plot(getMaPlot(tf1D, showSMA50 and showtf1D, sma50), color=color50SMA, transp=0, linewidth=3, title=sma50String + tf1DString)
  61.  
  62. buy920 = close > getMaPlot(tf1D, showSMA9 and showtf1D, sma9) and close > getMaPlot(tf1D, showSMA20 and showtf1D, sma20)? lime : na
  63. bgcolor(buy920, transp=85, show_last=10, title='BUY /9 /20')
  64.  
  65. sell920 = close < getMaPlot(tf1D, showSMA9 and showtf1D, sma9) and close < getMaPlot(tf1D, showSMA20 and showtf1D, sma20)? red : na
  66. bgcolor(sell920, transp=80, show_last=10, title='SELL \9 \20')
  67.  
  68. long3050 = crossover(getMaPlot(tf1D, showSMA30 and showtf1D, sma30), getMaPlot(tf1D, showSMA50 and showtf1D, sma50))
  69. plotshape(series=long3050, title='LONG 30X50', style=shape.triangleup, location=location.belowbar, color=lime, text='LONG 30X50', transp=0, size=size.small)
  70.  
  71. short3050 = crossunder(getMaPlot(tf1D, showSMA30 and showtf1D, sma30), getMaPlot(tf1D, showSMA50 and showtf1D, sma50))
  72. plotshape(series=short3050, title='SHORT 30X50', style=shape.triangledown, location=location.abovebar, color=red, text='SHORT 30X50', transp=0, size=size.small)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement