SuperTrend Oscillator v2

This is a republishing of my SuperTrend Oscillator indicator with added features and an explanation of its uses.
First and foremost, thanks to whomever's code or scraps of code was borrowed to make this.
Borrowed from:
-BlindFreddy's SuperTrend BF
-LazyBear's ATR Pips
-ChrisMoody's Stochastic Multi-Timeframe
//Explanation (for the workings of the oscillator open up the editor)
The oscillator displays on its midline and on the histogram bars the SuperTrend trend. The histogram's top changes color based its slope. Purple Histogram bars are denoted extreme levels, marking an extreme distance between price and trend, and will often retrace or consolidate (though not always, this is purely contextual). To help visualize possible retracements, dots on the histogram's top appear to signal that both the trend's slope and price are moving against the trend for as much as five periods after an extreme level is signaled. It should be noted that trend reversals
usually flash purple because the SuperTrend multiplier will make the oscillator jump more than price moved.
This indicator displays the difference between price (close) and the SuperTrend line to gauge price momentum relative to the (super)trend. Much like the Commodity Channel Index ( CCI ) the STO will detect emerging trends or trend exhaustion. It is however superior to the CCI in that the SuperTrend basis will detect and maintain its direction towards the trend. It will show highs and lows relative to the trend, often allowing you to anticipate breakouts/downs.
//Application model
On this chart I demonstrated what I believe (so far) to be its best uses; I map trend support/resist levels on the oscillator (here on the daily) and transpose them onto price. The trend support/resist levels will give me an indication of the trend's momentum relative to price; if these are broken the trend is failing. The price transposed S&R levels show where the momentum gains were made; these are key trend levels that are often broken shortly after their STO counterparts break.
I plot minor S&R levels in gray; they mark single periods where the trend advanced             .
I plot major S&R levels in white; they mark multiple periods of trend advancement and are often key to maintaining the trend.
I displayed two trades here that were executed using the older version of the STO (accompanied by other indicators and further research).
The first is a H&S short with an anticipated right shoulder fall, confirmed by the trend breaking to new lows. The target was a 38.2% fib retracement target.
The second is a rising wedge/double bottom long with an anticipated local resistance break, confirmed by a trend resist test (break anticipated). The target was the aforementioned right shoulder high.
Note that these trades where set up independently of the STO, but that it was instrumental to anticipating price action relative to S&R levels. Note also that retracement dots came in too early for both trades, but effectively warned of price consolidation.
//Additional examples
Trading range in teal, SuperTrend profit in blue and STO profit in purple.
These were interesting trades I came across while paper trading/backtesting the oscillator.
An example of whipsawing price made easy to trade. When the market only gives you odd spikes retracement dots work very well.
I entered the trade on the basis that price attempted to form an abcd higher but failed and broke an S&R level.
I often exit trades when on top of retracement dots and the STO displays higher highs (like the exit here) or lower lows.
An example here of a trend emerging and being confirmed by a break.
Remove from Favorite Scripts Add to Favorite Scripts
//Thank you to whomever's code or scraps of code was borrowed to make this (borrowed from LazyBear, blindfreddy, ChrisMoody and perhaps others)
//Green/red historgram is the supertrend trend
//Green/red line (slope of the histogram) is movement of price relative to the supertrend line
//Purple for extreme  moves -> they often retrace/consolidate, especially on larger timeframes
study(title="SuperTrend Oscillator",overlay = false)
useCurrentRes = input(true, title="Use Current Chart Resolution?")
resCustom = input(title="Use Different Timeframe? Uncheck Box Above", type=resolution, defval="240")
res = useCurrentRes ? period : resCustom
ebc=input(false, title="Paint Extreme Bars Purple?")
urc=input(true, title="Use Retracement Circles?")
uah=input(true, title="Display Trend On Histogram?")
length = input(12, minval=1, title="SuperTrend Length")
lengthema = input(12, minval=1, title="EMA Length")
lengthbb = input(12, minval=1, title="BB Length")
mult = input(3, type="float",minval=1, title="SuperTrend Multiplier")
sb=input(true, title="Use BB")
m = input(2, minval=1, maxval=50, title="BB Multiplier")
//SuperTrend code
avgTR = atr(length)
newshortband= hl2 + avgTR * mult
newlongband= hl2 - avgTR * mult
longband=close[1]>longband[1]? max(newlongband,longband[1]) : newlongband
shortband=close[1]<shortband[1]? min(newshortband,shortband[1]) : newshortband
trendres = close > shortband[1] ? 1: close< longband[1]? -1: nz(trendres[1],1)
trend = security(tickerid, res, trendres)
suptres = trend==1? longband: shortband
supt = security(tickerid, res, suptres)
//SuperTrend Oscillator code
sptres = (close - supt)
spt = security(tickerid, res, sptres)
//EMA of SuperTrend code
sptemares = ema(spt, lengthema)
sptema = security(tickerid, res, sptemares)
//Bollinger Bands of Supertrend Oscillator code
basisres = sb?sma(spt, lengthbb):na
basis = security(tickerid, res, basisres)
devres = sb?m * stdev(spt, lengthbb):na
dev = security(tickerid, res, devres)
upper = sb ? (basis + dev) : na
lower = sb ? (basis - dev) : na
slope_spt_level_up1 = (spt) > (spt) [1]
slope_spt_level_down1 = (spt) < (spt) [1]
slope_spt_level_up2 = (spt) > (spt) [2]
slope_spt_level_down2 = (spt) < (spt) [2]
slope_spt_level_up3 = (spt) > (spt) [3]
slope_spt_level_down3 = (spt) < (spt) [3]
slope_spt_level_up4 = (spt) > (spt) [4]
slope_spt_level_down4 = (spt) < (spt) [4]
slope_spt_level_up5 = (spt) > (spt) [5]
slope_spt_level_down5 = (spt) < (spt) [5]
slope_spt_level_up6 = (spt) > (spt) [6]
slope_spt_level_down6 = (spt) < (spt) [6]
slope_spt_level_up7 = (spt) > (spt) [7]
slope_spt_level_down7 = (spt) < (spt) [7]
slope_spt_level_up8 = (spt) > (spt) [8]
slope_spt_level_down8 = (spt) < (spt) [8]
slope_spt_level_up9 = (spt) > (spt) [9]
slope_spt_level_down9 = (spt) < (spt) [9]
slope_spt_level_up10 = (spt) > (spt) [10]
slope_spt_level_down10 = (spt) < (spt) [10]
uptrendextreme = (spt>0) and (spt>upper)
downtrendextreme = (spt<0) and (spt<lower)
trendextreme = uptrendextreme or downtrendextreme
trendwarningup1=(uptrendextreme[1] and (close<close[1]) and (trend==1) and slope_spt_level_down1)
trendwarningup2=(uptrendextreme[2] and (close<close[1]) and (trend==1) and slope_spt_level_down1)
trendwarningup3=(uptrendextreme[3] and (close<close[1]) and (trend==1) and slope_spt_level_down1)
trendwarningup4=(uptrendextreme[4] and (close<close[1]) and (trend==1) and slope_spt_level_down1)
trendwarningup5=(uptrendextreme[5] and (close<close[1]) and (trend==1) and slope_spt_level_down1)
trendwarningdown1=(downtrendextreme[1] and (close>close[1]) and (trend==-1) and slope_spt_level_up1)
trendwarningdown2=(downtrendextreme[2] and (close>close[1]) and (trend==-1) and slope_spt_level_up1)
trendwarningdown3=(downtrendextreme[3] and (close>close[1]) and (trend==-1) and slope_spt_level_up1)
trendwarningdown4=(downtrendextreme[4] and (close>close[1]) and (trend==-1) and slope_spt_level_up1)
trendwarningdown5=(downtrendextreme[5] and (close>close[1]) and (trend==-1) and slope_spt_level_up1)
spt_color = slope_spt_level_down1?red:slope_spt_level_up1?lime:slope_spt_level_down2?red:slope_spt_level_up2?lime:slope_spt_level_down3?red:slope_spt_level_up3?lime:slope_spt_level_down4?red:slope_spt_level_up4?lime:slope_spt_level_down5?red:slope_spt_level_up5?lime:slope_spt_level_down6?red:slope_spt_level_up6?lime:slope_spt_level_down7?red:slope_spt_level_up7?lime:slope_spt_level_down8?red:slope_spt_level_up8?lime:slope_spt_level_down9?red:slope_spt_level_up9?lime:slope_spt_level_down10?red:slope_spt_level_up10?lime:white
midcolor = trend==1? green: maroon
histcolor = uah?(trendextreme?purple:trend==1? green: maroon):(trendextreme?purple:na)
extremebarcolor = trendextreme?purple:na
plot(spt, color= histcolor , style=histogram, linewidth=1,title="Histogram", editable=true)
p1=plot(spt, color= spt_color , style=line, linewidth=2,title="SuperTrend", editable=true)
p2=plot(0, style=line, linewidth=2, color=midcolor,title="Midline", editable=true)
plot(urc?spt:na,style=circles,linewidth=3, color=trendwarningcolor, editable=true)
Thanks for sharing you ideas, j1O9SB!
But I can not add it to my chart, show pic like this

chenchen3529 chenchen3529
It show: Error, can not compile script"super trend oscillator v2"
Nice work!
j1O9SB PRO coondawg71
Thanks! Keep me posted should you have ideas/setups with this indicator.
If anyone knows how to code S&R levels that draw automatically onto the oscillator and would be willing to help doing so, please pm me. Thanks in advance.
EN English
EN English (UK)
EN English (IN)
DE Deutsch
FR Français
ES Español
IT Italiano
PL Polski
TR Türkçe
RU Русский
PT Português
ID Bahasa Indonesia
MS Bahasa Melayu
TH ภาษาไทย
VI Tiếng Việt
JA 日本語
KO 한국어
ZH 简体中文
ZH 繁體中文
Home Stock Screener Forex Signal Finder Cryptocurrency Signal Finder Economic Calendar How It Works Chart Features House Rules Moderators Website & Broker Solutions Widgets Stock Charting Library Feature Request Blog & News FAQ Help & Wiki Twitter
Profile Profile Settings Account and Billing My Support Tickets Contact Support Ideas Published Followers Following Private Messages Chat Sign Out