Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator('SuperTrend With EMA100', overlay=true, format=format.price, precision=2, timeframe='')
- Periods = input(title='ATR Period', defval=10)
- emaLength = input(title='EMA Length', defval=100)
- emass = ta.ema(close, emaLength)
- Multiplier = input.float(title='ATR Multiplier', step=0.1, defval=0.5)
- changeATR = input(title='Change ATR Calculation Method ?', defval=true)
- highlighting = input(title='Highlighter On/Off ?', defval=true)
- atr2 = ta.sma(ta.tr, Periods)
- atr = changeATR ? ta.atr(Periods) : atr2
- up = emass - Multiplier * atr
- up1 = nz(up[1], up)
- up := close[1] > up1 ? math.max(up, up1) : up
- dn = emass + Multiplier * atr
- dn1 = nz(dn[1], dn)
- dn := close[1] < dn1 ? math.min(dn, dn1) : dn
- trend = 1
- trend := nz(trend[1], trend)
- trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
- upPlot = plot(trend == 1 ? up : na, title='Up Trend', style=plot.style_linebr, linewidth=2, color=color.new(color.green, 0))
- buySignal = trend == 1 and trend[1] == -1
- plotshape(buySignal ? up : na, title='UpTrend Begins', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.green, 0))
- dnPlot = plot(trend == 1 ? na : dn, title='Down Trend', style=plot.style_linebr, linewidth=2, color=color.new(color.red, 0))
- sellSignal = trend == -1 and trend[1] == 1
- plotshape(sellSignal ? dn : na, title='DownTrend Begins', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.red, 0))
- mPlot = plot(ohlc4, title='', style=plot.style_circles, linewidth=0)
- longFillColor = highlighting ? trend == 1 ? color.green : color.white : color.white
- shortFillColor = highlighting ? trend == -1 ? color.red : color.white : color.white
- fill(mPlot, upPlot, title='UpTrend Highligter', color=longFillColor, transp=90)
- fill(mPlot, dnPlot, title='DownTrend Highligter', color=shortFillColor, transp=90)
- alertcondition(buySignal, title='SuperTrend Buy', message='SuperTrend Buy!')
- alertcondition(sellSignal, title='SuperTrend Sell', message='SuperTrend Sell!')
- changeCond = trend != trend[1]
- plot(emass, color=color.new(color.blue, 0), linewidth=1)
- alertcondition(changeCond, title='SuperTrend Direction Change', message='SuperTrend has changed direction!')
Advertisement
Add Comment
Please, Sign In to add comment