SuperTrend TradingView Look-A-Like

Hapme

New member
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
 

barbaros

Well-known member
VIP
barbos i tried and still is printing signals to buy below 9 and 21 ema any hope for this to work? thank you

It is checking if the EMAs are crossed and not where the close price ends up. It is easy to add though.
 

freedom Traders

New member
VIP
CAN SOMEONE PLEASE MAKE A SCAN FOR THIS PLEASE....JUST FOR THE BUY OR SELL SIGNAL OR ALERT PLEASE
 
Last edited by a moderator:

barbaros

Well-known member
VIP
CAN SOMEONE PLEASE MAKE A SCAN FOR THIS PLEASE....JUST FOR THE BUY OR SELL SIGNAL OR ALERT PLEASE

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
 

McManaman

New member
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
 

barbaros

Well-known member
VIP
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?
 

McManaman

New member
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
 

barbaros

Well-known member
VIP
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
 

quijanoj44

Member
VIP
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:

barbaros

Well-known member
VIP
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
 

ChristianS

New member
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
 

barbaros

Well-known member
VIP
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.
 

Similar threads

Top