SuperTrend TradingView Look-A-Like For ThinkOrSwim

Latest revisions of this has EMA cross as a filter.
Can someone please tell me why Supertrend is not working correctly for me. Note the attached image. Candles are closed but 'SELL' is not printed. It initially prints, lasts about 2 seconds then disappears. I circled the areas in question. I am new to this site so hopefully I posted correctly. If not please do not criticize, but provide helpful instruction (in plain english please, I am not a coder). As you can see 'BUY' alerts work fine.

RlUxs7O.jpg
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Here is how to use this. Save the script below to a study, and then you can select either the LongAlert or ShortAlert from the filter settings as plot option and select "is true" for the value.

Code:
# SuperTrend Yahoo Finance Replica - Modified from Modius SuperTrend
# Modified Modius ver. by RConner7
# Modified by Barbaros to replicate look from TradingView version
# Modified by Barbaros to add EMA cross for bubbles and alerts
# Modified by Barbaros to update bar color painting
# v3.3 - Scanner

input AtrMult = 1.00;
input nATR = 6;
input AvgType = AverageType.HULL;
input PaintBars = yes;
input ShowBubbles = yes;
input ShowLabels = yes;
input UseEmaCross = yes;
input EMA1 = 10;
input EMA2 = 20;

def ATR = ATR("length" = nATR, "average type" = AvgType);
def UP_Band_Basic = HL2 + (AtrMult * ATR);
def LW_Band_Basic = HL2 + (-AtrMult * ATR);
def UP_Band = if ((UP_Band_Basic < UP_Band[1]) or (close[1] > UP_Band[1])) then UP_Band_Basic else UP_Band[1];
def LW_Band = if ((LW_Band_Basic > LW_Band[1]) or (close[1] < LW_Band[1])) then LW_Band_Basic else LW_Band[1];

def ST = if ((ST[1] == UP_Band[1]) and (close < UP_Band)) then UP_Band
else if ((ST[1] == UP_Band[1]) and (close > Up_Band)) then LW_Band
else if ((ST[1] == LW_Band[1]) and (close > LW_Band)) then LW_Band
else if ((ST[1] == LW_Band) and (close < LW_Band)) then UP_Band
else LW_Band;

def EMA1Val = MovAvgExponential(close, EMA1);
def EMA2Val = MovAvgExponential(close, EMA2);
def EMADirection = if EMA1Val > EMA2Val then 1 else if EMA1Val < EMA2Val then -1 else 0;

def Long = if close > ST then ST else Double.NaN;
def Short = if close < ST then ST else Double.NaN;

def LongTrigger = isNaN(Long[1]) and !isNaN(Long);
def ShortTrigger = isNaN(Short[1]) and !isNaN(Short);

def LongDot = if LongTrigger then ST else Double.NaN;
def ShortDot = if ShortTrigger then ST else Double.NaN;

def LongConfirm = (UseEmaCross and close > ST and EMADirection == 1) or (!UseEmaCross and LongTrigger);
def ShortConfirm = (UseEmaCross and close < ST and EMADirection == -1) or (!UseEmaCross and ShortTrigger);

plot LongAlert = LongConfirm and LongConfirm[1] != LongConfirm;
plot ShortAlert = ShortConfirm and ShortConfirm[1] != ShortConfirm;

# End Code SuperTrend Yahoo Finance Replica
I tried using this as a scan, and all I get is No matching symbols. I'm not sure what the problem is. I even tried to show within 10 bars and nothing. Any ideas?
 
SuperTrend TradingView Look-A-Like For ThinkOrSwim

I modified a version of SuperTrend that is already available for Thinkorswim to imitate the style.

kyuKOnh.png


You can adjust the look from the options. Labels are turned off by default.
4GZNCcv.png


It also has alerts for trend change.
DnqfdSv.png


Python:
# SuperTrend Yahoo Finance Replica - Modified from Modius SuperTrend
# Modified Modius ver. by RConner7
# Modified by Barbaros to replicate look from TradingView version
# v3.0

input AtrMult = 1.00;
input nATR = 6;
input AvgType = AverageType.HULL;
input PaintBars = no;
input ShowBubbles = no;

def ATR = ATR("length" = nATR, "average type" = AvgType);
def UP_Band_Basic = HL2 + (AtrMult * ATR);
def LW_Band_Basic = HL2 + (-AtrMult * ATR);
def UP_Band = if ((UP_Band_Basic < UP_Band[1]) or (close[1] > UP_Band[1])) then UP_Band_Basic else UP_Band[1];
def LW_Band = if ((LW_Band_Basic > LW_Band[1]) or (close[1] < LW_Band[1])) then LW_Band_Basic else LW_Band[1];

def ST = if ((ST[1] == UP_Band[1]) and (close < UP_Band)) then UP_Band
else if ((ST[1] == UP_Band[1]) and (close > Up_Band)) then LW_Band
else if ((ST[1] == LW_Band[1]) and (close > LW_Band)) then LW_Band
else if ((ST[1] == LW_Band) and (close < LW_Band)) then UP_Band
else LW_Band;

plot Long = if close > ST then ST else Double.NaN;
Long.AssignValueColor(Color.GREEN);
Long.SetLineWeight(2);

plot Short = if close < ST then ST else Double.NaN;
Short.AssignValueColor(Color.RED);
Short.SetLineWeight(3);

def LongTrigger = isNaN(Long[1]) and !isNaN(Long);
def ShortTrigger = isNaN(Short[1]) and !isNaN(Short);

plot LongDot = if LongTrigger then ST else Double.NaN;
LongDot.SetPaintingStrategy(PaintingStrategy.POINTS);
LongDot.AssignValueColor(Color.GREEN);
LongDot.SetLineWeight(4);

plot ShortDot = if ShortTrigger then ST else Double.NaN;
ShortDot.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot.AssignValueColor(Color.RED);
ShortDot.SetLineWeight(4);

AddChartBubble(ShowBubbles and LongTrigger, ST, "BUY", Color.GREEN, no);
AddChartBubble(ShowBubbles and ShortTrigger, ST, "SELL", Color.RED, yes);

AssignPriceColor(if PaintBars and close < ST
               then Color.RED
               else if PaintBars and close > ST
                    then Color.GREEN
                    else Color.CURRENT);

Alert(LongTrigger, "Long", Alert.BAR, Sound.Ding);
Alert(ShortTrigger, "Short", Alert.BAR, Sound.Ding);

# End Code SuperTrend Yahoo Finance Replica

It works well for me with 2 SuperTrends, (1,5 and 2,10) . Enter when both trends have same color and exit when (1,5) trend changed color.
Can you add a dot and bubble at the end of the trend line?.
Thank you very much.
 
It works well for me with 2 SuperTrends, (1,5 and 2,10) . Enter when both trends have same color and exit when (1,5) trend changed color.
Can you add a dot and bubble at the end of the trend line?.
Thank you very much.
Is it NATR 1 and multiplier 5?
 
Can anyone add a cloud to the super trend like the one in this picture, green cloud when its trading up and red cloud when its trading down. Thanks in advance!!

o-use-the-Super-Trend-Indicator-for-MT5-Sell-Trade.png
 
Can anyone add a cloud to the super trend like the one in this picture, green cloud when its trading up and red cloud when its trading down. Thanks in advance!!

o-use-the-Super-Trend-Indicator-for-MT5-Sell-Trade.png
Just add this to the code.
AddCloud(close, long, Color.green, Color.green, no);
AddCloud(short, close, Color.red, Color.red, no);
 
@chewie76 Thank you it worked, but how do you get the cloud to be under the candle to look a little smoother like the image above and not the top wick of the candle, looks a bit more choppy if that make sense. Thanks in advance!
 
@chewie76 Thank you it worked, but how do you get the cloud to be under the candle to look a little smoother like the image above and not the top wick of the candle, looks a bit more choppy if that make sense. Thanks in advance!
If you look close to the picture, the cloud follows the close of the candle. That's what the code says. You could change close to high or low if you want.
 
Can anyone convert this to multi time frame. I know there are some multi time frames supertrends but they are bottom study’s, I like to have this one on my actual charts to see. Love this supertrend in particular this one is my favorite. To be able to put a higher time frame on a lower time frame on this script would be amazing. Thanks in advance!
 
//@version=2
//Original author: Rajandran R from www.marketcalls.in
study("Supertrend Alerts 1.1", overlay = true)
cand_col = input(title="Color Candles", type=bool, defval=true)
show_line = input(title="Show Supertrend Line", type=bool, defval=true)
Factor = input(3, type=float)
PD = input(7, minval = 1, maxval = 100)

Up=hl2-(Factor*atr(PD))
Dn=hl2+(Factor*atr(PD))
TrendUp = close[1] > TrendUp[1] ? max(Up, TrendUp[1]) : Up
TrendDown = close[1] < TrendDown[1] ? min(Dn, TrendDown[1]) : Dn
Trend = close > TrendDown[1] ? 1: close< TrendUp[1]? -1: nz(Trend[1], 1)
TSL = Trend == 1 ? TrendUp : TrendDown
linecolor = Trend == 1 ? color(green, 0) : color(red, 0)
barcolor((cand_col and Trend == 1) ? color(green, 0) : na)
barcolor((cand_col and Trend == -1) ? color(red, 0) : na)
plot(show_line ? TSL : na, color = linecolor , style = line , linewidth = 2, title = "SuperTrend Line", transp=65)
newup = cross(close,TSL) and close>TSL
newdn = cross(TSL,close) and close<TSL
plotshape(newup, "Long", shape.triangleup, location.belowbar, color(green, 0), size=size.normal)
plotshape(newdn, "Short", shape.triangledown , location.abovebar, color(red, 0), size=size.normal)
alertcondition(newup, title='Supertrend Long', message='Supertrend: Long ')
alertcondition(newdn, title='Supertrend Short', message='Supertrend: Short ')
alertcondition(newup or newdn, title='Supertrend Signal', message='Supertrend: Long or Short ')
 
Please help! Would like the following code (Supertrend) to show 5 minute data on the 1 minute chart. Thanks in advance for input.

def c = close;
def H = hl2;

input AtrMult = 1.00;
input nATR = 6;
input AvgType = AverageType.HULL;

def ATR = ATR("length" = nATR, "average type" = AvgType);
def UP_Band_Basic = H + (AtrMult * ATR);
def LW_Band_Basic = H + (-AtrMult * ATR);
def UP_Band = if ((UP_Band_Basic < UP_Band[1]) or (c[1] > UP_Band[1])) then UP_Band_Basic else UP_Band[1];
def LW_Band = if ((LW_Band_Basic > LW_Band[1]) or (c[1] < LW_Band[1])) then LW_Band_Basic else LW_Band[1];

def ST = if ((ST[1] == UP_Band[1]) and (c < UP_Band)) then UP_Band
else if ((ST[1] == UP_Band[1]) and (c > UP_Band)) then LW_Band
else if ((ST[1] == LW_Band[1]) and (c > LW_Band)) then LW_Band
else if ((ST[1] == LW_Band) and (c < LW_Band)) then UP_Band
else LW_Band;

plot BULL = if c > ST then 1 else 0;
BULL.AssignValueColor(Color.black);

plot BEAR = if c < ST then 1 else 0;
BEAR.AssignValueColor(Color.black);

plot ma1 = ExpAverage(close, 18);
ma1.AssignValueColor(if BULL then (CreateColor(0, 230, 118)) else if BEAR then (CreateColor(255, 82, 82)) else Color.YELLOW);
ma1.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
ma1.SetLineWeight(5);

plot ZERO_LINE = 0;

# End Code
 
Please help! Would like the following code (Supertrend) to show 5 minute data on the 1 minute chart. Thanks in advance for input.

def c = close;
def H = hl2;

input AtrMult = 1.00;
input nATR = 6;
input AvgType = AverageType.HULL;

def ATR = ATR("length" = nATR, "average type" = AvgType);
def UP_Band_Basic = H + (AtrMult * ATR);
def LW_Band_Basic = H + (-AtrMult * ATR);
def UP_Band = if ((UP_Band_Basic < UP_Band[1]) or (c[1] > UP_Band[1])) then UP_Band_Basic else UP_Band[1];
def LW_Band = if ((LW_Band_Basic > LW_Band[1]) or (c[1] < LW_Band[1])) then LW_Band_Basic else LW_Band[1];

def ST = if ((ST[1] == UP_Band[1]) and (c < UP_Band)) then UP_Band
else if ((ST[1] == UP_Band[1]) and (c > UP_Band)) then LW_Band
else if ((ST[1] == LW_Band[1]) and (c > LW_Band)) then LW_Band
else if ((ST[1] == LW_Band) and (c < LW_Band)) then UP_Band
else LW_Band;

plot BULL = if c > ST then 1 else 0;
BULL.AssignValueColor(Color.black);

plot BEAR = if c < ST then 1 else 0;
BEAR.AssignValueColor(Color.black);

plot ma1 = ExpAverage(close, 18);
ma1.AssignValueColor(if BULL then (CreateColor(0, 230, 118)) else if BEAR then (CreateColor(255, 82, 82)) else Color.YELLOW);
ma1.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
ma1.SetLineWeight(5);

plot ZERO_LINE = 0;

# End Code

FYI, please do not remove the headers from your scripts.
When you have the header; you can re-find that thread and then find the MTF version within that thread:
https://usethinkscript.com/threads/...a-like-for-thinkorswim.7719/page-2#post-75325
 
Thanks a lot .. This is really helpful
Also is below code is correct way to setup a scan

Code:
# SuperTrend Yahoo Finance Replica - Modified from Modius SuperTrend
# Modified Modius ver. by RConner7
# Modified by Barbaros to replicate look from TradingView version
# v3.0

input AtrMult = 1.00;
input nATR = 6;
input AvgType = AverageType.HULL;
input PaintBars = no;
input ShowBubbles = no;

def ATR = ATR("length" = nATR, "average type" = AvgType);
def UP_Band_Basic = HL2 + (AtrMult * ATR);
def LW_Band_Basic = HL2 + (-AtrMult * ATR);
def UP_Band = if ((UP_Band_Basic < UP_Band[1]) or (close[1] > UP_Band[1])) then UP_Band_Basic else UP_Band[1];
def LW_Band = if ((LW_Band_Basic > LW_Band[1]) or (close[1] < LW_Band[1])) then LW_Band_Basic else LW_Band[1];

def ST = if ((ST[1] == UP_Band[1]) and (close < UP_Band)) then UP_Band
else if ((ST[1] == UP_Band[1]) and (close > Up_Band)) then LW_Band
else if ((ST[1] == LW_Band[1]) and (close > LW_Band)) then LW_Band
else if ((ST[1] == LW_Band) and (close < LW_Band)) then UP_Band
else LW_Band;

def Long = if close > ST then ST else Double.NaN;


def LongTrigger = isNaN(Long[1]) and !isNaN(Long);

plot LongDot = if LongTrigger then 1 else 0;
Yes, this code def works as a scan!! Thx!! I've had trouble previously trying to put this into a scannable code in TOS. Well done!!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
316 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top