SuperTrend TradingView Look-A-Like For ThinkOrSwim

DeepThinker

New member
@barbaros
Thanks again for this indicator. Excellent tool!
I was hoping you can find time and help with the scanners that are currently working if embedded as scripts.
That presents few limitations when trying to
a) combine scanner criteria with other scanners criteria
b) set "#of bars" window to capture expected results
 

barbaros

Administrator
Staff member
@barbaros
Thanks again for this indicator. Excellent tool!
I was hoping you can find time and help with the scanners that are currently working if embedded as scripts.
That presents few limitations when trying to
a) combine scanner criteria with other scanners criteria
b) set "#of bars" window to capture expected results
No problem.

Combining this scanner with another scanner criteria shouldn’t be a problem. This criteria will be one line and the others will have their own line in the scanner. Can you expand which use case is limiting?

If you want the add the bar look back, you can add within x bars to the end of the condition line.
 

DeepThinker

New member
No problem.

Combining this scanner with another scanner criteria shouldn’t be a problem. This criteria will be one line and the others will have their own line in the scanner. Can you expand which use case is limiting?

If you want the add the bar look back, you can add within x bars to the end of the condition line.
Thanks for responding so quickly.

The "embedded script" presents limitation when aiming to create complex "OR" and "AND" conditions, while referencing several custom studies.
Which is the best way to achieve by using Thinkscript vs Scanner ("ALL" | "ANY" | "NONE") groups.

As a workaround (still not a solution) I agree, using "full" and modified code with added "within x bars" may help, but this would create further maintenance concerns.
Many Thanks
 

barbaros

Administrator
Staff member
Thanks for responding so quickly.

The "embedded script" presents limitation when aiming to create complex "OR" and "AND" conditions, while referencing several custom studies.
Which is the best way to achieve by using Thinkscript vs Scanner ("ALL" | "ANY" | "NONE") groups.

As a workaround (still not a solution) I agree, using "full" and modified code with added "within x bars" may help, but this would create further maintenance concerns.
Many Thanks
Unfortunately, issue is with ToS itself and not with the script. You can use the original long or short version of the script and save them as studies. You can then use the studies in your scanners. I found that the recent version of ToS had difficulty producing results when they were saved as studies, however, using them as custom code in the scanner editor worked fine.
 

DeepThinker

New member
Unfortunately, issue is with ToS itself and not with the script. You can use the original long or short version of the script and save them as studies. You can then use the studies in your scanners. I found that the recent version of ToS had difficulty producing results when they were saved as studies, however, using them as custom code in the scanner editor worked fine.
Thanks for your honest answer. Perhaps we should write a petition, aiming to persuade TradingView team implementing scanners functionality :)
 

sam4cok

Member
some more setting. ie. ST cloud, ST Line on/off. Signal Arrow/Bubble, GetAgg.
# 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
# Modified by Barbaros to add MTF
# Modified by SAM4COK to add GetAgg, ST Cloud, Arrow and Alert/Cloud/ST Line.
# v3.45

input AtrMult = 2.00;
input nATR = 10;
input AvgType = AverageType.HULL;
input PaintBars = yes;
input Alert = no;
input ShowBubbles = yes;
input ShowSignal = yes;
input ShowLabels = yes;
input CloudST = yes;
input LinesST = yes;
input UseEmaCross = yes;
input EMA1 = 10;
input EMA2 = 20;
input Signal = {default Arrow, Bubbles, Non};

def Agg = GetAggregationPeriod();

def closePrice = close(period = Agg);
def highPrice = high(period = Agg);
def lowPrice = low(period = Agg);
def HL2Price = hl2(period = Agg);

def ATR = MovingAverage(AvgType, TrueRange(highPrice, closePrice, lowPrice), nATR);
def UP_Band_Basic = HL2Price + (AtrMult * ATR);
def LW_Band_Basic = HL2Price + (-AtrMult * ATR);
def UP_Band = if ((UP_Band_Basic < UP_Band[1]) or (closePrice[1] > UP_Band[1])) then UP_Band_Basic else UP_Band[1];
def LW_Band = if ((LW_Band_Basic > LW_Band[1]) or (closePrice[1] < LW_Band[1])) then LW_Band_Basic else LW_Band[1];

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

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

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

plot Short = if LinesST and closePrice < 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 closePrice > ST and EMADirection == 1) or (!UseEmaCross and LongTrigger);
def ShortConfirm = (UseEmaCross and closePrice < 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 closePrice > ST then "Bullish" else if closePrice < ST then "Bearish" else "Neutral"),
if closePrice > ST then Color.GREEN else if closePrice < 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);

def LongSignal;
def ShortSignal;
def shape;

switch (Signal) {
case Arrow:
Shape = 1;
LongSignal = if LongAlert then Low else 0;
ShortSignal = if ShortAlert then High else 0;
case Bubbles:
Shape = 2;
LongSignal = if LongAlert then Low else 0;
ShortSignal = if ShortAlert then High else 0;
case Non:
Shape = 0;
LongSignal = 0;
ShortSignal = 0;
}

Plot LongArrow = if LongSignal and shape == 1 then low else double.nan;;

LongArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
LongArrow.AssignValueColor(Color.GREEN);
LongArrow.SetLineWeight(4);

Plot ShortArrow = if ShortSignal and shape == 1 then high else double.nan;
ShortArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ShortArrow.AssignValueColor(Color.RED);
ShortArrow.SetLineWeight(4);

Def LongBubble = if LongSignal and shape == 2 then LongSignal else double.nan;
Def ShortBubble = if ShortSignal and shape == 2then ShortSignal else double.nan;

AddChartBubble(LongSignal and shape==2, low, "BUY", Color.GREEN, no);
AddChartBubble (ShortSignal and shape==2, high, "SELL", Color.RED, yes);

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

def Cloud = if CloudST and ST then ST else Double.NaN;

DefineGlobalColor("Bullish", Color.DARK_GREEN);
DefineGlobalColor("Bearish", Color.DARK_RED);
AddCloud(Cloud, hl2, GlobalColor("Bearish"), GlobalColor("Bullish"));

def LongAlertON = Alert and LongAlert;
def ShortAlertON = Alert and ShortAlert;
Alert(LongAlertON, "Long", Alert.BAR, Sound.Ding);
Alert(ShortAlertON, "Short", Alert.BAR, Sound.Ding);

# End Code SuperTrend Yahoo Finance Replica
 

Erik1970

New member
Is there a Watchlist for this? Thanks

Code:
# Modified by Barbaros to replicate look from TradingView version
# v3.0

input AtrMult = 1.0;
input nATR = 6;
input AvgType = AverageType.HULL;
input PaintBars = no;
input ShowBubbles = no;

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

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

AssignPriceColor(if PaintBars and close < ST
               then Color.RED
               else if PaintBars and close > ST
                    then Color.GREEN
                    else Color.CURRENT);

#Alert(LongTrigger, "Long", Alert.BAR, Sound.Ding);
#Alert(ShortTrigger, "Short", Alert.BAR, Sound.Ding);

# End Code SuperTrend Yahoo Finance Replica
 
Last edited by a moderator:

barbaros

Administrator
Staff member
Is there a Watchlist for this? Thanks

Code:
# Modified by Barbaros to replicate look from TradingView version
# v3.0

input AtrMult = 1.0;
input nATR = 6;
input AvgType = AverageType.HULL;
input PaintBars = no;
input ShowBubbles = no;

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

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

AssignPriceColor(if PaintBars and close < ST
               then Color.RED
               else if PaintBars and close > ST
                    then Color.GREEN
                    else Color.CURRENT);

#Alert(LongTrigger, "Long", Alert.BAR, Sound.Ding);
#Alert(ShortTrigger, "Short", Alert.BAR, Sound.Ding);

# End Code SuperTrend Yahoo Finance Replica
Here is a mod for watchlist column.

Code:
# Modified by Barbaros to replicate look from TradingView version
# v3.0 - Watchlist Column

def AtrMult = 1.0;
def nATR = 6;
def AvgType = AverageType.HULL;

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 Long = if close > ST then ST else Double.NaN;
def Short = if close < ST then ST else Double.NaN;
def LongTrigger = isNaN(Long[1]) and !isNaN(Long);
def ShortTrigger = isNaN(Short[1]) and !isNaN(Short);

AddLabel(yes,
                if LongTrigger then "Buy"
                else if ShortTrigger then "Sell"
                else if Long then "Long"
                else if Short then "Short"
                else "Unknown",
                if close < ST then Color.RED
               else if close > ST then Color.GREEN
               else Color.CURRENT);

# End Code SuperTrend Yahoo Finance Replica
 

barbaros

Administrator
Staff member
Its say's there is an error in the code -

Incompatible parameter: Avgtype at 8:11
Try changing this line
def ATR = ATR("length" = nATR, "average type" = AvgType);

To this
def ATR = ATR("length" = nATR, "average type" = AverageType.HULL);

And, remove this line
def AvgType = AverageType.HULL;
 
Top