Archived: Supertrend Indicator by Mobius for ThinkorSwim

Status
Not open for further replies.
Due to my poor math skills I cannot explain this well. Here is the try. The ST is a plot of the fundamental mean of price plus or minus the ATR factor. So a moving average of mean of price plus or minus the ATR factor. The ATR factor is 1 * the ATR or -1 * the ATR. If the close is < previous ST plot the UP ATR factor is added to price and if the close is >previous ST plot the ATR factor is subtracted from the price. My guess is if there is a large price range in a bar or several the ATR becomes large causing the ST plot and price to become farther apart. It then takes a bit for those to come together. The candle color will not change until price crosses the ST plot.
 

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

Due to my poor math skills I cannot explain this well. Here is the try. The ST is a plot of the fundamental mean of price plus or minus the ATR factor. So a moving average of mean of price plus or minus the ATR factor. The ATR factor is 1 * the ATR or -1 * the ATR. If the close is < previous ST plot the UP ATR factor is added to price and if the close is >previous ST plot the ATR factor is subtracted from the price. My guess is if there is a large price range in a bar or several the ATR becomes large causing the ST plot and price to become farther apart. It then takes a bit for those to come together. The candle color will not change until price crosses the ST plot.
@horserider I would agree with that. It is a hazard of Penny Stocks. That first Red Bar in the circled area is pretty heavy to the downside.
 
Ticker SNCA using 1 min timeframe. The chart is from today.


@zeek Think you are using a different study code. Using the thinkScript code for Supertrend from post #1 as posted by @BenTen, I loaded ticker SNCA on a 1 min aggregation and the resulting display is very different from yours. Use the following code. It does not have the problem you reported earlier

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
 
@zeek the line below, from the code you posted, is probably why it acted up. The original that is posted just above is what you want.

# Altered default settings for values that made more sense on Intraday Futures.
 
Crickey! I took a second look at both codes and don't see any differences other than one having the AddChartBubble and the other had it removed. Worse, now they both display the exact same output. Think @markos might be on to something here regarding his comment on penny stocks. This sure is an odd one
 
Put the actual ST plot on the chart. Then see if the plot separates a distance from price. If so it will take a while to fill that difference. As mentioned above. That is my theory and I am sticking to it. ;)
 
Crickey! I took a second look at both codes and don't see any differences other than one having the AddChartBubble and the other had it removed. Worse, now they both display the exact same output. Think @markos might be on to something here regarding his comment on penny stocks. This sure is an odd one

Now that I've had a coffee break, I took a closer look at this issue.

The key to the puzzle is that if the candle closes BELOW the ST line, then the candles would be painted red. Now, how is the ST line computed? It takes the mid point of the candle and calculates an "upper bound" as well as a "lower bound" by adding the average true range. From the example of ticker SNCA, since the "lower bound" level was exceeded, this in turn flags the candle to be painted red. Quick a slick approach the way Mobius designed this study
 
Hmmm Thought it painted red if close was below ST plot green if price breaks above ST plot.. ST plot determined by adding the up or down ATR calculation to median of the candles. But it is the cross of price and ST plot that changes the candle color.
if close < ST then Color.RED

Maybe we are saying the same thing in a different way. Do not know.

I think anyone confused how this works, please enable the ST plot and it should be more clear.
 
@BenTen @tomsk I'm getting scan alerts seemingly randomly. I used the scan code from the initial post (#commenting out either bull or bear for each filter). Added both of them to "Any of the following". Scanning only in /ES. And alerting only when "a symbol is added to scan results". I ensured the 'atr mult' & 'natr' settings are the same in my chart and both scan & charts are set to hourly. I am getting alerts even when no buy or sell signals are created. I know i'm missing something lol. Thanks for any insight! :)


@switchfire Post your complete scan code, I'll take a look at that and see if anything obvious comes up modulo the other comments made here
 
@tomsk The same code on the first page, just 1.5 AtrMult:
Code:
# SuperTrend Scan
# Mobius
# V01.10.2015
# Comment out (#) the direction NOT to use for a scan

input AtrMult = 1.5;
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
 
@switchfire So long as you understand the effects of changing the AtrMult to 1.5, I don't see any apparant issues with that. As a matter of fact running the scan on a daily aggregation on the S&P 500, I obtained 12 results, including BA. Loading the SuperTrend study on a chart, it does look in line with the scan.
 
@switchfire So long as you understand the effects of changing the AtrMult to 1.5, I don't see any apparant issues with that. As a matter of fact running the scan on a daily aggregation on the S&P 500, I obtained 12 results, including BA. Loading the SuperTrend study on a chart, it does look in line with the scan.

It would be nice if i could set up the alerts to only notify if the supertrend has signaled with the closing bar for whichever time frame.
 
Hi All. Hoping you can help me here please. How do I create a supertrend watchlist with the code supplied in above comment? Not sure where to copy the code to. Appreciate any help please. Thanks in advance.
 
@JohnsonM Under your watchlist, there is a dropdown called Custom Quotes. Select one of the option in there and paste the code in. Also, be sure to adjust the timeframe.
 
HI Ben. Thanks so much for your quick reply. Apologies for my ignorance but I cannot see Custom Quotes. Could you please send me a screenshot? I only see Customize but am limited to the studies in there without ability to paste code in ... unless I am looking in the wrong place.
 
@JohnsonM Where you paste your code, there is an option to adjust the timeframe. By default, your watchlist will be assigned to the Daily timeframe. You can switch to another timeframe based on your liking.
 
Ive been playing with a combo of the Supertrend and Ehler's MAMA. Any ideas from anyone on filtering out some go the chop? I tried the Chop Indy that's been posted on one of these threads, tried an ADX/DMI combo, tried various CCI's, all worked to one degree or another, none really knocked my socks off. There seems to be some real experience on this site. Any knowledge I can steal from anyone?
 
I couldn’t find the exact code I see post for ECI Gaussian, but which one are you referring to with the dots ?
 
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
440 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