xmd79

SuperTrend With EMA100

Nov 15th, 2021
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. //@version=5
  2. indicator('SuperTrend With EMA100', overlay=true, format=format.price, precision=2, timeframe='')
  3.  
  4. Periods = input(title='ATR Period', defval=10)
  5. emaLength = input(title='EMA Length', defval=100)
  6. emass = ta.ema(close, emaLength)
  7. Multiplier = input.float(title='ATR Multiplier', step=0.1, defval=0.5)
  8. changeATR = input(title='Change ATR Calculation Method ?', defval=true)
  9. highlighting = input(title='Highlighter On/Off ?', defval=true)
  10. atr2 = ta.sma(ta.tr, Periods)
  11. atr = changeATR ? ta.atr(Periods) : atr2
  12. up = emass - Multiplier * atr
  13. up1 = nz(up[1], up)
  14. up := close[1] > up1 ? math.max(up, up1) : up
  15. dn = emass + Multiplier * atr
  16. dn1 = nz(dn[1], dn)
  17. dn := close[1] < dn1 ? math.min(dn, dn1) : dn
  18. trend = 1
  19. trend := nz(trend[1], trend)
  20. trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
  21. upPlot = plot(trend == 1 ? up : na, title='Up Trend', style=plot.style_linebr, linewidth=2, color=color.new(color.green, 0))
  22. buySignal = trend == 1 and trend[1] == -1
  23. plotshape(buySignal ? up : na, title='UpTrend Begins', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.green, 0))
  24. dnPlot = plot(trend == 1 ? na : dn, title='Down Trend', style=plot.style_linebr, linewidth=2, color=color.new(color.red, 0))
  25. sellSignal = trend == -1 and trend[1] == 1
  26. plotshape(sellSignal ? dn : na, title='DownTrend Begins', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.red, 0))
  27. mPlot = plot(ohlc4, title='', style=plot.style_circles, linewidth=0)
  28. longFillColor = highlighting ? trend == 1 ? color.green : color.white : color.white
  29. shortFillColor = highlighting ? trend == -1 ? color.red : color.white : color.white
  30. fill(mPlot, upPlot, title='UpTrend Highligter', color=longFillColor, transp=90)
  31. fill(mPlot, dnPlot, title='DownTrend Highligter', color=shortFillColor, transp=90)
  32. alertcondition(buySignal, title='SuperTrend Buy', message='SuperTrend Buy!')
  33. alertcondition(sellSignal, title='SuperTrend Sell', message='SuperTrend Sell!')
  34. changeCond = trend != trend[1]
  35. plot(emass, color=color.new(color.blue, 0), linewidth=1)
  36. alertcondition(changeCond, title='SuperTrend Direction Change', message='SuperTrend has changed direction!')
  37.  
  38.  
Advertisement
Add Comment
Please, Sign In to add comment