- Platform
-
- Thinkorswim
- TradingView
This code is from TV. Can anyone help to convert this into TOS. Thank you! @barbaros
Code:
//@version=3
// Copyright (c) 2019-present, Alex Orekhov (everget)
study("SuperTrend Buy And Sell", overlay=true)
length = input(title="ATR Period", type=integer, defval=1)
mult = input(title="ATR Multiplier", type=float, step=0.1, defval=10.0)
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 = blue
shortColor = blue
//plot
plot(dir == 1 ? longStop : na, title="BuyLine", style=linebr, linewidth=2, color=longColor)
plotshape(dir == 1 and dir[1] == -1 ? longStop : na, title="Buy", style=shape.labelup, location=location.absolute, size=size.normal, text="Buy", transp=0, textcolor = white, color=green, transp=0)
plot(dir == 1 ? na : shortStop, title="SellLine", style=linebr, linewidth=2, color=shortColor)
plotshape(dir == -1 and dir[1] == 1 ? shortStop : na, title="Sell", style=shape.labeldown, location=location.absolute, size=size.normal, text="Sell", transp=0, textcolor = white, color=red, transp=0)
barcolor(dir == 1 ? green: red)
alertcondition(dir == 1 and dir[1] == -1 ? longStop : na, title="Buy", message="Buy!")
alertcondition(dir == 1 and dir[1] == -1 ? longStop : na, title="Buy", message="Buy!")
alertcondition(dir == 1 and dir[1] == -1 ? longStop : na, title="Buy", message="Buy!")
alertcondition(dir == -1 and dir[1] == 1 ? shortStop : na, title="Sell", message="Sell!")
Last edited by a moderator: