Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=3
- study(title='M', overlay=true)
- //titles
- tf1DString = '1D'
- sma9String = '9 SMA '
- sma20String = '20 SMA '
- sma30String = '30 SMA '
- sma50String = '50 SMA '
- //colors
- color9SMA = color(aqua, 0)
- color20SMA = color(yellow, 0)
- color30SMA = color(blue, 0)
- color50SMA = color(lime, 0)
- //mas
- lengthSMA9 = input(defval=9, title=sma9String)
- lengthSMA20 = input(defval=20, title=sma20String)
- lengthSMA30 = input(defval=30, title=sma30String)
- lengthSMA50 = input(defval=50, title=sma50String)
- //timeframes
- tf1D = input(defval=1440, title=tf1DString)
- //resolution
- chartResolution = interval
- if isdaily
- chartResolution := 24*60*interval
- if isweekly
- chartResolution := 24*60*7*interval
- //visibility
- showSMA9 = lengthSMA9
- showSMA20 = lengthSMA20
- showSMA30 = lengthSMA30
- showSMA50 = lengthSMA50
- //default
- sma9 = sma(close, showSMA9 ? lengthSMA9 : 1)
- sma20 = sma(close, showSMA20 ? lengthSMA20 : 1)
- sma30 = sma(close, showSMA30 ? lengthSMA30 : 1)
- sma50 = sma(close, showSMA50 ? lengthSMA50 : 1)
- smaEmpty = sma(open, 1)
- showtf1D = chartResolution
- //functions
- timeframeToString(timeframe) => timeframe == 0 ? 'D' : timeframe == 1440 ? "1D" : tostring(timeframe)
- maPlot(maSeries) => not na(maSeries) and (abs(maSeries[0] - close[0])/close[0]) ? maSeries : na
- getMaPlot(timeframe, show, ma) => show ? maPlot(security(tickerid, timeframeToString(timeframe), ma)) : na
- //smas
- plot(getMaPlot(tf1D, showSMA9 and showtf1D, sma9), color=color9SMA, transp=0, linewidth=3, title=sma9String + tf1DString)
- plot(getMaPlot(tf1D, showSMA20 and showtf1D, sma20), color=color20SMA, transp=0, linewidth=3, title=sma20String + tf1DString)
- plot(getMaPlot(tf1D, showSMA30 and showtf1D, sma30), color=color30SMA, transp=0, linewidth=3, title=sma30String + tf1DString)
- plot(getMaPlot(tf1D, showSMA50 and showtf1D, sma50), color=color50SMA, transp=0, linewidth=3, title=sma50String + tf1DString)
- buy920 = close > getMaPlot(tf1D, showSMA9 and showtf1D, sma9) and close > getMaPlot(tf1D, showSMA20 and showtf1D, sma20)? lime : na
- bgcolor(buy920, transp=85, show_last=10, title='BUY /9 /20')
- sell920 = close < getMaPlot(tf1D, showSMA9 and showtf1D, sma9) and close < getMaPlot(tf1D, showSMA20 and showtf1D, sma20)? red : na
- bgcolor(sell920, transp=80, show_last=10, title='SELL \9 \20')
- long3050 = crossover(getMaPlot(tf1D, showSMA30 and showtf1D, sma30), getMaPlot(tf1D, showSMA50 and showtf1D, sma50))
- plotshape(series=long3050, title='LONG 30X50', style=shape.triangleup, location=location.belowbar, color=lime, text='LONG 30X50', transp=0, size=size.small)
- short3050 = crossunder(getMaPlot(tf1D, showSMA30 and showtf1D, sma30), getMaPlot(tf1D, showSMA50 and showtf1D, sma50))
- 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