Archived: Supertrend Indicator by Mobius for ThinkorSwim

Status
Not open for further replies.
@BbenSD By doesn't work, what do you mean by that? No signal? Did you adjust the timeframe in the scanner to the timeframe that you want? By default, it will scan for signals on the daily chart.
Yeah, I've got it on 5 minutes on the TOS side, I've altered nothing in the script except for adding the hashtag to exclude bearish scans.

By saying it doesn't work, I mean the scanner doesn't return results showing the current candle crossing up on the supertrend line, it just shows random conditions unrelated.

this is what I have for the script, and my TOS timeframe is on 5 minutes as well as the indicator + chart:

# 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;
# End Code SuperTrend
 
@BbenSD Using the snippet you posted, I ran the scanner, and here are my results from the S&P 500 watchlist / 5min chart.

I checked some of these results, and they were showing correctly. I do not see any issue on my side.

8Eshhql.png
 
@BbenSD Using the snippet you posted, I ran the scanner, and here are my results from the S&P 500 watchlist / 5min chart.

I checked some of these results, and they were showing correctly. I do not see any issue on my side.

8Eshhql.png
Alright, mine came up with the same results. But if you were to look at the stocks on a 5-minute chart, only 15 of the 50 on that page had within 1 bar, generated the Bullish Supertrend bubble, why? Have any idea to filter out the inaccuracies? And really, thanks for the help bro.
 
@BbenSD Can you post an example or two of the misinformation or "wrong signal"? Preferably through screenshots, so I know what you're looking at on your 5m chart. If you don't know how to upload images, then take a look at this post.
 
Yeah for example, here's adobe. The bubble isn't pertinent to either the close at 1PST or Afterhours, so what is it telling me?

Jdxxg01.jpg
 
@BbenSD The problem seems to be because you have after hours on. I don't use after-hours data when I'm scanning for stuff. I would recommend turning it off. You can also have the option to include after-hours into your scanner by checking the EXT box next to the timeframe selection.
 
@BbenSD The problem seems to be because you have after hours on. I don't use after-hours data when I'm scanning for stuff. I would recommend turning it off. You can also have the option to include after-hours into your scanner by checking the EXT box next to the timeframe selection.

@BenTen One common mistake most people make when using the scanner is that they don't check for aggregations.
For SuperTrend, I always use Daily aggregation, in which case you don't have the extended hours issue
You'll only see the extended hours option only if you scan using intraday aggregations
I just ran that scan on the S&P 500 and obtained 135 results using the code posted above (DAILY)
 
@tomsk I absolutely agree. I used the 5min timeframe for this scanner because it fits the situation that @BbenSD was referring to.
 
@tomsk I absolutely agree. I used the 5min timeframe for this scanner because it fits the situation that @BbenSD was referring to.

Yep. Since Watchlists are such a common facility that many people depend on, perhaps we can rope in @markos to help write a tutorial for setting up watchlists. He did such a stellar job with the tutorial for scans. Just whenever he has the cycles to do so. I'm sure the community would appreciate it
 
@BbenSD The problem seems to be because you have after hours on. I don't use after-hours data when I'm scanning for stuff. I would recommend turning it off. You can also have the option to include after-hours into your scanner by checking the EXT box next to the timeframe selection.

Well guys, I have to first say that I appreciate continued support. I actually have been scanning and using my chart without extended or after hours. It's required to be off for the ORB indicator, which is also why I've been using 5 minutes. I only used after hours to illustrate the scanner using live market data because it was after hours when I took the screenshot. I'll post another screenshot come Monday.

And @tomsk did you see if the Supertrend bubble populated on the most recent bar in your scan of S&P500?

Thanks again dudes.
 
@BbenSD There is nothing wrong with using after-hours data. But when you have a chart with after hours, be sure to have it on for your scanner as well. And just a warning that ThinkorSwim scanner doesn’t respond too well when scanning with after-hours data. That could be the reason why you’re seeing some inaccurate results.
 
@BenTen does the scanner not work after hours. Cant seem to get it to bring anything up. Trying to make a query of the scan for watchlist.
 
@MBF It should work as long as you enable the extended hours option for the scanner. But like I mentioned yesterday, ToS scanner doesn’t work well with extended hours data.
 
Okay, I think its the after hours, I have ext on. I'll try it monday morn. Thanks for replying!
 
@tomsk anyway to reverse the chart bubble to point left of the candlestick instead of the right? Or possibly even relocating the bubbles to top of the screen somewhere so its out of the way of the candlesticks?

Please refer to the pic...the one on the left shows the bubble on the left of the candlestick when you're scrolling back...while the one on the right appears when you're scrolling right or with the market. I think it would be more visible if the chart bubbles where facing the other way so they don't block the current candlesticks...


Also someone here mentioned I think it was @BenTen that this SuperTrend does not repaint...do you know of any other SuperTrends that do not repaint? I really liked what you did with the Magic Trend and the triangles and I was wondering if perhaps you'd be able to do something similar by combining 3 or so SuperTrends that don't repaint and make something like you did with the Magic Trend?
@HighBredCloud some studies require some manual intervention. In settings, check the boxes to add some room at the top and bottom.
ALSO, grab the price scale and slide it up or down to help the bubbles fit. It may change depending on the product you are watching.
Please work with the code in #88 that @tomsk worked on. It is Mobius' code and it has been a great, with no problems for a numerous years.
You will have to play with it. That supertrend is perfect for combining with RSI LaGuerre on your chart. Good luck.
 
@corello Here is the code for that. It comes in 2 parts.

Step 1: Create a new Strategy (not a Study) > Copy and Paste the original code in the first page into it.

Step 2: Add the following code to the end of the script:

Code:
# The following code is for backtesting
def SuperTrendUP = if ST crosses below close then 1 else 0;
def SuperTrendDN = if ST crosses above close then 1 else 0;

Step 3a: If you want to test out bullish strategy then add this code after the code from Step 2:

Code:
# Bullish Orders
AddOrder(OrderType.BUY_TO_OPEN, condition = SuperTrendUp, price = close,100, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "BUY");
AddOrder(OrderType.SELL_TO_CLOSE, condition = SuperTrendDN, price = open,100, tickcolor = Color.RED, arrowcolor = Color.RED, name = "SELL");

Step 3b: If you want to test out bearish strategy then add this code after the code from Step 2:

Code:
# Bearish Orders
AddOrder(OrderType.SELL_TO_OPEN, condition = SuperTrendDN, price = open,100, tickcolor = Color.RED, arrowcolor = Color.RED, name = "SELL");
AddOrder(OrderType.BUY_TO_CLOSE, condition = SuperTrendUp, price = close,100, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "BUY");

Do not place both codes from 3a and 3b into the same script.

Hi all,

I am new to the community and I have to say that it is a wonderful resource, hopefully I will be able to contribute in the near future.

@BenTen in the backtest are the orders for stock only or is it for long calls/puts? If not, is there away to change it for caal/puts?

Thank you for all the information shared here, truly wonderful.
 
@BenTen thanks for getting back to me, would you know how I could change the code to buy options instead of stock? I am just starting to learn thinkscript and still a little lost in it all.
 
@kmeade I don't think so. Never seen a backtesting strategy that allows you to setup buy or sell options instead of stocks.
 
Status
Not open for further replies.

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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