SuperTrend Yahoo Finance Type for ThinkorSwim

R

RConner7

Member
I've created the popular SuperTrend indicator that works and displays very similar to how the Yahoo Finance SuperTrend works. This was modified from the version that Modius originally created.



Painted bars:


Yahoo Finance version


Code:
# SuperTrend Yahoo Finance Replica - Modified from Modius SuperTrend
# Modified Modius ver. by RConner7

# Works similar to how Yahoo Finance Supertrend works and displays. Holds supertrend value until cross.

input AtrMult = 1.00;
input nATR = 6;
input AvgType = AverageType.HULL;
input PaintBars = yes;

def ATR = ATR("length" = nATR, "average type" = AvgType);
def UP_Band_Basic = HL2 + (AtrMult * ATR);

def LW_Band_Basic = HL2 + (-AtrMult * ATR);

def UP_Band = if ((UP_Band_Basic < UP_Band[1]) or (close[1] > UP_Band[1])) then UP_Band_Basic else UP_Band[1];

def LW_Band = if ((LW_Band_Basic > LW_Band[1]) or (close[1] < LW_Band[1])) then LW_Band_Basic else LW_Band[1];

def ST = if ((ST[1] == UP_Band[1]) and (close < UP_Band)) then UP_Band
else if ((ST[1] == UP_Band[1]) and (close > Up_Band)) then LW_Band
else if ((ST[1] == LW_Band[1]) and (close > LW_Band)) then LW_Band
else if ((ST[1] == LW_Band) and (close < LW_Band)) then UP_Band
else LW_Band;

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);

plot ArrowDown = Supertrend crosses above close;
ArrowDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
ArrowDown.SetDefaultColor(Color.RED);
ArrowDown.SetLineWeight(3);

plot ArrowUp = Supertrend crosses below close;
ArrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
ArrowUp.SetDefaultColor(Color.GREEN);
ArrowUp.SetLineWeight(3);

# End Code SuperTrend Yahoo Finance Replica
 
Last edited:
K

kshires4

Member
Can someone help ? Looking to make a scanner in TOS for the Yahoo Supertrend code.
 
Last edited by a moderator:
H

HighBredCloud

Active member
VIP
This SuperTrend works good...a scanner would be nice.
 
R

RConner7

Member
@HighBredCloud - sorry for the delay on this. I think the below code should work as a scanner for this SuperTrend version. Please let me know if this seems to work out for you.

The current settings should give you any results where the supertrend crossed (up or down) within the past 3 candles.

If you were looking to scan specifically for up or down, i can adjust if needed.

Code:
# SuperTrend Yahoo Finance Replica - Modified from Modius SuperTrend
# Modified Modius ver. by RConner7
# SCANNER #
# Works similar to how Yahoo Finance Supertrend works and displays. Holds supertrend value until cross.

input AtrMult = 1.00;
input nATR = 6;
input AvgType = AverageType.HULL;
input PaintBars = yes;

def ATR = ATR("length" = nATR, "average type" = AvgType);
def UP_Band_Basic = HL2 + (AtrMult * ATR);

def LW_Band_Basic = HL2 + (-AtrMult * ATR);

def UP_Band = if ((UP_Band_Basic < UP_Band[1]) or (close[1] > UP_Band[1])) then UP_Band_Basic else UP_Band[1];

def LW_Band = if ((LW_Band_Basic > LW_Band[1]) or (close[1] < LW_Band[1])) then LW_Band_Basic else LW_Band[1];

def ST = if ((ST[1] == UP_Band[1]) and (close < UP_Band)) then UP_Band
else if ((ST[1] == UP_Band[1]) and (close > Up_Band)) then LW_Band
else if ((ST[1] == LW_Band[1]) and (close > LW_Band)) then LW_Band
else if ((ST[1] == LW_Band) and (close < LW_Band)) then UP_Band
else LW_Band;

plot ST_Cross = if (ST crosses above close) or (ST crosses below close) within 3 bars then 1 else 0;
 
H

HighBredCloud

Active member
VIP
@RConner7 Would you also be able to include the UP/DOWN scanner as well? Sometimes depending on the timeframe you scan on not everything appears right away...and sometimes it appears with delay. I run multiple scanners on my dedicated monitor just because of that reason. Besides I am sure others on here might find uses for either one. Some like myself...ONLY scan for stocks trending in a given direction depending on the market on that day.

Also not to hijack your other thread with your strategy...figure I will post this in here not to interfere.

I've been using this SuperTrend and been doing some tests on a possible strategy. I was able to replicate an MTF version of this SuperTrend from a CSA that I am testing to use on lower timeframes. I am using a 15 min chart for the main trend. I set the ATR MULT to .7 from default 1.0...I kept the NATR default at 6...I then use the same settings on 5 min chart...Lastly I use a 1 min timeframe set to a 2 min aggregation to avoid the whipsaw generated by the 1 min...I left the default settings on the 1 min time frame of 1.0 ATR MULT and 6 NATR.

The idea is to trade in the direction of the 15 min chart...IF the 15 min chart is GREEN...I go long...IF RED...I short. I use the 5 min for pullbacks and both 5 min and 15 min need to match up for any trade to happen. Lastly I go in on the 1 min timeframe that is set to 2 min aggregation.

To help with the possible exit I also use TMO with 3 different aggregation...15 min 5 min and 3 min on a 1 min timeframe. This further helps me narrow down the entry point and exit point.

I also use Trend Magic line ONLY as an additional confirmation...ANYTHING above it is confirming a long entry and below a short entry.

Overall I am surprised at how well this SuperTrend is working. Very responsive on even a 15 min timeframe...something most other SuperTrends lack. Its really hard to sit through the pullbacks just by using the SuperTrend alone for a day trader. We're not so much used to that as swing traders. This SuperTrend is by far the best one I've seen in terms of how responsive to price action it is.
 
C

Charlielee

New member
VIP
Very nice! I'm going to do some more testing but this so far this looks really good. Thanks for sharing
 
R

RConner7

Member
@HighBredCloud - i separated the BULL / BEAR scanner for you. The 2 below should give you the results if within past 3 bars.

DOWN:
Code:
# SuperTrend Yahoo Finance Replica - Modified from Modius SuperTrend
# Modified Modius ver. by RConner7
# BEAR SCANNER #
# Works similar to how Yahoo Finance Supertrend works and displays. Holds supertrend value until cross.

input AtrMult = 1.00;
input nATR = 6;
input AvgType = AverageType.HULL;
input PaintBars = yes;

def ATR = ATR("length" = nATR, "average type" = AvgType);
def UP_Band_Basic = HL2 + (AtrMult * ATR);

def LW_Band_Basic = HL2 + (-AtrMult * ATR);

def UP_Band = if ((UP_Band_Basic < UP_Band[1]) or (close[1] > UP_Band[1])) then UP_Band_Basic else UP_Band[1];

def LW_Band = if ((LW_Band_Basic > LW_Band[1]) or (close[1] < LW_Band[1])) then LW_Band_Basic else LW_Band[1];

def ST = if ((ST[1] == UP_Band[1]) and (close < UP_Band)) then UP_Band
else if ((ST[1] == UP_Band[1]) and (close > Up_Band)) then LW_Band
else if ((ST[1] == LW_Band[1]) and (close > LW_Band)) then LW_Band
else if ((ST[1] == LW_Band) and (close < LW_Band)) then UP_Band
else LW_Band;

plot ST_Cross = if (ST crosses above close) within 3 bars then 1 else 0;

UP:
Code:
# SuperTrend Yahoo Finance Replica - Modified from Modius SuperTrend
# Modified Modius ver. by RConner7
# BULL SCANNER #
# Works similar to how Yahoo Finance Supertrend works and displays. Holds supertrend value until cross.

input AtrMult = 1.00;
input nATR = 6;
input AvgType = AverageType.HULL;
input PaintBars = yes;

def ATR = ATR("length" = nATR, "average type" = AvgType);
def UP_Band_Basic = HL2 + (AtrMult * ATR);

def LW_Band_Basic = HL2 + (-AtrMult * ATR);

def UP_Band = if ((UP_Band_Basic < UP_Band[1]) or (close[1] > UP_Band[1])) then UP_Band_Basic else UP_Band[1];

def LW_Band = if ((LW_Band_Basic > LW_Band[1]) or (close[1] < LW_Band[1])) then LW_Band_Basic else LW_Band[1];

def ST = if ((ST[1] == UP_Band[1]) and (close < UP_Band)) then UP_Band
else if ((ST[1] == UP_Band[1]) and (close > Up_Band)) then LW_Band
else if ((ST[1] == LW_Band[1]) and (close > LW_Band)) then LW_Band
else if ((ST[1] == LW_Band) and (close < LW_Band)) then UP_Band
else LW_Band;

plot ST_Cross = if (ST crosses below close) within 3 bars then 1 else 0;
 
H

HighBredCloud

Active member
VIP
@RConner7 Thank You for the scanners...will use all 3 of them this week to see what pulls the bests results. Can I pick your brain a bit about this SuperTrend a bit? I made an MTF version of this SuperTrend based on a CSA study that I am currently testing. I am trying to find the sweet spot setting for this SuperTrend on a 1 min timeframe but with a 5 min time aggregation. My current setting on the 5 min chart is .07 ATR MULT and I left the NATR default 6 setting.

As you know...using a multi time frame of 5 min on 1 min chart you are prone to have the candles repaint in this case 5 candles back on the 1 min timeframe while the 5 min candle is still in OPEN condition. Even AFTER the 5 min candle closes the 1 min will paint 5 candles or however many candles back as your aggregation...This is not the point as that is expected just stating the obvious for people who may not know this.

I have also made a lower study version of this SuperTrend using "POINTS" to reflect the color of the candles. I wanted to use the lower study in conjunction with the upper MTF SuperTrend to serve as an entry or exit indication. With this in mind what is your recommendation of using possibly a higher ATR MULT than the 1.0 default setting on a 1 min chart? Also should I bother changing NATR form 6 to something else? I am trying to see if there is a value running this SuperTrend in MTF format on lower timeframes along with a lower study set to the current timeframe to see if there is possibly a quicker exit opportunity than on the main chart...in this case the 5 min.

It is rather scary how accurate this SuperTrend is...Yesterday I was using On Demand and I was looking at my other indicators such as True Momentum Oscillator...my friend who was helping me test this was drawing his trend lines all over the chart as he usually does when live trading...to find that IF ONLY the SuperTrend was used the best results would have been obtained on lower timeframes such as 5 min or less...The test was on 1 min chart with a 3 min aggregation FYI...seemed to work really well.

On the flip side though...high timeframes such as 15m + are also responsive BUT as with any SuperTrends they do tend to lag a bit when it comes to the candle color change vs the trend...as expected. I've had really good luck testing RSI crossover with the 5 SMA as well Mobius Price Range Color study found below. The combination of RSI cross over with Price Range Color and Stochastics FULL seemed to work really well...Anyway you can look at incorporating any of those studies I mentioned above to this SuperTrend to be even more responsive on a higher timeframe without compromising the trend? Would be nice to identify pullbacks on higher timeframes quicker other than by utilizing multi timeframe as I mentioned above.

Below is the Price Range Color by Mobius I referred to above...its very similar to the RSI crossing the 5 SMA...
Code:
# Price Range Color
# Mobius
# Smooths price over a range of bars eliminating noise

input range = 4;

def h = highest(high, range);
def l = lowest(low, range);
def c = close;
def Data = if ((c - l) / (h - l)) > .5
            then low - tickSize()
            else high + TickSize();
AssignPriceColor(if data < low then color.green else color.red);
 
R

Rama9

New member
@RConner7: Modified Super Trend is awesome especially with the arrows. Is it possible to borrow a higher time frame "permission" arrow and stick it
into the lower "trading" time frame so we don't have to refer 2 charts? Thanks
 
R

RConner7

Member
@RConner7: Modified Super Trend is awesome especially with the arrows. Is it possible to borrow a higher time frame "permission" arrow and stick it
into the lower "trading" time frame so we don't have to refer 2 charts? Thanks
Hmm... possible. So you would want to see cross over arrows from say a 5min chart on a 1min chart?
 

Top