Archived: Supertrend Indicator by Mobius for ThinkorSwim

Status
Not open for further replies.

BenTen

Administrative
Staff member
Staff
VIP
Lifetime

These are the archived posts for the Supertrend. The current thread can be found:


This is a Supertrend indicator for ThinkorSwim created by Mobius.

What's new in V03.10.2015
  • Added Bubbles to mark entry and exit prices. Doesn't give much time to follow into trade, but better than guessing.
  • Altered default settings for values that made more sense on Intraday Futures. Added Color and ColorBars.

Supertrend Indicator: shows trend direction and gives buy or sell signals according to that. It is based on a combination of the average price rate in the current period along with a volatility indicator. The ATR indicator is most commonly used as volatility indicator. The values are calculated as follows:

Up = (HIGH + LOW) / 2 + Multiplier * ATR
Down = (HIGH + LOW) / 2 – Multiplier * ATR
When the change of trend occurs, the indicator flips

N3y7JFY.png


thinkScript Code for Supertrend

Code:
# Mobius
# SuperTrend
# Chat Room Request
input AtrMult = 1.0;
input nATR = 4;
input AvgType = AverageType.HULL;
input PaintBars = yes;
def ATR = MovingAverage(AvgType, TrueRange(high, close, low), nATR);
def UP = HL2 + (AtrMult * ATR);
def DN = HL2 + (-AtrMult * ATR);
def ST = if close < ST[1] then UP else DN;
plot SuperTrend = ST;
SuperTrend.AssignValueColor(if close < ST then Color.RED else Color.GREEN);
AssignPriceColor(if PaintBars and close < ST

                 then Color.RED

                 else if PaintBars and close > ST

                      then Color.GREEN

                      else Color.CURRENT);

AddChartBubble(close crosses below ST, low[1], low[1], color.Dark_Gray);
AddChartBubble(close crosses above ST, high[1], high[1], color.Dark_Gray, no);
# End Code SuperTrend

SuperTrend Scanner for ThinkorSwim

Code:
# SuperTrend Scan
# Mobius
# V01.10.2015
# Comment out (#) the direction NOT to use for a scan

input AtrMult = .70;
input nATR = 4;
input AvgType = AverageType.HULL;
def h = high;
def l = low;
def c = close;
def v = volume;
def ATR = MovingAverage(AvgType, TrueRange(h, c, l), nATR);
def UP = HL2 + (AtrMult * ATR);
def DN = HL2 + (-AtrMult * ATR);
def ST = if c < ST[1]
         then Round(UP / tickSize(), 0) * tickSize()
         else Round(DN / tickSize(), 0) * tickSize();
#plot SuperTrendUP = if ST crosses below close then 1 else 0;
plot SuperTrendDN = if ST crosses above close then 1 else 0;
# End Code SuperTrend

Shareable Link

https://tos.mx/mK9Vgg

For anyone looking for the mobile version of this indicator, here is the link to that.

Video Tutorial

 
Last edited by a moderator:

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

Screenshot (179).png

Everything You Want To Know About SuperTrend Indicators And Were Afraid To Ask.
Study and scanner found in Post#1 https://usethinkscript.com/threads/supertrend-indicator-by-mobius-for-thinkorswim.7/#post-12
Install instructions: https://usethinkscript.com/threads/how-to-import-existing-thinkscript-code-on-thinkorswim.10/
Start out with extended hours off.

Screenshot (85).png


What Is The Supertrend Indicator
Screenshot (175).png
1. How can you tell if you are in a trending market and avoid false signals?​
Use three time frames to decipher the long, medium, and short-term trends.​
2. Which timeframes you ask? Here is a summary of how to determine what timeframes to use:​
Screenshot (177).png
The indicator does well with the default multiplier setting. There is no best setting for any trading indicator.​
  • Smaller settings can make the indicator more reactive to the price which means, more signals
  • Higher settings will remove the noise from the market at the risk of less trading signals
Read through this thread to see the various ways members have adjusted this setting to fit their strategy.​


How Does It Work?
Screenshot (178).png
Video Tutorial:


Best Time Frame for SuperTrend is:
5Min – 15Min – 30Min – 1Hr ( 5- 10 days Charts )
Aggregations under 5min have more false signals due to noise.
Sell signals on aggregations 4hr and higher can result in giving back profit.

What Indicators Pair Best With The SuperTrend Indicator
All trending strategies work best when combined with:
  • Trend/Momentum study: RSI or MACD, etc
  • Support & Resistance (can be hand-drawn or a study)
  • Volume
 
This does not work in TOS IOS app appropriately - mainly bubbles with prices do not appear.

Do you have any idea how to fix it? Thanks

 
I am ok with just the line from supertrend. Just need to see when the candles closes on which side of the line relative to other indicators and key support /resistance. It has some good purpose so far.

Thanks to all.

 
@San If you want to remove the bubble, delete the following lines from the code:

Rich (BB code):
AddChartBubble(close crosses below ST, low[1], low[1], color.Dark_Gray); 
AddChartBubble(close crosses above ST, high[1], high[1], color.Dark_Gray, no);
 
Its working great.. U always rocking...

"Paris: Here's SuperTrend MTF for those interested, from my archives - complete with notes posted at the time the study was released"

Code:
# SuperTrend Multiple Time Frames
# Mobius
# V03.01.2016

# I pulled this study down from MyTrade for a reason. It wasn't
# plotting correctly with the multiple aggregations. And like
# all studies with secondary aggregations it tends to replot the
# higher ones. I decided to think about it some more and this is
# where I am with the ST MTF study now.
#
# It's still squirrely and blinks a lot. Using declare Once_Per_Bar
# does some bad things to it. I was considering making intra
# aggregation higher time frames. A pain to do but it gives more
# control over how it plots.
#
# Row 6 is supposed to be the output for all aggregations and the
# signal line. After hours when data isn't moving it's steady and
# has good signals. But since it's after hours, totally useless
# for any intraday trading.

declare lower;

input agg1 = AggregationPeriod.Five_Min;
input agg2 = AggregationPeriod.Ten_Min;
input agg3 = AggregationPeriod.Fifteen_Min;
input agg4 = AggregationPeriod.Thirty_Min;
input agg5 = AggregationPeriod.Hour;
input AtrMult = .70;
input nATR = 4;
input AvgType = AverageType.HULL;

script ST{
input agg = AggregationPeriod.Five_Min;
input AtrMult = .70;
input nATR = 4;
input AvgType = AverageType.HULL;
def Fh = FundamentalType.High;
def Fl = FundamentalType.Low;
def Fc = FundamentalType.Close;
def Fhl2 = FundamentalType.HL2;
def h = Fundamental(Fh, period = agg);
def l = Fundamental(Fl, period = agg);
def c = Fundamental(Fc, period = agg);
def hl = Fundamental(Fhl2, period = agg);
def ATR = MovingAverage(AvgType, TrueRange(h, c, l), nATR);
def UP = hl + (AtrMult * ATR);
def DN = hl + (-AtrMult * ATR);
def S = if c < S[1]
        then Round(UP / tickSize(), 0) * tickSize()
        else Round(DN / tickSize(), 0) * tickSize();
plot ST = if c > S then 1 else 0;
}
def cl = close;
def x = isNaN(cl[2]) and !isNaN(cl[3]);
def FirstAgg = ST(agg = agg1, AtrMult = AtrMult, nATR = nATR, AvgType = AvgType);
plot FirstAggPlot = if isNaN(cl)
                    then double.nan
                    else 1;
FirstAggPlot.SetStyle(Curve.Points);
FirstAggPlot.SetLineWeight(3);
FirstAggPlot.AssignValueColor(if FirstAgg == 1
                              then color.green
                              else color.red);
AddChartBubble(x, 1, (agg1/1000/60) + " min", color.white, yes);
def SecondAgg = ST(agg = agg2, AtrMult = AtrMult, nATR = nATR, AvgType = AvgType);
plot SecondAggPlot = if isNaN(cl)
                     then double.nan
                     else 2;
SecondAggPlot.SetStyle(Curve.Points);
SecondAggPlot.SetLineWeight(3);
SecondAggPlot.AssignValueColor(if SecondAgg == 1
                               then color.green
                               else color.red);
AddChartBubble(x, 2, (agg2/1000/60) + " min", color.white, yes);
def ThirdAgg = ST(agg = agg3, AtrMult = AtrMult, nATR = nATR, AvgType = AvgType);
plot ThirdAggPlot = if isNaN(cl)
                    then double.nan
                    else 3;
ThirdAggPlot.SetStyle(Curve.Points);
ThirdAggPlot.SetLineWeight(3);
ThirdAggPlot.AssignValueColor(if ThirdAgg == 1
                              then color.green
                              else color.red);
AddChartBubble(x, 3, (agg3/1000/60) + " min", color.white, yes);
def FourthAgg = ST(agg = agg4, AtrMult = AtrMult, nATR = nATR, AvgType = AvgType);
plot FourthAggPlot = if isNaN(cl)
                     then double.nan
                     else 4;
FourthAggPlot.SetStyle(Curve.Points);
FourthAggPlot.SetLineWeight(3);
FourthAggPlot.AssignValueColor(if FourthAgg == 1
                               then color.green
                               else color.red);
AddChartBubble(x, 4, (agg4/1000/60) + " min", color.white, yes);
def FifthAgg = ST(agg = agg5, AtrMult = AtrMult, nATR = nATR, AvgType = AvgType);
plot FifthAggPlot = if isNaN(cl)
                    then double.nan
                    else 5;
FifthAggPlot.SetStyle(Curve.Points);
FifthAggPlot.SetLineWeight(3);
FifthAggPlot.AssignValueColor(if FifthAgg == 1
                              then color.green
                              else color.red);
AddChartBubble(x, 5, (agg5/1000/60)+ " min", color.white, yes);
plot Six = if isNaN(cl)
           then double.nan
           else 6;
Six.SetStyle(Curve.Points);
Six.SetLineWeight(3);
Six.AssignValueColor(if FirstAgg and
                        SecondAgg and
                        ThirdAgg and
                        FourthAgg and
                        FifthAgg
                     then color.green
                     else if !FirstAgg and
                             !SecondAgg and
                             !ThirdAgg and
                             !FourthAgg and
                             !FifthAgg
                          then color.red
                     else color.black);
# End Code ST MTF
 
Thank you for sharing. You say the values are ideal for futures but which values would you recommend for intraday equities and options trading? Thanks again.

 
@full_of_options That was the note from the original author. I'm not sure what he was referring to.

 
@wombat711 Pay attention to the following lines:

Rich (BB code):
plot SuperTrendUP = if ST crosses below close then 1 else 0;
plot SuperTrendDN = if ST crosses above close then 1 else 0;
  • Include the first one if you're looking for bullish trend.
  • Include the second one if you're looking for bearish trend.
Never have both on the same scanner.
 
Hey guys - just found this forum. Looked awesome so I signed up. I've got the supertrend indicator and love it. The scanner - I cannot get it to return anything. Has anyone successfully run this scanner? I've had it search for values = 1.0, >1.0, > or =1.0, and all the same options but for 0. What am I missing?!

 
I use the scanner each trading day. The code is written to show new signals

#plot SuperTrendUP = if ST crosses below close then 1 else 0;

plot SuperTrendDN = if ST crosses above close then 1 else 0;

If you want to show active signals use the following;

plot SuperTrendUP = if ST < close then 1 else 0;

plot SuperTrendDN = if ST >close then 1 else 0;

 
@BenTen posted, when it comes to scanning, you can use as many inputs and defs as you need, but you can only run one plot:

Given the following last two lines of the SuperTrend scan:

Rich (BB code):
#plot SuperTrendUP = if ST crosses below close then 1 else 0;
plot SuperTrendDN = if ST crosses above close then 1 else 0;

You'll notice the hashtag character (#) in the beginning of the first line. That comments out that plot statement so the compiler skips over it and runs the second plot statement. When you want to run the first plot statement, you just delete the hashtag and type another hashtag in front of the first plot statement.

Hope this helps...

Good Luck and Good Trading :)
 
@mc01439

Guys thanks so much for the quick responses. I found my problem. This probably should have been understood by me - but I've never scanned this way. You have to use the "thinkscript editor" in the scan - no the "condition wizard". I've always used the wizard. See below. Thanks again!

Cnaoht5.png


 
Status
Not open for further replies.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
320 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