MichaelSF
New member
I was playing around with Mobius's original SuperTrend script recently -
https://usethinkscript.com/threads/supertrend-indicator-by-mobius-for-thinkorswim.7/
- and combining it with other popular indicators and found a couple of interesting results after a lot of tweaking and testing. Below is the first Indicator I tested this with; the MACD. It plots the MACD Diff Line (The Histogram Part) and uses that to calculate a SuperTrend "of" that line in order to smooth its movement. I'm sure that I'm not the first person to have done this, but I couldn't find a thread on here relating to it so here's my shot at it.
Above is an example of this indicator being used on SPY in combination with the normal RSI. I find it works best on extreme overbought/oversold conditions, which is why the RSI is a good pair with it.
Unsurprisingly, the next indicator I tried to convert to SuperTrend was the RSI. The thing with the RSI is that it tends to be very choppy, and SuperTrending it would just be a zig-zag mess of nothingness, which is pictured below. Still could be useful in some cases maybe, but too choppy to be reliable in my opinion.
The solution to this was creating a MovingAverage of the RSI, and then adding a SuperTrend calculated off of that line instead. Below is the result of this and the code for the script.
In the picture above its crosses were almost identical to the Original SuperTrend crosses, so I added another picture from a different day that shows it better below.
NOTE: I've found that when the Classic SuperTrend and AvgRSISuperTrend do line up it's actually a pretty good way of confirming a strong move, so if you choose to use this remember to look out for that.
A few other things:
Hopefully someone can find some use out of these. I've created a few strategies based on them and they ended up working pretty well.
Thank you to everyone that's apart of this community! Learned more than I could've imagined since finding this forum.
https://usethinkscript.com/threads/supertrend-indicator-by-mobius-for-thinkorswim.7/
- and combining it with other popular indicators and found a couple of interesting results after a lot of tweaking and testing. Below is the first Indicator I tested this with; the MACD. It plots the MACD Diff Line (The Histogram Part) and uses that to calculate a SuperTrend "of" that line in order to smooth its movement. I'm sure that I'm not the first person to have done this, but I couldn't find a thread on here relating to it so here's my shot at it.
Code:
#SuperTrendOfMACD
#MichaelSF 2/2020
#Original SuperTrend Code By Mobius
declare lower;
## MACD ##
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);
plot MACDdiff = Value - Avg;
MACDdiff.SetPaintingStrategy(PaintingStrategy.LINE);
plot ZeroLine = 0;
ZeroLine.setDefaultColor(Color.dark_GRAY);
## SUPERTREND ##
input AtrMult = 1.0;
input nATR = 18;
def ATR = MovingAverage(AverageType.HULL, TrueRange(MACDdiff, MACDdiff, MACDdiff), nATR);
def UP = MACDdiff + (AtrMult * ATR);
def DN = MACDdiff + (-AtrMult * ATR);
def ST = if MACDdiff < ST[1] then UP else DN;
plot SuperTrend = ST;
SuperTrend.setDefaultColor(Color.dark_GRAY);
## COLORS & PLOTS ##
MACDDiff.AssignValueColor(if ST < MACDdiff then color.green else if ST > MACDdiff then color.red else color.Gray);
plot UpSignal = if ST crosses below MACDdiff then MACDdiff else Double.NaN;
plot DownSignal = if ST crosses above MACDdiff then MACDdiff else Double.NaN;
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Above is an example of this indicator being used on SPY in combination with the normal RSI. I find it works best on extreme overbought/oversold conditions, which is why the RSI is a good pair with it.
Unsurprisingly, the next indicator I tried to convert to SuperTrend was the RSI. The thing with the RSI is that it tends to be very choppy, and SuperTrending it would just be a zig-zag mess of nothingness, which is pictured below. Still could be useful in some cases maybe, but too choppy to be reliable in my opinion.
The solution to this was creating a MovingAverage of the RSI, and then adding a SuperTrend calculated off of that line instead. Below is the result of this and the code for the script.
In the picture above its crosses were almost identical to the Original SuperTrend crosses, so I added another picture from a different day that shows it better below.
NOTE: I've found that when the Classic SuperTrend and AvgRSISuperTrend do line up it's actually a pretty good way of confirming a strong move, so if you choose to use this remember to look out for that.
Code:
#SuperTrendOfAvgRSI
#MichaelSF 2/2020
#Original SuperTrend Code By Mobius
declare lower;
## RSI ##
input AvgLength = 10;
input AvgType = AverageType.SIMPLE;
input price = close;
def NetChgAvg = MovingAverage(AverageType.WILDERS, price - price[1], 14);
def TotChgAvg = MovingAverage(AverageType.WILDERS, AbsValue(price - price[1]), 14);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
plot RSIAvg = MovingAverage(AvgType, RSI, Avglength);
RSIAvg.SetPaintingStrategy(PaintingStrategy.Line);
## SUPERTREND ##
input AtrMult = 1.0;
input nATR = 20;
def ATR = MovingAverage(AverageType.HULL, TrueRange(RSIAvg, RSIAvg, RSIAvg), nATR);
def UP = RSIAvg + (AtrMult * ATR);
def DN = RSIAvg + (-AtrMult * ATR);
def ST = if RSIAvg < ST[1] then UP else DN;
plot SuperTrend = ST;
SuperTrend.setDefaultColor(Color.dark_GRAY);
## COLORS ##
RSIAvg.AssignValueColor(if SuperTrend < RSIAvg then color.green else if SuperTrend > RSIAvg then color.red else color.Gray);
plot OverSold = 30;
OverSold.setDefaultColor(Color.dark_GRAY);
plot OverBought = 70;
OverBought.setDefaultColor(Color.dark_GRAY);
plot UpSignal = if ST crosses below RSIAvg then RSIAvg else Double.NaN;
plot DownSignal = if ST crosses above RSIAvg then RSIAvg else Double.NaN;
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
A few other things:
- The colors on the chart are from the Mobius SuperTrend, not the indicators
- The Settings on these indicators are what I found works best, but play around with them yourself to see if something works better for you.
Hopefully someone can find some use out of these. I've created a few strategies based on them and they ended up working pretty well.
Thank you to everyone that's apart of this community! Learned more than I could've imagined since finding this forum.
Last edited: