SuperTrend TradingView Look-A-Like For ThinkOrSwim

I use a plain chart with the 10 and 20 EMA’s to enter trades. That’s all I use now succeasfuly, but what I am trying to accomplish is to incorporate the supertrend’s signals as confirmation of direction, which I think it does a pretty good job of doing. So the idea is to have supertrend print signals only when they align with my 10 and 20 EMA’s. I will then decide if I want to take the trade as I presently do. I don’t need to do testing because I do mot blindly enter into trades and I do not follow “good back testing” results, as none of that works. So maybe you misunderstood me as someone looking for the holy grail. Not so. My system works, I just want visualizations to make faster decisions. So can we add the script and label and can I show you how I do it?

Hey @adefenza , did it work for you the code , cause when i add my 9 and 21 , still is giving me signals when is below 9 and 21 , i was hoping the code is to give signals when is above 9 em
 
Can someone please make a scan for this. Just for the buy and sell signal. Thank you.

Here is the scanner. Comment in and out the following 2 lines in the direction of the scan you are interested in.

Code:
plot LongAlert = LongConfirm and LongConfirm[1] != LongConfirm;
# plot ShortAlert = ShortConfirm and ShortConfirm[1] != ShortConfirm;

Scanner:

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 - Scanner

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;

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

def LongDot = if LongTrigger then ST else Double.NaN;
def ShortDot = if ShortTrigger then ST else Double.NaN;

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

plot LongAlert = LongConfirm and LongConfirm[1] != LongConfirm;
# plot ShortAlert = ShortConfirm and ShortConfirm[1] != ShortConfirm;

# End Code SuperTrend Yahoo Finance Replica
 
Last edited by a moderator:
Here is the scanner. Comment in and out the following 2 lines in the direction of the scan you are interested in.

Code:
plot LongAlert = LongConfirm and LongConfirm[1] != LongConfirm;
# plot ShortAlert = ShortConfirm and ShortConfirm[1] != ShortConfirm;

Scanner:

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 - Scanner

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;

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

def LongDot = if LongTrigger then ST else Double.NaN;
def ShortDot = if ShortTrigger then ST else Double.NaN;

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

plot LongAlert = LongConfirm and LongConfirm[1] != LongConfirm;
# plot ShortAlert = ShortConfirm and ShortConfirm[1] != ShortConfirm;

# End Code SuperTrend Yahoo Finance Replica
Hi @barbaros
I am one of you and @Chuck fans and thank you for the great effort.
Could you please give us an instruction to set up the scanner?
I tried to set it by choosing "is true" within 1 or 2 bars but it does not return any index.

Thanks for your time
 
Hi @barbaros
I am one of you and @Chuck fans and thank you for the great effort.
Could you please give us an instruction to set up the scanner?
I tried to set it by choosing "is true" within 1 or 2 bars but it does not return any index.

Thanks for your time

Hello. Thank you for your kind words.

This script doesn’t support being saved into a study to be used in a scanner. You can paste it in filter source to use it. However, it is easy to support the study filtering. Would you like to use it that way?
 
Hello. Thank you for your kind words.

This script doesn’t support being saved into a study to be used in a scanner. You can paste it in filter source to use it. However, it is easy to support the study filtering. Would you like to use it that way?
Hi @barbaros , Thanks for your response.
I am not that much familiar with the filter source module. If it is possible instruct me to use it in study filtering.
Thank you very much
 
Hi @barbaros , Thanks for your response.
I am not that much familiar with the filter source module. If it is possible instruct me to use it in study filtering.
Thank you very much
Here is how to use this. Save the script below to a study, and then you can select either the LongAlert or ShortAlert from the filter settings as plot option and select "is true" for the value.

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 - Scanner

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;

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

def LongDot = if LongTrigger then ST else Double.NaN;
def ShortDot = if ShortTrigger then ST else Double.NaN;

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

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

# End Code SuperTrend Yahoo Finance Replica
 
Is it possible to create an MTF version for this indicator? I would like to see in a 2 min chart, the 5 min SuperTrend.
 
Last edited by a moderator:
Is it possible to create an MTF version for this indicator? I would like to see in a 2 min chart, the 5 min SuperTrend.

I tried here:

It still has some bugs. I am not a coder, would appreciate any help. Thanks
Here is the MTF version

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
# Modified by Barbaros to add MTF
# v3.4

input Agg = AggregationPeriod.DAY;
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 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 closePrice > ST then ST else Double.NaN;
Long.AssignValueColor(Color.GREEN);
Long.SetLineWeight(2);

plot Short = if 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, if Agg < AggregationPeriod.HOUR then Round(Agg / AggregationPeriod.MIN, 0) + "m"
                     else if Agg < AggregationPeriod.DAY then Round(Agg / AggregationPeriod.HOUR, 0) + "H"
                     else if Agg < AggregationPeriod.WEEK then Round(Agg / AggregationPeriod.DAY, 0) + "D"
                     else if Agg < AggregationPeriod.MONTH then Round(Agg / AggregationPeriod.WEEK, 0) + "W"
                     else if Agg < AggregationPeriod.YEAR then Round(Agg / AggregationPeriod.MONTH, 0) + "M"
                     else "1Y"
                    , Color.GRAY);
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);

AddChartBubble(ShowBubbles and LongAlert, ST, "BUY", Color.GREEN, no);
AddChartBubble(ShowBubbles and ShortAlert, ST, "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);

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

# End Code SuperTrend Yahoo Finance Replica
 
I modified a version of SuperTrend that is already available for Thinkorswim to imitate the style.

kyuKOnh.png


You can adjust the look from the options. Labels are turned off by default.
4GZNCcv.png


It also has alerts for trend change.
DnqfdSv.png


Python:
# SuperTrend Yahoo Finance Replica - Modified from Modius SuperTrend
# Modified Modius ver. by RConner7
# Modified by Barbaros to replicate look from TradingView version
# v3.0

input AtrMult = 1.00;
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
Thank you very much, I am also trying to add a strategy but for some reason I don't understand the alert comes out of a candle after the purchase or sale, sorry my English I from argentina......., i appreciate the help since I'm still a very novice



Code:
# SuperTrend Yahoo Finance Replica - Modified from Modius SuperTrend
# Modified Modius ver. by RConner7
# Modified by Barbaros to replicate look from TradingView version
# v3.0

input AtrMult = 1.00;
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.cyan);
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.lime, no);
AddChartBubble(ShowBubbles and ShortTrigger, ST, "Sell", Color.cyan, 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);

AddOrder(OrderType.BUY_AUTO, longtrigger  , tickcolor = Color.YELLOW, arrowcolor = Color.BLACK, name = "Buy", tradeSize = 100);
AddOrder(OrderType.SELL_TO_CLOSE, shortTrigger , tickcolor = Color.PINK, arrowcolor = Color.RED, name = "sell", tradeSize = 100);

# End Code SuperTrend Yahoo Finance Replica
 
Thank you very much, I am also trying to add a strategy but for some reason I don't understand the alert comes out of a candle after the purchase or sale, sorry my English I from argentina......., i appreciate the help since I'm still a very novice



Code:
# SuperTrend Yahoo Finance Replica - Modified from Modius SuperTrend
# Modified Modius ver. by RConner7
# Modified by Barbaros to replicate look from TradingView version
# v3.0

input AtrMult = 1.00;
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.cyan);
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.lime, no);
AddChartBubble(ShowBubbles and ShortTrigger, ST, "Sell", Color.cyan, 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);

AddOrder(OrderType.BUY_AUTO, longtrigger  , tickcolor = Color.YELLOW, arrowcolor = Color.BLACK, name = "Buy", tradeSize = 100);
AddOrder(OrderType.SELL_TO_CLOSE, shortTrigger , tickcolor = Color.PINK, arrowcolor = Color.RED, name = "sell", tradeSize = 100);

# End Code SuperTrend Yahoo Finance Replica
You need to close the order before a sell signal is fired. For that, you need another instrument to determine a profit target or a stop loss is reached. One example is, you can use SuperTrend and measure a stop loss to your entry, and calculate a 1 to 1 RR.
 
Thank you very much, I am also trying to add a strategy but for some reason I don't understand the alert comes out of a candle after the purchase or sale, sorry my English I from argentina......., i appreciate the help since I'm still a very novice



Code:
# SuperTrend Yahoo Finance Replica - Modified from Modius SuperTrend
# Modified Modius ver. by RConner7
# Modified by Barbaros to replicate look from TradingView version
# v3.0

input AtrMult = 1.00;
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.cyan);
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.lime, no);
AddChartBubble(ShowBubbles and ShortTrigger, ST, "Sell", Color.cyan, 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);

AddOrder(OrderType.BUY_AUTO, longtrigger  , tickcolor = Color.YELLOW, arrowcolor = Color.BLACK, name = "Buy", tradeSize = 100);
AddOrder(OrderType.SELL_TO_CLOSE, shortTrigger , tickcolor = Color.PINK, arrowcolor = Color.RED, name = "sell", tradeSize = 100);

# End Code SuperTrend Yahoo Finance Replica


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;

Shouldndt it be LW_band[1] instead of LW_Band for the last else if condition?
 
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;

Shouldndt it be LW_band[1] instead of LW_Band for the last else if condition?
Probably correct.
 
Hello @barbaros .. I have a question. Is it possible to add the value to the label that reads ST: Bullish when green so it can read ST: Bullish 2200. The reason why I ask is because I would like to add two other different times and would like to see the value of the supertrend line without switching timeframes in the chart. Thank you.
 
Hello @barbaros .. I have a question. Is it possible to add the value to the label that reads ST: Bullish when green so it can read ST: Bullish 2200. The reason why I ask is because I would like to add two other different times and would like to see the value of the supertrend line without switching timeframes in the chart. Thank you.
Can you explain the label a bit further? What is 2200? Is it price, time, custom text?
 
Barbaros! Very slick redesign! Well done! I use Mobius’ Supertrend as the centerpiece of my intraday trades. I like the look of your script better. Are the action signals generated Using the same criteria as Mobius’?

Thank you for sharing!
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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