Is it possible to plot a Triple Supertrend as a red dot/ green dot ribbon as a lower indicator?

@barbaros - any chance for a scanner for when the first bar triggers from green to red and vice versa. Meaning the top level bar. The best would be a scanner that could scan for any of the 3 supertrend signal changes, i.e any of the 3 levels. Thanks in advance if you can help. Hopefully I described this well enough
@barbaros does this sound like something doable?
 

barbaros

Administrator
Staff member
Alright team, here is another update. I added an overall trend line for the lower indicator. You can set how many ST dots you want to match in the direction and when it finds consensus, it paints the top line in that direction. Dots above the horizontal gray line is the overall trend dots. You can also enable the bar color painting for the overall trend direction.

vGJjKlI.png


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 Fluideng to make the triple SuplerTrend into one indicator. Also removed EMA2 and Bar color.
# Modified by Barbaros to show as a lower indicator, removed EMA and others
# Modified by Barbaros to add trend consensus and bar painting
# v4.0

declare lower;

input Limit = 3;
input BarColor = yes;

### SuperTrend #1
input AtrMult = 3.00;
input nATR = 12;
input 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;

### SuperTrend #2
input AtrMult2 = 2.00;
input nATR2 = 11;

def ATR2 = ATR("length" = nATR2, "average type" = AvgType);
def UP_Band_Basic2 = HL2 + (AtrMult2 * ATR);
def LW_Band_Basic2 = HL2 + (-AtrMult2 * ATR);
def UP_Band2 = if ((UP_Band_Basic2 < UP_Band2[1]) or (close[1] > UP_Band2[1])) then UP_Band_Basic2 else UP_Band2[1];
def LW_Band2 = if ((LW_Band_Basic2 > LW_Band2[1]) or (close[1] < LW_Band2[1])) then LW_Band_Basic2 else LW_Band2[1];

def ST2 = if ((ST2[1] == UP_Band2[1]) and (close < UP_Band2)) then UP_Band2
else if ((ST2[1] == UP_Band2[1]) and (close > Up_Band2)) then LW_Band2
else if ((ST2[1] == LW_Band2[1]) and (close > LW_Band2)) then LW_Band2
else if ((ST2[1] == LW_Band2) and (close < LW_Band2)) then UP_Band2
else LW_Band2;

### SuperTrend #3
input AtrMult3 = 1.00;
input nATR3 = 10;

def ATR3 = ATR("length" = nATR3, "average type" = AvgType);
def UP_Band_Basic3 = HL2 + (AtrMult3 * ATR);
def LW_Band_Basic3 = HL2 + (-AtrMult3 * ATR);
def UP_Band3 = if ((UP_Band_Basic3 < UP_Band3[1]) or (close[1] > UP_Band3[1])) then UP_Band_Basic3 else UP_Band3[1];
def LW_Band3 = if ((LW_Band_Basic3 > LW_Band3[1]) or (close[1] < LW_Band3[1])) then LW_Band_Basic3 else LW_Band3[1];

def ST3 = if ((ST3[1] == UP_Band3[1]) and (close < UP_Band3)) then UP_Band3
else if ((ST3[1] == UP_Band3[1]) and (close > Up_Band3)) then LW_Band3
else if ((ST3[1] == LW_Band3[1]) and (close > LW_Band3)) then LW_Band3
else if ((ST3[1] == LW_Band3) and (close < LW_Band3)) then UP_Band3
else LW_Band3;

### ST consensus

def totalCount = (if close > ST then 1 else if close < ST then -1 else 0) +
                 (if close > ST2 then 1 else if close < ST2 then -1 else 0) +
                 (if close > ST3 then 1 else if close < ST3 then -1 else 0);
def TrendDirection = if totalCount > 0 and totalCount >= Limit then 1 else if totalCount < 0 and totalCount <= Limit then -1 else 0;

### Plots

plot Trend = if isNaN(close) then Double.NaN else 5;
Trend.SetPaintingStrategy(PaintingStrategy.POINTS);
Trend.SetLineWeight(3);
Trend.AssignValueColor(if TrendDirection == 1 then Color.GREEN else if TrendDirection == -1 then Color.RED else Color.GRAY);

plot Separator = if isNaN(close) then Double.NaN else 4;
Separator.SetDefaultColor(Color.GRAY);

plot SuperTrend1 = if isNaN(close) then Double.NaN else 1;
SuperTrend1.SetPaintingStrategy(PaintingStrategy.POINTS);
SuperTrend1.SetLineWeight(3);
SuperTrend1.AssignValueColor(if close > ST then Color.GREEN else if close < ST then Color.RED else Color.GRAY);

plot SuperTrend2 = if isNaN(close) then Double.NaN else 2;
SuperTrend2.SetPaintingStrategy(PaintingStrategy.POINTS);
SuperTrend2.SetLineWeight(3);
SuperTrend2.AssignValueColor(if close > ST2 then Color.GREEN else if close < ST2 then Color.RED else Color.GRAY);

plot SuperTrend3 = if isNaN(close) then Double.NaN else 3;
SuperTrend3.SetPaintingStrategy(PaintingStrategy.POINTS);
SuperTrend3.SetLineWeight(3);
SuperTrend3.AssignValueColor(if close > ST3 then Color.GREEN else if close < ST3 then Color.RED else Color.GRAY);

### Bar Color

AssignPriceColor(if BarColor then if TrendDirection == 1 then Color.GREEN else if TrendDirection == -1 then Color.RED else Color.GRAY else Color.CURRENT);

# End Code SuperTrend Yahoo Finance Replica

For the scanner. I moved the outputs into plots so you can use the script below for scanning, including the overall trend direction. You need to compare the plots numerically to 1, -1, or 0.
1 = bullish
-1 = bearish
0 = neutral

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 Fluideng to make the triple SuplerTrend into one indicator. Also removed EMA2 and Bar color.
# Modified by Barbaros to show as a lower indicator, removed EMA and others
# Modified by Barbaros to add trend consensus and bar painting
# v4.0

declare lower;

input Limit = 3;
input BarColor = yes;

### SuperTrend #1
input AtrMult = 3.00;
input nATR = 12;
input 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;

### SuperTrend #2
input AtrMult2 = 2.00;
input nATR2 = 11;

def ATR2 = ATR("length" = nATR2, "average type" = AvgType);
def UP_Band_Basic2 = HL2 + (AtrMult2 * ATR);
def LW_Band_Basic2 = HL2 + (-AtrMult2 * ATR);
def UP_Band2 = if ((UP_Band_Basic2 < UP_Band2[1]) or (close[1] > UP_Band2[1])) then UP_Band_Basic2 else UP_Band2[1];
def LW_Band2 = if ((LW_Band_Basic2 > LW_Band2[1]) or (close[1] < LW_Band2[1])) then LW_Band_Basic2 else LW_Band2[1];

def ST2 = if ((ST2[1] == UP_Band2[1]) and (close < UP_Band2)) then UP_Band2
else if ((ST2[1] == UP_Band2[1]) and (close > Up_Band2)) then LW_Band2
else if ((ST2[1] == LW_Band2[1]) and (close > LW_Band2)) then LW_Band2
else if ((ST2[1] == LW_Band2) and (close < LW_Band2)) then UP_Band2
else LW_Band2;

### SuperTrend #3
input AtrMult3 = 1.00;
input nATR3 = 10;

def ATR3 = ATR("length" = nATR3, "average type" = AvgType);
def UP_Band_Basic3 = HL2 + (AtrMult3 * ATR);
def LW_Band_Basic3 = HL2 + (-AtrMult3 * ATR);
def UP_Band3 = if ((UP_Band_Basic3 < UP_Band3[1]) or (close[1] > UP_Band3[1])) then UP_Band_Basic3 else UP_Band3[1];
def LW_Band3 = if ((LW_Band_Basic3 > LW_Band3[1]) or (close[1] < LW_Band3[1])) then LW_Band_Basic3 else LW_Band3[1];

def ST3 = if ((ST3[1] == UP_Band3[1]) and (close < UP_Band3)) then UP_Band3
else if ((ST3[1] == UP_Band3[1]) and (close > Up_Band3)) then LW_Band3
else if ((ST3[1] == LW_Band3[1]) and (close > LW_Band3)) then LW_Band3
else if ((ST3[1] == LW_Band3) and (close < LW_Band3)) then UP_Band3
else LW_Band3;

### ST consensus

def totalCount = (if close > ST then 1 else if close < ST then -1 else 0) +
                 (if close > ST2 then 1 else if close < ST2 then -1 else 0) +
                 (if close > ST3 then 1 else if close < ST3 then -1 else 0);

### Scanner Plots

plot TrendDirection = if totalCount > 0 and totalCount >= Limit then 1 else if totalCount < 0 and totalCount <= Limit then -1 else 0;
plot SuperTrend1 = if close > ST then 1 else if close < ST then -1 else 0;
plot SuperTrend2 = if close > ST2 then 1 else if close < ST2 then -1 else 0;
plot SuperTrend3 = if close > ST3 then 1 else if close < ST3 then -1 else 0;


# End Code SuperTrend Yahoo Finance Replica
 
Not sure I get the scanner. What I wanted to scan for is the ability to pick any of the 3 Supertrend lines and scan for a red or green dot. I guess just a simple scan for the one supertrend I am interested in is really all that is needed. So just scan for the shortest term supertrend since that is the trigger.

More info might be useful here. The concept is like a car shifting gears. You buy/sell when the fastest Supertrend changes colors i.e. to green. You go long on the first green dot on the fastest supertrend. When the middle supertrend turns green, that then becomes the level you are trading from- Second gear. You stay long as long as the middle is green, regardless what the fastest supertrend is doing. This is is now the controller of your position until you shift to 3rd gear meaning the 3rd level slowest supertrend turns green. Then it controls and manages the trade regardless what the 1st or 2nd level colors are doing. Hopefully that is clear as mud.
 

barbaros

Administrator
Staff member
Yep, that's what i was thinking when I suggested the upper indicator, but if you like, we can put vertical lines in the lower indicator to show the "gear" number :)
 

barbaros

Administrator
Staff member
@barbaros @hockeydoug
Very Interesting "shift" concept.
Many thanks for your contribution.

My 2-c, I would prefer updates to the lower indicator.
a) can be placed and managed in the separate ( lower ) frame.
Upper frame is usually overloaded with multiple scripts.
b) also, scanner and watch list column.
Agreed. We'll keep it as a lower indicator. I'll post the update soon.
 

barbaros

Administrator
Staff member
Team, here is the first pass of the gears update. I didn't spend too much time on this, please test.

Gear numbers are the labels above all the dots. Vertical lines were getting too busy, so I opted for bubbles. Adjust the size of the lower indicator row to show it all.

qMOa5tG.png


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 Fluideng to make the triple SuplerTrend into one indicator. Also removed EMA2 and Bar color.
# Modified by Barbaros to show as a lower indicator, removed EMA and others
# Modified by Barbaros to add trend consensus and bar painting
# modified by Barbaros to add gear numbers
# v4.1

declare lower;

input Limit = 3;
input BarColor = yes;

### SuperTrend #1
input AtrMult = 3.00;
input nATR = 12;
input 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;

### SuperTrend #2
input AtrMult2 = 2.00;
input nATR2 = 11;

def ATR2 = ATR("length" = nATR2, "average type" = AvgType);
def UP_Band_Basic2 = HL2 + (AtrMult2 * ATR);
def LW_Band_Basic2 = HL2 + (-AtrMult2 * ATR);
def UP_Band2 = if ((UP_Band_Basic2 < UP_Band2[1]) or (close[1] > UP_Band2[1])) then UP_Band_Basic2 else UP_Band2[1];
def LW_Band2 = if ((LW_Band_Basic2 > LW_Band2[1]) or (close[1] < LW_Band2[1])) then LW_Band_Basic2 else LW_Band2[1];

def ST2 = if ((ST2[1] == UP_Band2[1]) and (close < UP_Band2)) then UP_Band2
else if ((ST2[1] == UP_Band2[1]) and (close > Up_Band2)) then LW_Band2
else if ((ST2[1] == LW_Band2[1]) and (close > LW_Band2)) then LW_Band2
else if ((ST2[1] == LW_Band2) and (close < LW_Band2)) then UP_Band2
else LW_Band2;

### SuperTrend #3
input AtrMult3 = 1.00;
input nATR3 = 10;

def ATR3 = ATR("length" = nATR3, "average type" = AvgType);
def UP_Band_Basic3 = HL2 + (AtrMult3 * ATR);
def LW_Band_Basic3 = HL2 + (-AtrMult3 * ATR);
def UP_Band3 = if ((UP_Band_Basic3 < UP_Band3[1]) or (close[1] > UP_Band3[1])) then UP_Band_Basic3 else UP_Band3[1];
def LW_Band3 = if ((LW_Band_Basic3 > LW_Band3[1]) or (close[1] < LW_Band3[1])) then LW_Band_Basic3 else LW_Band3[1];

def ST3 = if ((ST3[1] == UP_Band3[1]) and (close < UP_Band3)) then UP_Band3
else if ((ST3[1] == UP_Band3[1]) and (close > Up_Band3)) then LW_Band3
else if ((ST3[1] == LW_Band3[1]) and (close > LW_Band3)) then LW_Band3
else if ((ST3[1] == LW_Band3) and (close < LW_Band3)) then UP_Band3
else LW_Band3;

### ST consensus

def ST1Val = (if close > ST then 1 else if close < ST then -1 else 0);
def ST2Val = (if close > ST2 then 1 else if close < ST2 then -1 else 0);
def ST3Val = (if close > ST3 then 1 else if close < ST3 then -1 else 0);

def totalShorts = (if ST1Val < 0 then -1 else 0) +
                  (if ST2Val < 0 then -1 else 0) +
                  (if ST3Val < 0 then -1 else 0);
def totalLongs = (if ST1Val > 0 then 1 else 0) +
                 (if ST2Val > 0 then 1 else 0) +
                 (if ST3Val > 0 then 1 else 0);

def TrendDirection = if totalLongs > 0 and totalLongs >= Limit then 1 else if totalShorts < 0 and totalShorts <= -Limit then -1 else 0;

### Gears

def DirectionFilter = if totalLongs == 3 then 1 else if totalShorts == -3 then -1 else DirectionFilter[1];

def LongGear1_ = totalShorts crosses above -3;
def LongGear2_ = totalShorts crosses above -2;
def LongGear3_ = totalShorts crosses above -1;

def LongGear1 = DirectionFilter == -1 and LongGear1_ and !LongGear2_ and !LongGear3_;
def LongGear2 = DirectionFilter == -1 and LongGear2_ and !LongGear3_;
def LongGear3 = DirectionFilter == 1 and LongGear3_;

def ShortGear1_ = totalLongs crosses below 3;
def ShortGear2_ = totalLongs crosses below 2;
def ShortGear3_ = totalLongs crosses below 1;

def ShortGear1 = DirectionFilter == 1 and ShortGear1_ and !ShortGear2_ and !ShortGear3_;
def ShortGear2 = DirectionFilter == 1 and ShortGear2_ and !ShortGear3_;
def ShortGear3 = DirectionFilter == -1 and ShortGear3_;

### Plots

plot SeparatorTop = if isNaN(close) then Double.NaN else 7;
SeparatorTop.SetDefaultColor(Color.GRAY);

plot Trend = if isNaN(close) then Double.NaN else 5;
Trend.SetPaintingStrategy(PaintingStrategy.POINTS);
Trend.SetLineWeight(3);
Trend.AssignValueColor(if TrendDirection == 1 then Color.GREEN else if TrendDirection == -1 then Color.RED else Color.GRAY);

plot SeparatorBottom = if isNaN(close) then Double.NaN else 4;
SeparatorBottom.SetDefaultColor(Color.GRAY);

plot SuperTrend1 = if isNaN(close) then Double.NaN else 1;
SuperTrend1.SetPaintingStrategy(PaintingStrategy.POINTS);
SuperTrend1.SetLineWeight(3);
SuperTrend1.AssignValueColor(if close > ST then Color.GREEN else if close < ST then Color.RED else Color.GRAY);

plot SuperTrend2 = if isNaN(close) then Double.NaN else 2;
SuperTrend2.SetPaintingStrategy(PaintingStrategy.POINTS);
SuperTrend2.SetLineWeight(3);
SuperTrend2.AssignValueColor(if close > ST2 then Color.GREEN else if close < ST2 then Color.RED else Color.GRAY);

plot SuperTrend3 = if isNaN(close) then Double.NaN else 3;
SuperTrend3.SetPaintingStrategy(PaintingStrategy.POINTS);
SuperTrend3.SetLineWeight(3);
SuperTrend3.AssignValueColor(if close > ST3 then Color.GREEN else if close < ST3 then Color.RED else Color.GRAY);

AddChartBubble(LongGear1, 5, "1", Color.YELLOW);
AddChartBubble(LongGear2, 5, "2", Color.GREEN);
AddChartBubble(LongGear3, 5, "3", Color.LIGHT_GREEN);

AddChartBubble(ShortGear1, 5, "1", Color.DARK_RED);
AddChartBubble(ShortGear2, 5, "2", Color.RED);
AddChartBubble(ShortGear3, 5, "3", Color.LIGHT_RED);

### Bar Color

AssignPriceColor(if BarColor then if TrendDirection == 1 then Color.GREEN else if TrendDirection == -1 then Color.RED else Color.GRAY else Color.CURRENT);

# End Code SuperTrend Yahoo Finance Replica
 
Last edited:

barbaros

Administrator
Staff member
Bug fix.

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 Fluideng to make the triple SuplerTrend into one indicator. Also removed EMA2 and Bar color.
# Modified by Barbaros to show as a lower indicator, removed EMA and others
# Modified by Barbaros to add trend consensus and bar painting
# modified by Barbaros to add gear numbers
# modified by Barbaros to bug fixes
# v4.2

declare lower;

input Limit = 3;
input BarColor = yes;

### SuperTrend #1
input AtrMult = 3.00;
input nATR = 12;
input 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;

### SuperTrend #2
input AtrMult2 = 2.00;
input nATR2 = 11;

def ATR2 = ATR("length" = nATR2, "average type" = AvgType);
def UP_Band_Basic2 = HL2 + (AtrMult2 * ATR);
def LW_Band_Basic2 = HL2 + (-AtrMult2 * ATR);
def UP_Band2 = if ((UP_Band_Basic2 < UP_Band2[1]) or (close[1] > UP_Band2[1])) then UP_Band_Basic2 else UP_Band2[1];
def LW_Band2 = if ((LW_Band_Basic2 > LW_Band2[1]) or (close[1] < LW_Band2[1])) then LW_Band_Basic2 else LW_Band2[1];

def ST2 = if ((ST2[1] == UP_Band2[1]) and (close < UP_Band2)) then UP_Band2
else if ((ST2[1] == UP_Band2[1]) and (close > Up_Band2)) then LW_Band2
else if ((ST2[1] == LW_Band2[1]) and (close > LW_Band2)) then LW_Band2
else if ((ST2[1] == LW_Band2) and (close < LW_Band2)) then UP_Band2
else LW_Band2;

### SuperTrend #3
input AtrMult3 = 1.00;
input nATR3 = 10;

def ATR3 = ATR("length" = nATR3, "average type" = AvgType);
def UP_Band_Basic3 = HL2 + (AtrMult3 * ATR);
def LW_Band_Basic3 = HL2 + (-AtrMult3 * ATR);
def UP_Band3 = if ((UP_Band_Basic3 < UP_Band3[1]) or (close[1] > UP_Band3[1])) then UP_Band_Basic3 else UP_Band3[1];
def LW_Band3 = if ((LW_Band_Basic3 > LW_Band3[1]) or (close[1] < LW_Band3[1])) then LW_Band_Basic3 else LW_Band3[1];

def ST3 = if ((ST3[1] == UP_Band3[1]) and (close < UP_Band3)) then UP_Band3
else if ((ST3[1] == UP_Band3[1]) and (close > Up_Band3)) then LW_Band3
else if ((ST3[1] == LW_Band3[1]) and (close > LW_Band3)) then LW_Band3
else if ((ST3[1] == LW_Band3) and (close < LW_Band3)) then UP_Band3
else LW_Band3;

### ST consensus

def ST1Val = (if close > ST then 1 else if close < ST then -1 else 0);
def ST2Val = (if close > ST2 then 1 else if close < ST2 then -1 else 0);
def ST3Val = (if close > ST3 then 1 else if close < ST3 then -1 else 0);

def totalShorts = (if ST1Val < 0 then -1 else 0) +
                  (if ST2Val < 0 then -1 else 0) +
                  (if ST3Val < 0 then -1 else 0);
def totalLongs = (if ST1Val > 0 then 1 else 0) +
                 (if ST2Val > 0 then 1 else 0) +
                 (if ST3Val > 0 then 1 else 0);

def TrendDirection = if totalLongs > 0 and totalLongs >= Limit then 1 else if totalShorts < 0 and totalShorts <= -Limit then -1 else 0;

### Gears

def DirectionFilter = if totalLongs == 3 then 1 else if totalShorts == -3 then -1 else DirectionFilter[1];

def LongGear1_ = totalShorts crosses above -3;
def LongGear2_ = totalShorts crosses above -2;
def LongGear3_ = totalShorts crosses above -1;

def LongGear1 = DirectionFilter == -1 and LongGear1_ and !LongGear2_ and !LongGear3_;
def LongGear2 = DirectionFilter == -1 and LongGear2_ and !LongGear3_;
def LongGear3 = DirectionFilter[1] == -1 and LongGear3_;

def ShortGear1_ = totalLongs crosses below 3;
def ShortGear2_ = totalLongs crosses below 2;
def ShortGear3_ = totalLongs crosses below 1;

def ShortGear1 = DirectionFilter == 1 and ShortGear1_ and !ShortGear2_ and !ShortGear3_;
def ShortGear2 = DirectionFilter == 1 and ShortGear2_ and !ShortGear3_;
def ShortGear3 = DirectionFilter[1] == 1 and ShortGear3_;

def GearNumber = if LongGear1 then 1
                 else if LongGear2 then 2
                 else if LongGear3 then 3
                 else if ShortGear1 then -1
                 else if ShortGear2 then -2
                 else if ShortGear3 then -3
                 else GearNumber[1];

### Plots

plot SeparatorTop = if isNaN(close) then Double.NaN else 7;
SeparatorTop.SetDefaultColor(Color.GRAY);

plot Trend = if isNaN(close) then Double.NaN else 5;
Trend.SetPaintingStrategy(PaintingStrategy.POINTS);
Trend.SetLineWeight(3);
Trend.AssignValueColor(if TrendDirection == 1 then Color.GREEN else if TrendDirection == -1 then Color.RED else Color.GRAY);

plot SeparatorBottom = if isNaN(close) then Double.NaN else 4;
SeparatorBottom.SetDefaultColor(Color.GRAY);

plot SuperTrend1 = if isNaN(close) then Double.NaN else 1;
SuperTrend1.SetPaintingStrategy(PaintingStrategy.POINTS);
SuperTrend1.SetLineWeight(3);
SuperTrend1.AssignValueColor(if close > ST then Color.GREEN else if close < ST then Color.RED else Color.GRAY);

plot SuperTrend2 = if isNaN(close) then Double.NaN else 2;
SuperTrend2.SetPaintingStrategy(PaintingStrategy.POINTS);
SuperTrend2.SetLineWeight(3);
SuperTrend2.AssignValueColor(if close > ST2 then Color.GREEN else if close < ST2 then Color.RED else Color.GRAY);

plot SuperTrend3 = if isNaN(close) then Double.NaN else 3;
SuperTrend3.SetPaintingStrategy(PaintingStrategy.POINTS);
SuperTrend3.SetLineWeight(3);
SuperTrend3.AssignValueColor(if close > ST3 then Color.GREEN else if close < ST3 then Color.RED else Color.GRAY);

AddChartBubble(LongGear1, 5, "1", Color.YELLOW);
AddChartBubble(LongGear2, 5, "2", Color.GREEN);
AddChartBubble(LongGear3, 5, "3", Color.LIGHT_GREEN);

AddChartBubble(ShortGear1, 5, "1", Color.DARK_RED);
AddChartBubble(ShortGear2, 5, "2", Color.RED);
AddChartBubble(ShortGear3, 5, "3", Color.LIGHT_RED);

### Bar Color

AssignPriceColor(if BarColor then if TrendDirection == 1 then Color.GREEN else if TrendDirection == -1 then Color.RED else Color.GRAY else Color.CURRENT);

# End Code SuperTrend Yahoo Finance Replica
 

DeepThinker

New member
Bug fix.

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 Fluideng to make the triple SuplerTrend into one indicator. Also removed EMA2 and Bar color.
# Modified by Barbaros to show as a lower indicator, removed EMA and others
# Modified by Barbaros to add trend consensus and bar painting
# modified by Barbaros to add gear numbers
# modified by Barbaros to bug fixes
# v4.2

declare lower;

input Limit = 3;
input BarColor = yes;

### SuperTrend #1
input AtrMult = 3.00;
input nATR = 12;
input 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;

### SuperTrend #2
input AtrMult2 = 2.00;
input nATR2 = 11;

def ATR2 = ATR("length" = nATR2, "average type" = AvgType);
def UP_Band_Basic2 = HL2 + (AtrMult2 * ATR);
def LW_Band_Basic2 = HL2 + (-AtrMult2 * ATR);
def UP_Band2 = if ((UP_Band_Basic2 < UP_Band2[1]) or (close[1] > UP_Band2[1])) then UP_Band_Basic2 else UP_Band2[1];
def LW_Band2 = if ((LW_Band_Basic2 > LW_Band2[1]) or (close[1] < LW_Band2[1])) then LW_Band_Basic2 else LW_Band2[1];

def ST2 = if ((ST2[1] == UP_Band2[1]) and (close < UP_Band2)) then UP_Band2
else if ((ST2[1] == UP_Band2[1]) and (close > Up_Band2)) then LW_Band2
else if ((ST2[1] == LW_Band2[1]) and (close > LW_Band2)) then LW_Band2
else if ((ST2[1] == LW_Band2) and (close < LW_Band2)) then UP_Band2
else LW_Band2;

### SuperTrend #3
input AtrMult3 = 1.00;
input nATR3 = 10;

def ATR3 = ATR("length" = nATR3, "average type" = AvgType);
def UP_Band_Basic3 = HL2 + (AtrMult3 * ATR);
def LW_Band_Basic3 = HL2 + (-AtrMult3 * ATR);
def UP_Band3 = if ((UP_Band_Basic3 < UP_Band3[1]) or (close[1] > UP_Band3[1])) then UP_Band_Basic3 else UP_Band3[1];
def LW_Band3 = if ((LW_Band_Basic3 > LW_Band3[1]) or (close[1] < LW_Band3[1])) then LW_Band_Basic3 else LW_Band3[1];

def ST3 = if ((ST3[1] == UP_Band3[1]) and (close < UP_Band3)) then UP_Band3
else if ((ST3[1] == UP_Band3[1]) and (close > Up_Band3)) then LW_Band3
else if ((ST3[1] == LW_Band3[1]) and (close > LW_Band3)) then LW_Band3
else if ((ST3[1] == LW_Band3) and (close < LW_Band3)) then UP_Band3
else LW_Band3;

### ST consensus

def ST1Val = (if close > ST then 1 else if close < ST then -1 else 0);
def ST2Val = (if close > ST2 then 1 else if close < ST2 then -1 else 0);
def ST3Val = (if close > ST3 then 1 else if close < ST3 then -1 else 0);

def totalShorts = (if ST1Val < 0 then -1 else 0) +
                  (if ST2Val < 0 then -1 else 0) +
                  (if ST3Val < 0 then -1 else 0);
def totalLongs = (if ST1Val > 0 then 1 else 0) +
                 (if ST2Val > 0 then 1 else 0) +
                 (if ST3Val > 0 then 1 else 0);

def TrendDirection = if totalLongs > 0 and totalLongs >= Limit then 1 else if totalShorts < 0 and totalShorts <= -Limit then -1 else 0;

### Gears

def DirectionFilter = if totalLongs == 3 then 1 else if totalShorts == -3 then -1 else DirectionFilter[1];

def LongGear1_ = totalShorts crosses above -3;
def LongGear2_ = totalShorts crosses above -2;
def LongGear3_ = totalShorts crosses above -1;

def LongGear1 = DirectionFilter == -1 and LongGear1_ and !LongGear2_ and !LongGear3_;
def LongGear2 = DirectionFilter == -1 and LongGear2_ and !LongGear3_;
def LongGear3 = DirectionFilter[1] == -1 and LongGear3_;

def ShortGear1_ = totalLongs crosses below 3;
def ShortGear2_ = totalLongs crosses below 2;
def ShortGear3_ = totalLongs crosses below 1;

def ShortGear1 = DirectionFilter == 1 and ShortGear1_ and !ShortGear2_ and !ShortGear3_;
def ShortGear2 = DirectionFilter == 1 and ShortGear2_ and !ShortGear3_;
def ShortGear3 = DirectionFilter[1] == 1 and ShortGear3_;

def GearNumber = if LongGear1 then 1
                 else if LongGear2 then 2
                 else if LongGear3 then 3
                 else if ShortGear1 then -1
                 else if ShortGear2 then -2
                 else if ShortGear3 then -3
                 else GearNumber[1];

### Plots

plot SeparatorTop = if isNaN(close) then Double.NaN else 7;
SeparatorTop.SetDefaultColor(Color.GRAY);

plot Trend = if isNaN(close) then Double.NaN else 5;
Trend.SetPaintingStrategy(PaintingStrategy.POINTS);
Trend.SetLineWeight(3);
Trend.AssignValueColor(if TrendDirection == 1 then Color.GREEN else if TrendDirection == -1 then Color.RED else Color.GRAY);

plot SeparatorBottom = if isNaN(close) then Double.NaN else 4;
SeparatorBottom.SetDefaultColor(Color.GRAY);

plot SuperTrend1 = if isNaN(close) then Double.NaN else 1;
SuperTrend1.SetPaintingStrategy(PaintingStrategy.POINTS);
SuperTrend1.SetLineWeight(3);
SuperTrend1.AssignValueColor(if close > ST then Color.GREEN else if close < ST then Color.RED else Color.GRAY);

plot SuperTrend2 = if isNaN(close) then Double.NaN else 2;
SuperTrend2.SetPaintingStrategy(PaintingStrategy.POINTS);
SuperTrend2.SetLineWeight(3);
SuperTrend2.AssignValueColor(if close > ST2 then Color.GREEN else if close < ST2 then Color.RED else Color.GRAY);

plot SuperTrend3 = if isNaN(close) then Double.NaN else 3;
SuperTrend3.SetPaintingStrategy(PaintingStrategy.POINTS);
SuperTrend3.SetLineWeight(3);
SuperTrend3.AssignValueColor(if close > ST3 then Color.GREEN else if close < ST3 then Color.RED else Color.GRAY);

AddChartBubble(LongGear1, 5, "1", Color.YELLOW);
AddChartBubble(LongGear2, 5, "2", Color.GREEN);
AddChartBubble(LongGear3, 5, "3", Color.LIGHT_GREEN);

AddChartBubble(ShortGear1, 5, "1", Color.DARK_RED);
AddChartBubble(ShortGear2, 5, "2", Color.RED);
AddChartBubble(ShortGear3, 5, "3", Color.LIGHT_RED);

### Bar Color

AssignPriceColor(if BarColor then if TrendDirection == 1 then Color.GREEN else if TrendDirection == -1 then Color.RED else Color.GRAY else Color.CURRENT);

# End Code SuperTrend Yahoo Finance Replica

@barbaros As always, great work. Many thanks for sharing updates.

If it is not too much trouble adding the setting for turning on/off Chart Bubbles?
Sorry, this could be per my experience only, but due to the Screen vs Chart size the "bubbling" is too cluttering :)

Perhaps the usual BUY vs SELL arrows could be more helpful with making observation and further decisions
Also, Would this be possible, providing idea for the watchlist column - flags for tracking trend direction?
Thanks
 

barbaros

Administrator
Staff member
@barbaros As always, great work. Many thanks for sharing updates.

If it is not too much trouble adding the setting for turning on/off Chart Bubbles?
Sorry, this could be per my experience only, but due to the Screen vs Chart size the "bubbling" is too cluttering :)

Perhaps the usual BUY vs SELL arrows could be more helpful with making observation and further decisions
Also, Would this be possible, providing idea for the watchlist column - flags for tracking trend direction?
Thanks
Yep, sorry about that. Here is a version that can toggle the visibility of the gears. You can use the top line color for entry signals.
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 Fluideng to make the triple SuplerTrend into one indicator. Also removed EMA2 and Bar color.
# Modified by Barbaros to show as a lower indicator, removed EMA and others
# Modified by Barbaros to add trend consensus and bar painting
# modified by Barbaros to add gear numbers
# modified by Barbaros to bug fixes
# v4.2

declare lower;

input Limit = 3;
input BarColor = yes;
input ShowGears = yes;

### SuperTrend #1
input AtrMult = 3.00;
input nATR = 12;
input 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;

### SuperTrend #2
input AtrMult2 = 2.00;
input nATR2 = 11;

def ATR2 = ATR("length" = nATR2, "average type" = AvgType);
def UP_Band_Basic2 = HL2 + (AtrMult2 * ATR);
def LW_Band_Basic2 = HL2 + (-AtrMult2 * ATR);
def UP_Band2 = if ((UP_Band_Basic2 < UP_Band2[1]) or (close[1] > UP_Band2[1])) then UP_Band_Basic2 else UP_Band2[1];
def LW_Band2 = if ((LW_Band_Basic2 > LW_Band2[1]) or (close[1] < LW_Band2[1])) then LW_Band_Basic2 else LW_Band2[1];

def ST2 = if ((ST2[1] == UP_Band2[1]) and (close < UP_Band2)) then UP_Band2
else if ((ST2[1] == UP_Band2[1]) and (close > Up_Band2)) then LW_Band2
else if ((ST2[1] == LW_Band2[1]) and (close > LW_Band2)) then LW_Band2
else if ((ST2[1] == LW_Band2) and (close < LW_Band2)) then UP_Band2
else LW_Band2;

### SuperTrend #3
input AtrMult3 = 1.00;
input nATR3 = 10;

def ATR3 = ATR("length" = nATR3, "average type" = AvgType);
def UP_Band_Basic3 = HL2 + (AtrMult3 * ATR);
def LW_Band_Basic3 = HL2 + (-AtrMult3 * ATR);
def UP_Band3 = if ((UP_Band_Basic3 < UP_Band3[1]) or (close[1] > UP_Band3[1])) then UP_Band_Basic3 else UP_Band3[1];
def LW_Band3 = if ((LW_Band_Basic3 > LW_Band3[1]) or (close[1] < LW_Band3[1])) then LW_Band_Basic3 else LW_Band3[1];

def ST3 = if ((ST3[1] == UP_Band3[1]) and (close < UP_Band3)) then UP_Band3
else if ((ST3[1] == UP_Band3[1]) and (close > Up_Band3)) then LW_Band3
else if ((ST3[1] == LW_Band3[1]) and (close > LW_Band3)) then LW_Band3
else if ((ST3[1] == LW_Band3) and (close < LW_Band3)) then UP_Band3
else LW_Band3;

### ST consensus

def ST1Val = (if close > ST then 1 else if close < ST then -1 else 0);
def ST2Val = (if close > ST2 then 1 else if close < ST2 then -1 else 0);
def ST3Val = (if close > ST3 then 1 else if close < ST3 then -1 else 0);

def totalShorts = (if ST1Val < 0 then -1 else 0) +
                  (if ST2Val < 0 then -1 else 0) +
                  (if ST3Val < 0 then -1 else 0);
def totalLongs = (if ST1Val > 0 then 1 else 0) +
                 (if ST2Val > 0 then 1 else 0) +
                 (if ST3Val > 0 then 1 else 0);

def TrendDirection = if totalLongs > 0 and totalLongs >= Limit then 1 else if totalShorts < 0 and totalShorts <= -Limit then -1 else 0;

### Gears

def DirectionFilter = if totalLongs == 3 then 1 else if totalShorts == -3 then -1 else DirectionFilter[1];

def LongGear1_ = totalShorts crosses above -3;
def LongGear2_ = totalShorts crosses above -2;
def LongGear3_ = totalShorts crosses above -1;

def LongGear1 = DirectionFilter == -1 and LongGear1_ and !LongGear2_ and !LongGear3_;
def LongGear2 = DirectionFilter == -1 and LongGear2_ and !LongGear3_;
def LongGear3 = DirectionFilter[1] == -1 and LongGear3_;

def ShortGear1_ = totalLongs crosses below 3;
def ShortGear2_ = totalLongs crosses below 2;
def ShortGear3_ = totalLongs crosses below 1;

def ShortGear1 = DirectionFilter == 1 and ShortGear1_ and !ShortGear2_ and !ShortGear3_;
def ShortGear2 = DirectionFilter == 1 and ShortGear2_ and !ShortGear3_;
def ShortGear3 = DirectionFilter[1] == 1 and ShortGear3_;

def GearNumber = if LongGear1 then 1
                 else if LongGear2 then 2
                 else if LongGear3 then 3
                 else if ShortGear1 then -1
                 else if ShortGear2 then -2
                 else if ShortGear3 then -3
                 else GearNumber[1];

### Plots

plot SeparatorTop = if isNaN(close) then Double.NaN else 7;
SeparatorTop.SetDefaultColor(Color.GRAY);
SeparatorTop.SetHiding(!ShowGears);

plot Trend = if isNaN(close) then Double.NaN else 5;
Trend.SetPaintingStrategy(PaintingStrategy.POINTS);
Trend.SetLineWeight(3);
Trend.AssignValueColor(if TrendDirection == 1 then Color.GREEN else if TrendDirection == -1 then Color.RED else Color.GRAY);

plot SeparatorBottom = if isNaN(close) then Double.NaN else 4;
SeparatorBottom.SetDefaultColor(Color.GRAY);

plot SuperTrend1 = if isNaN(close) then Double.NaN else 1;
SuperTrend1.SetPaintingStrategy(PaintingStrategy.POINTS);
SuperTrend1.SetLineWeight(3);
SuperTrend1.AssignValueColor(if close > ST then Color.GREEN else if close < ST then Color.RED else Color.GRAY);

plot SuperTrend2 = if isNaN(close) then Double.NaN else 2;
SuperTrend2.SetPaintingStrategy(PaintingStrategy.POINTS);
SuperTrend2.SetLineWeight(3);
SuperTrend2.AssignValueColor(if close > ST2 then Color.GREEN else if close < ST2 then Color.RED else Color.GRAY);

plot SuperTrend3 = if isNaN(close) then Double.NaN else 3;
SuperTrend3.SetPaintingStrategy(PaintingStrategy.POINTS);
SuperTrend3.SetLineWeight(3);
SuperTrend3.AssignValueColor(if close > ST3 then Color.GREEN else if close < ST3 then Color.RED else Color.GRAY);

AddChartBubble(ShowGears and LongGear1, 5, "1", Color.YELLOW);
AddChartBubble(ShowGears and LongGear2, 5, "2", Color.GREEN);
AddChartBubble(ShowGears and LongGear3, 5, "3", Color.LIGHT_GREEN);

AddChartBubble(ShowGears and ShortGear1, 5, "1", Color.DARK_ORANGE);
AddChartBubble(ShowGears and ShortGear2, 5, "2", Color.RED);
AddChartBubble(ShowGears and ShortGear3, 5, "3", Color.LIGHT_RED);

### Bar Color

AssignPriceColor(if BarColor then if TrendDirection == 1 then Color.GREEN else if TrendDirection == -1 then Color.RED else Color.GRAY else Color.CURRENT);

# End Code SuperTrend Yahoo Finance Replica

# Testing
#plot test = GearNumber;
#test.SetPaintingStrategy(paintingStrategy.VALUES_BELOW);
 

DeepThinker

New member
Yep, sorry about that. Here is a version that can toggle the visibility of the gears. You can use the top line color for entry signals.
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 Fluideng to make the triple SuplerTrend into one indicator. Also removed EMA2 and Bar color.
# Modified by Barbaros to show as a lower indicator, removed EMA and others
# Modified by Barbaros to add trend consensus and bar painting
# modified by Barbaros to add gear numbers
# modified by Barbaros to bug fixes
# v4.2

declare lower;

input Limit = 3;
input BarColor = yes;
input ShowGears = yes;

### SuperTrend #1
input AtrMult = 3.00;
input nATR = 12;
input 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;

### SuperTrend #2
input AtrMult2 = 2.00;
input nATR2 = 11;

def ATR2 = ATR("length" = nATR2, "average type" = AvgType);
def UP_Band_Basic2 = HL2 + (AtrMult2 * ATR);
def LW_Band_Basic2 = HL2 + (-AtrMult2 * ATR);
def UP_Band2 = if ((UP_Band_Basic2 < UP_Band2[1]) or (close[1] > UP_Band2[1])) then UP_Band_Basic2 else UP_Band2[1];
def LW_Band2 = if ((LW_Band_Basic2 > LW_Band2[1]) or (close[1] < LW_Band2[1])) then LW_Band_Basic2 else LW_Band2[1];

def ST2 = if ((ST2[1] == UP_Band2[1]) and (close < UP_Band2)) then UP_Band2
else if ((ST2[1] == UP_Band2[1]) and (close > Up_Band2)) then LW_Band2
else if ((ST2[1] == LW_Band2[1]) and (close > LW_Band2)) then LW_Band2
else if ((ST2[1] == LW_Band2) and (close < LW_Band2)) then UP_Band2
else LW_Band2;

### SuperTrend #3
input AtrMult3 = 1.00;
input nATR3 = 10;

def ATR3 = ATR("length" = nATR3, "average type" = AvgType);
def UP_Band_Basic3 = HL2 + (AtrMult3 * ATR);
def LW_Band_Basic3 = HL2 + (-AtrMult3 * ATR);
def UP_Band3 = if ((UP_Band_Basic3 < UP_Band3[1]) or (close[1] > UP_Band3[1])) then UP_Band_Basic3 else UP_Band3[1];
def LW_Band3 = if ((LW_Band_Basic3 > LW_Band3[1]) or (close[1] < LW_Band3[1])) then LW_Band_Basic3 else LW_Band3[1];

def ST3 = if ((ST3[1] == UP_Band3[1]) and (close < UP_Band3)) then UP_Band3
else if ((ST3[1] == UP_Band3[1]) and (close > Up_Band3)) then LW_Band3
else if ((ST3[1] == LW_Band3[1]) and (close > LW_Band3)) then LW_Band3
else if ((ST3[1] == LW_Band3) and (close < LW_Band3)) then UP_Band3
else LW_Band3;

### ST consensus

def ST1Val = (if close > ST then 1 else if close < ST then -1 else 0);
def ST2Val = (if close > ST2 then 1 else if close < ST2 then -1 else 0);
def ST3Val = (if close > ST3 then 1 else if close < ST3 then -1 else 0);

def totalShorts = (if ST1Val < 0 then -1 else 0) +
                  (if ST2Val < 0 then -1 else 0) +
                  (if ST3Val < 0 then -1 else 0);
def totalLongs = (if ST1Val > 0 then 1 else 0) +
                 (if ST2Val > 0 then 1 else 0) +
                 (if ST3Val > 0 then 1 else 0);

def TrendDirection = if totalLongs > 0 and totalLongs >= Limit then 1 else if totalShorts < 0 and totalShorts <= -Limit then -1 else 0;

### Gears

def DirectionFilter = if totalLongs == 3 then 1 else if totalShorts == -3 then -1 else DirectionFilter[1];

def LongGear1_ = totalShorts crosses above -3;
def LongGear2_ = totalShorts crosses above -2;
def LongGear3_ = totalShorts crosses above -1;

def LongGear1 = DirectionFilter == -1 and LongGear1_ and !LongGear2_ and !LongGear3_;
def LongGear2 = DirectionFilter == -1 and LongGear2_ and !LongGear3_;
def LongGear3 = DirectionFilter[1] == -1 and LongGear3_;

def ShortGear1_ = totalLongs crosses below 3;
def ShortGear2_ = totalLongs crosses below 2;
def ShortGear3_ = totalLongs crosses below 1;

def ShortGear1 = DirectionFilter == 1 and ShortGear1_ and !ShortGear2_ and !ShortGear3_;
def ShortGear2 = DirectionFilter == 1 and ShortGear2_ and !ShortGear3_;
def ShortGear3 = DirectionFilter[1] == 1 and ShortGear3_;

def GearNumber = if LongGear1 then 1
                 else if LongGear2 then 2
                 else if LongGear3 then 3
                 else if ShortGear1 then -1
                 else if ShortGear2 then -2
                 else if ShortGear3 then -3
                 else GearNumber[1];

### Plots

plot SeparatorTop = if isNaN(close) then Double.NaN else 7;
SeparatorTop.SetDefaultColor(Color.GRAY);
SeparatorTop.SetHiding(!ShowGears);

plot Trend = if isNaN(close) then Double.NaN else 5;
Trend.SetPaintingStrategy(PaintingStrategy.POINTS);
Trend.SetLineWeight(3);
Trend.AssignValueColor(if TrendDirection == 1 then Color.GREEN else if TrendDirection == -1 then Color.RED else Color.GRAY);

plot SeparatorBottom = if isNaN(close) then Double.NaN else 4;
SeparatorBottom.SetDefaultColor(Color.GRAY);

plot SuperTrend1 = if isNaN(close) then Double.NaN else 1;
SuperTrend1.SetPaintingStrategy(PaintingStrategy.POINTS);
SuperTrend1.SetLineWeight(3);
SuperTrend1.AssignValueColor(if close > ST then Color.GREEN else if close < ST then Color.RED else Color.GRAY);

plot SuperTrend2 = if isNaN(close) then Double.NaN else 2;
SuperTrend2.SetPaintingStrategy(PaintingStrategy.POINTS);
SuperTrend2.SetLineWeight(3);
SuperTrend2.AssignValueColor(if close > ST2 then Color.GREEN else if close < ST2 then Color.RED else Color.GRAY);

plot SuperTrend3 = if isNaN(close) then Double.NaN else 3;
SuperTrend3.SetPaintingStrategy(PaintingStrategy.POINTS);
SuperTrend3.SetLineWeight(3);
SuperTrend3.AssignValueColor(if close > ST3 then Color.GREEN else if close < ST3 then Color.RED else Color.GRAY);

AddChartBubble(ShowGears and LongGear1, 5, "1", Color.YELLOW);
AddChartBubble(ShowGears and LongGear2, 5, "2", Color.GREEN);
AddChartBubble(ShowGears and LongGear3, 5, "3", Color.LIGHT_GREEN);

AddChartBubble(ShowGears and ShortGear1, 5, "1", Color.DARK_ORANGE);
AddChartBubble(ShowGears and ShortGear2, 5, "2", Color.RED);
AddChartBubble(ShowGears and ShortGear3, 5, "3", Color.LIGHT_RED);

### Bar Color

AssignPriceColor(if BarColor then if TrendDirection == 1 then Color.GREEN else if TrendDirection == -1 then Color.RED else Color.GRAY else Color.CURRENT);

# End Code SuperTrend Yahoo Finance Replica

# Testing
#plot test = GearNumber;
#test.SetPaintingStrategy(paintingStrategy.VALUES_BELOW);
Superb ! Many Thanks
 
@barbaros I still seem to be too stupid to get the scanner to work. Can you help with a step by step? I know it has to do with making equal to 1, -1 But I can't get it to work right. What I want is to scan for the short term (3,12 setting) when it turns green on 30 min and is priced greater then $5.00 and average daily volume is greater then 500K and occurs within 3 bars. Can you help me? Thanks in advance.
 
Top