SuperTrend Yahoo Finance Type for ThinkorSwim

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

I want to try this Supertrend Indicator, to scalping tool, as soon as trend changes, and post its number, then automatically buy and sell for you with OCO bracket on it. Is there a way to do it.
Unfortunately, I don't think you can reference the code from, or include it in, a Conditional Order... You can try, but don't get your hopes up... You won't get errors most of the time from Conditional Orders that TOS can't handle, just orders that immediately Buy and then immediately Sell after saving the OCO order... Been there, done that...!!! o_O
 
@BenTen or whoever. Can you please help with this scanner? I've watched the video and tried all different settings, but I can never yield a result. Is there something with the code? Any help would be much appreciated.
 
@BenTen or whoever. Can you please help with this scanner? I've watched the video and tried all different settings, but I can never yield a result. Is there something with the code? Any help would be much appreciated.

if the scanner is installed properly (copy and paste the script into the thinkscript editor within the scanner tab > add study> custom> delete the study that is loaded on this screen and then > select thinkscript editor > paste the script > adjust the Altmult and natr to your preference in the script > select the time frame for the scanner that coincides with your altmult and natr> save it . then narrrow down what stocks you want to scan for ie. Last price, (study) volume average, then hit scan, make sure you change the number of results you want to 200 or less or many times it wont load, try 100, that is plenty of results. Hit scan. If it doesn't load anything the first time, hit scan again, then again. Usually by the 2nd or 3rd time it will fetch your results.
 
If anyone is interested, I modified this a little to show a label for the selected timeframe. You can add more than one to show different timeframes in the same chart. Make sure the timeframes you select are higher than the chart setting.

Python:
# SuperTrend Yahoo Finance Replica - Modified from Modius SuperTrend - MTF Labels Version
# Modified Modius ver. by RConner7
# Modified by barbaros for multi time frame label

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

input agg1 = AggregationPeriod.HOUR;
input AtrMult = 1.00;
input nATR = 6;
input AvgType = AverageType.HULL;

def ATR = MovingAverage (AvgType, TrueRange(high(period = agg1), close(period = agg1), low(period = agg1)), nATR);
def UP_Band_Basic = HL2(period = agg1) + (AtrMult * ATR);

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

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

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

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

AddLabel(yes, if agg1== aggregationPeriod.MONTH then "M"
    else
    if agg1== aggregationPeriod.WEEK then "W"
    else
    if agg1== aggregationPeriod.FOUR_DAYS then "4D"
    else
    if agg1== aggregationPeriod.THREE_DAYS then "3D"
    else
    if agg1== aggregationPeriod.TWO_DAYS then "2D"
    else
    if agg1== aggregationPeriod.DAY then "D"
    else
    if agg1== aggregationPeriod.FOUR_HOURS then "4H"
    else
    if agg1== aggregationPeriod.TWO_HOURS then "2H"
    else
    if agg1== aggregationPeriod.HOUR then "1H"
    else
    if agg1== aggregationPeriod.THIRTY_MIN then "30m"
    else
    if agg1== aggregationPeriod.TWENTY_MIN then "20m"
    else
    if agg1== aggregationPeriod.FIFTEEN_MIN then "15m"
    else
    if agg1== aggregationPeriod.TEN_MIN then "10m"
    else
    if agg1== aggregationPeriod.FIVE_MIN then "5m"
    else
    if agg1== aggregationPeriod.FOUR_MIN then "4m"
    else
    if agg1== aggregationPeriod.THREE_MIN then "3m"
    else
    if agg1== aggregationPeriod.TWO_MIN then "2m"
    else
    if agg1== aggregationPeriod.MIN then "1m"
    else "",
         if close(period = agg1) < ST
                then Color.RED
               else if close(period = agg1) > ST
                    then Color.GREEN
                     else Color.DARK_GRAY);

# End Code SuperTrend Yahoo Finance Replica - MTF Labels Version
Hello barbros, I know this has been a while since you were on this thread, but I just wanted to ask if this repaints after the close of the bar?
 
not really trending...its just market sentiment...So it can be trending...or in a channel...I tried using this technique on SPY and it does seem to be very text book...MACD set to 15 min will help filter out the fake moves that may not end up going anywhere on lower timeframes...Try implementing all of the criteria by using multiple scanners all in ONE scan and trade stocks other that it generates other than

I don’t recall since I stopped using this, but since it has multi time frame component, probably repaints.
I know the original Super mtf lower study did have those issues, but not really on Afterhours. I was able to pair this study with you and chucks BB study as a strat and had again very positive results, would you be able to check it out and see if this is realistic?
 
I don’t recall since I stopped using this, but since it has multi time frame component, probably repaints.
Also from what I read in other forums the real problem with MTF repainting was due to using the second aggregation in the form of script() code as stated by Mobius and then posted on the forum by @tomsk (not that I know what that means) as I was going through your code, I did not spot any of that, so I'm not sure if this is also a positive sign.
 
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.

Suepr-Trend1.jpg


Painted bars:
Suepr-Trend2.jpg


Yahoo Finance version
Suepr-Trend-YF.jpg


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
Bro, I have been using this, Quite helpful. I use the 3min chart to trade. Have yo backtested what nATR works best esp for scalping under $20 stocks. I have tried 1 and 3
 
I use this scan for my chart on thinkorswim but when I try to copy and paste it in the scanner it says... Addlabel not allowed in this content. I want the scan to be just like the chart. Any help on getting the below code to work on the scanner would be much much appreciated.

Code:
# SuperTrend Yahoo Finance Replica - Modified from Modius SuperTrend
# Modified Modius ver. by RConner7
# Modified by Barbaros to replicate look from TradingView version
# Modified by Barbaros to add EMA cross for bubbles and alerts
# Modified by Barbaros to update bar color painting
# v3.3

input AtrMult = 1.00;
input nATR = 6;
input AvgType = AverageType.HULL;
input PaintBars = yes;
input ShowBubbles = yes;
input ShowLabels = yes;
input UseEmaCross = yes;
input EMA1 = 10;
input EMA2 = 20;

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;

def EMA1Val = MovAvgExponential(close, EMA1);
def EMA2Val = MovAvgExponential(close, EMA2);
def EMADirection = if EMA1Val > EMA2Val then 1 else if EMA1Val < EMA2Val then -1 else 0;

plot Long = if close > ST then ST else Double.NaN;
Long.AssignValueColor(Color.GREEN);
Long.SetLineWeight(2);

plot Short = if close < ST then ST else Double.NaN;
Short.AssignValueColor(Color.RED);
Short.SetLineWeight(3);

def LongTrigger = isNaN(Long[1]) and !isNaN(Long);
def ShortTrigger = isNaN(Short[1]) and !isNaN(Short);

plot LongDot = if LongTrigger then ST else Double.NaN;
LongDot.SetPaintingStrategy(PaintingStrategy.POINTS);
LongDot.AssignValueColor(Color.GREEN);
LongDot.SetLineWeight(4);

plot ShortDot = if ShortTrigger then ST else Double.NaN;
ShortDot.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot.AssignValueColor(Color.RED);
ShortDot.SetLineWeight(4);

def LongConfirm = (UseEmaCross and close > ST and EMADirection == 1) or (!UseEmaCross and LongTrigger);
def ShortConfirm = (UseEmaCross and close < ST and EMADirection == -1) or (!UseEmaCross and ShortTrigger);

def LongAlert = LongConfirm and LongConfirm[1] != LongConfirm;
def ShortAlert = ShortConfirm and ShortConfirm[1] != ShortConfirm;

AddLabel(ShowLabels, "ST: " + (if close > ST then "Bullish" else if close < ST then "Bearish" else "Neutral"),
                              if close > ST then Color.GREEN else if close < ST then Color.RED else Color.GRAY);
AddLabel(ShowLabels and UseEmaCross, "EMA: " + (if EMADirection == 1 then "Bullish" else if EMADirection == -1 then "Bearish" else "Neutral"),
                              if EMADirection == 1 then Color.GREEN else if EMADirection == -1 then Color.RED else Color.GRAY);

AddChartBubble(ShowBubbles and LongAlert, ST, "BUY", Color.GREEN, no);
AddChartBubble(ShowBubbles and ShortAlert, ST, "SELL", Color.RED, yes);

AssignPriceColor(if PaintBars and close < ST and (!UseEmaCross or EMADirection == -1) then Color.RED
                 else if PaintBars and close > ST and (!UseEmaCross or EMADirection == 1) then Color.GREEN
                 else if PaintBars then Color.GRAY
                 else Color.CURRENT);

Alert(LongAlert, "Long", Alert.BAR, Sound.Ding);
Alert(ShortAlert, "Short", Alert.BAR, Sound.Ding);

# End Code SuperTrend Yahoo Finance Replica

I have it saved for my charts and it works great. I also seem to have it saved as an indicator because when I search for it while trying to build a scan, it's there but when I load it, the values are all blank. As value, is true, is false, crosses over, crosses under etc. Do I need to select one or more of those or is it already in the code for a scan? The scanner isn't finding anything but sometimes when it's late, it doesn't work. Thank you
 
Last edited by a moderator:
I use this scan for my chart on thinkorswim but when I try to copy and paste it in the scanner it says... Addlabel not allowed in this content. I want the scan to be just like the chart. Any help on getting the below code to work on the scanner would be much much appreciated.

Code:
# SuperTrend Yahoo Finance Replica - Modified from Modius SuperTrend
# Modified Modius ver. by RConner7
# Modified by Barbaros to replicate look from TradingView version
# Modified by Barbaros to add EMA cross for bubbles and alerts
# Modified by Barbaros to update bar color painting
# v3.3

input AtrMult = 1.00;
input nATR = 6;
input AvgType = AverageType.HULL;
input PaintBars = yes;
input ShowBubbles = yes;
input ShowLabels = yes;
input UseEmaCross = yes;
input EMA1 = 10;
input EMA2 = 20;

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;

def EMA1Val = MovAvgExponential(close, EMA1);
def EMA2Val = MovAvgExponential(close, EMA2);
def EMADirection = if EMA1Val > EMA2Val then 1 else if EMA1Val < EMA2Val then -1 else 0;

plot Long = if close > ST then ST else Double.NaN;
Long.AssignValueColor(Color.GREEN);
Long.SetLineWeight(2);

plot Short = if close < ST then ST else Double.NaN;
Short.AssignValueColor(Color.RED);
Short.SetLineWeight(3);

def LongTrigger = isNaN(Long[1]) and !isNaN(Long);
def ShortTrigger = isNaN(Short[1]) and !isNaN(Short);

plot LongDot = if LongTrigger then ST else Double.NaN;
LongDot.SetPaintingStrategy(PaintingStrategy.POINTS);
LongDot.AssignValueColor(Color.GREEN);
LongDot.SetLineWeight(4);

plot ShortDot = if ShortTrigger then ST else Double.NaN;
ShortDot.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot.AssignValueColor(Color.RED);
ShortDot.SetLineWeight(4);

def LongConfirm = (UseEmaCross and close > ST and EMADirection == 1) or (!UseEmaCross and LongTrigger);
def ShortConfirm = (UseEmaCross and close < ST and EMADirection == -1) or (!UseEmaCross and ShortTrigger);

def LongAlert = LongConfirm and LongConfirm[1] != LongConfirm;
def ShortAlert = ShortConfirm and ShortConfirm[1] != ShortConfirm;

AddLabel(ShowLabels, "ST: " + (if close > ST then "Bullish" else if close < ST then "Bearish" else "Neutral"),
                              if close > ST then Color.GREEN else if close < ST then Color.RED else Color.GRAY);
AddLabel(ShowLabels and UseEmaCross, "EMA: " + (if EMADirection == 1 then "Bullish" else if EMADirection == -1 then "Bearish" else "Neutral"),
                              if EMADirection == 1 then Color.GREEN else if EMADirection == -1 then Color.RED else Color.GRAY);

AddChartBubble(ShowBubbles and LongAlert, ST, "BUY", Color.GREEN, no);
AddChartBubble(ShowBubbles and ShortAlert, ST, "SELL", Color.RED, yes);

AssignPriceColor(if PaintBars and close < ST and (!UseEmaCross or EMADirection == -1) then Color.RED
                 else if PaintBars and close > ST and (!UseEmaCross or EMADirection == 1) then Color.GREEN
                 else if PaintBars then Color.GRAY
                 else Color.CURRENT);

Alert(LongAlert, "Long", Alert.BAR, Sound.Ding);
Alert(ShortAlert, "Short", Alert.BAR, Sound.Ding);

# End Code SuperTrend Yahoo Finance Replica

I have it saved for my charts and it works great. I also seem to have it saved as an indicator because when I search for it while trying to build a scan, it's there but when I load it, the values are all blank. As value, is true, is false, crosses over, crosses under etc. Do I need to select one or more of those or is it already in the code for a scan? The scanner isn't finding anything but sometimes when it's late, it doesn't work. Thank you
https://usethinkscript.com/threads/supertrend-yahoo-finance-type-for-thinkorswim.1998/#post-20153
 
hey everyone
Creating a "SuperTrend Yahoo Finance Type" for ThinkorSwim involves adapting Yahoo Finance's SuperTrend indicator for use in ThinkorSwim's platform. This customization could enhance trend analysis and trading strategies for ThinkorSwim users, providing a unique and potentially valuable tool for technical analysis within the platform.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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