Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- study("SuperTrend TEST", overlay=true)
- //This SuperTrend software is used on 15 minute chart. The second part of SuperTrend is for security on 120 minute timeframe.
- //SuperTrend should give signal on 15 minute chart only when SuperTrend is in same direction of 120 minute timeframe.
- length = input(title="ATR Period", type=input.integer, defval=7)
- mult = input(title="ATR Multiplier", type=input.float, step=0.1, defval=5)
- showLabels = input(title="Show Buy/Sell Labels ?", type=input.bool, defval=true)
- atr = mult * atr(length)
- longStop = hl2 - atr
- longStopPrev = nz(longStop[1], longStop)
- longStop := close[1] > longStopPrev ? max(longStop, longStopPrev) : longStop
- shortStop = hl2 + atr
- shortStopPrev = nz(shortStop[1], shortStop)
- shortStop := close[1] < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop
- dir = 1
- dir := nz(dir[1], dir)
- dir := dir == -1 and close > shortStopPrev ? 1 :
- dir == 1 and close < longStopPrev ? -1 : dir
- longColor = color.blue
- shortColor = color.red
- //---------------
- //SuperTrend on 120 minute timeframe.
- length120 = input(title="ATR Period", type=input.integer, defval=7)
- mult120 = input(title="ATR Multiplier", type=input.float, step=0.1, defval=5)
- atr120 = mult120 * atr(length120)
- sechigh120 = security(syminfo.ticker, "120", (high), lookahead = barmerge.lookahead_on)
- seclow120 = security(syminfo.ticker, "120", (low), lookahead = barmerge.lookahead_on)
- secclose120 = security(syminfo.ticker, "120", (close), lookahead = barmerge.lookahead_on)
- longStop120 = (sechigh120 + seclow120)/2 - atr120
- longStopPrev120 = nz(longStop120[1], longStop120)
- longStop120 := secclose120[1] > longStopPrev120 ? max(longStop120, longStopPrev120) : longStop120
- shortStop120 = (sechigh120 + seclow120)/2 + atr120
- shortStopPrev120 = nz(shortStop120[1], shortStop120)
- shortStop120 := secclose120[1] < shortStopPrev120 ? min(shortStop120, shortStopPrev120) : shortStop120
- dir120 = 1
- dir120 := nz(dir120[1], dir120)
- dir120 := dir120 == -1 and secclose120 > shortStopPrev120 ? 1 :
- dir120 == 1 and secclose120 < longStopPrev120 ? -1 : dir120
- longColor120 = color.blue
- shortColor120 = color.red
- //---------------
- plot(dir == 1 ? longStop : na, title="Long Stop", style=plot.style_linebr, linewidth=2, color=longColor)
- buySignal15 = dir == 1 and dir[1] == -1
- buySignal120 = dir120 == 1 and dir120[1] == -1
- plotshape(buySignal15 and buySignal120 ? longStop : na, title="Long Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=longColor, transp=0)
- plotshape(buySignal15 and buySignal120 and showLabels ? longStop : na, title="Buy Label", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=longColor, textcolor=color.white, transp=0)
- plot(dir == 1 ? na : shortStop, title="Short Stop", style=plot.style_linebr, linewidth=2, color=shortColor)
- sellSignal15 = dir == -1 and dir[1] == 1
- sellSignal120 = dir120 == -1 and dir120[1] == 1
- plotshape(sellSignal15 and sellSignal120 ? shortStop : na, title="Short Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=shortColor, transp=0)
- plotshape(sellSignal15 and sellSignal120 and showLabels ? shortStop : na, title="Sell Label", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=shortColor, textcolor=color.white, transp=0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement