SuperBollingerTrend:
https://www.tradingview.com/script/AjWfiZpw-SuperBollingerTrend-Expo/
SushiTrend:
https://www.tradingview.com/v/dfVzbU6r/
CODE: Fix Sushi Tend Code
CSS:
#--- SuperTrend, Bollinger Trend, Sushi Trrend indicator
# Converted and modifiedTrueRange by Sam4Cok@Samer800 - 05/2023
# Sushi Trend Code Fix - 11/2023
input BarsColor = no;
input SupertrendCloud = no;
input ShowTrendLine = yes;
input ShowZigZag = no;
input ShowMovAvgLine = no;
input ShowSignals = yes;
input UseMovAvgFilter = no;
input CalcMethod = {"ATR Trend", default "Bollinger Trend", "Sushi Trend"};
input supertrendSource = hl2;
input Period = 12; # "Length"
input factor = 2.0; # "Factor"
input FactorForSushiTrend = 5;#, title = 'Engulfing Factor')
input averageType = {default "ZLSMA","TRAMA","VAWMA","eVWMA","SMMA","EMA","TEMA","WMA","VWMA","SMA","HMA", "McGinley"};
input MovAvgLength = 100;
input MovAvgSrc = close;
#input useChartTimeFrame = yes;
#input manualAggPeriod = AggregationPeriod.FIFTEEN_MIN;
def na = Double.NaN;
def src = supertrendSource;
def bodyMiddle = ohlc4;
def current = GetAggregationPeriod();
#def tf = if useChartTimeFrame then current else manualAggPeriod;
#def zlsmaSrc = if useChartTimeFrame then MovAvgSrc else close(Period=tf);
#---color
DefineGlobalColor("Blue" , CreateColor(33, 150, 243));
DefineGlobalColor("up", CreateColor(76, 175, 80));
DefineGlobalColor("dn", CreateColor(255, 82, 82));
def atrTrend = CalcMethod == CalcMethod."ATR Trend";
def SushTrend = CalcMethod == CalcMethod."Sushi Trend";
#vwma(source, length)
script VWMA {
input x = close;
input y = 15;
def VWMA = Average(x * volume, y) / Average(volume, y);
plot result = VWMA;
}
# vawma(src, len) =>
script vawma {
input src = hlc3;
input len = 50;
def sum;
def vol;
def v;
def s = fold i = 0 to len with p do
src[i];
def volm = if IsNaN(volm[1]) then 0 else
fold j = 0 to len with u do
volume[j];
def ma = if !IsNaN(s) and !IsNaN(volm) then
fold k = 0 to len with w do
len - k else 0;
v = fold l = 1 to len with q do
if IsNaN(v[1]) then volm else
volume * ma;
vol = fold m = 0 to len with r do
r + v[m];
sum = fold n = 0 to len with t do
t + src[n] * v[n];
plot vawma = sum / vol;
}
#ma(mode, len, src) =>
script ma {
input type = "EMA";
input src = close;
input len = 100;
def lsma = Inertia(src, len);
def lsma2 = Inertia(lsma, len);
def eq = lsma - lsma2;
def zlsma = lsma + eq;
def volumeSum = Sum(volume, len);
def evwma = ((volumeSum - volume) * evwma[1] + volume * src) / volumeSum;
def e = ExpAverage(src, len);
def Mcg = if IsNaN(Mcg[1]) then Average(src, len) else
CompoundValue(1, Mcg[1] + ((src - Mcg[1]) / (0.6 * len * Power(src / Mcg[1], 4))), src);
def H = Highest(high, len);
def L = Lowest(low, len);
def HH = Max(Sign(H - H[1]), 0);
def LL = Max(Sign(L - L[1]) * -1, 0);
def TC = Power(Average(if HH or LL then 1 else 0, len), 2);
def ama = CompoundValue(1, ama[1] + TC * (src - ama[1]), src);
def ma;
ma = if type == "SMA" then Average(src, len) else
if type == "ZLSMA" then zlsma else
if type == "VAWMA" then vawma(src, len) else
if type == "EMA" then ExpAverage(src, len) else
if type == "TEMA" then TEMA(src, len) else
if type == "WMA" then WMA(src, len) else
if type == "VWMA" then vwma(src, len) else
if type == "SMMA" then WildersSmoothing(src, len) else
if type == "HMA" then HullMovingAvg(src, len) else
if type == "eVWMA" then evwma else
if type == "TRAMA" then ama else
if type == "McGinley" then Mcg else Average(src, len);
plot result = ma;
}
#pine_supertrend(src, factor, atrPeriod) =>
script supertrend {
input src = hl2;
input factor = 3;
input Period = 10;
input atrTrend = yes;
input MovAvgType = AverageType.SIMPLE;
def lowerBand;
def upperBand;
def nATR = ATR(LENGTH = Period);
def bbup = ma(MovAvgType, high, Period) + StDev(high, Period) * factor;
def bbdn = ma(MovAvgType, low, Period) - StDev(low, Period) * factor;
def atrup = src + factor * nATR;
def atrdn = src - factor * nATR;
def up = if atrTrend then atrup else bbup;
def dn = if atrTrend then atrdn else bbdn;
def up1 = if (IsNaN(upperBand[1]) or upperBand[1] == 0) then up else If(upperBand[1] == 0, up, upperBand[1]);
def dn1 = if (IsNaN(lowerBand[1]) or lowerBand[1] == 0) then dn else If(lowerBand[1] == 0, dn, lowerBand[1]);
upperBand = if (up < up1) or (close[1] > up1) then up else up1;
lowerBand = if (dn > dn1) or (close[1] < dn1) then dn else dn1;
def trend;# = na
def superTrend;# = na
def prevSuperTrend = If(superTrend[1] == 0, up1, superTrend[1]);
if IsNaN(nATR[1]) or IsNaN(StDev(src, Period)) {
trend = 1;
} else
if prevSuperTrend == up1 {
trend = if close > upperBand then -1 else 1;
} else {
trend = if close < lowerBand then 1 else -1;
}
superTrend = if trend == -1 then lowerBand else upperBand;
plot ST = superTrend;
plot dir = trend;
}
#-- Moving Avg
def MovAvg = ma(averageType, MovAvgSrc, MovAvgLength);
plot MovAvgLine = if ShowMovAvgLine then MovAvg else na;
MovAvgLine.SetDefaultColor(Color.CYAN);
#-- ST
def supertrend = if SushTrend then na else supertrend(src, factor, Period, atrTrend, averageType).ST;
def direction = if SushTrend then na else supertrend(src, factor, Period, atrTrend, averageType).DIR;
plot upTrend = if ShowTrendLine and (direction < 0) then supertrend else na;#, "Up Trend"
upTrend.SetDefaultColor(GlobalColor("up"));
plot downTrend = if ShowTrendLine and (direction > 0) then supertrend else na;#, "Down Trend"
downTrend.SetDefaultColor(GlobalColor("dn"));
def LongTrigger = direction != direction[1] and direction < 0;
def ShortTrigger = direction != direction[1] and direction > 0;
plot LongDot = if ShowTrendLine and LongTrigger then upTrend else na;
LongDot.SetPaintingStrategy(PaintingStrategy.POINTS);
LongDot.AssignValueColor(GlobalColor("up"));
LongDot.SetLineWeight(4);
plot ShortDot = if ShowTrendLine and ShortTrigger then downTrend else na;
ShortDot.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot.AssignValueColor(GlobalColor("dn"));
ShortDot.SetLineWeight(4);
AddChartBubble(ShowSignals and LongTrigger and If(UseMovAvgFilter, src > MovAvg, 1),
If(ShowTrendLine, supertrend, low), "Bull", Color.GREEN, no);
AddChartBubble(ShowSignals and ShortTrigger and If(UseMovAvgFilter, src < MovAvg, 1),
If(ShowTrendLine, supertrend, high), "Bear", Color.RED, yes);
AddCloud(bodyMiddle, upTrend, Color.DARK_GREEN);
AddCloud(downTrend, bodyMiddle, Color.DARK_RED);
#-- END CODE--
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © HoanGhetti
#indicator("Sushi Trend [HG]", overlay = true)
def last = IsNaN(close);
def hh = Highest(high, FactorForSushiTrend);
def ll = Lowest(low, FactorForSushiTrend);
def stMatrixMax = Highest(high, FactorForSushiTrend * 2);
def stMatrixMin = Lowest(low, FactorForSushiTrend * 2);
def max = hh == stMatrixMax;
def min = ll == stMatrixMin;
def valid = max and min and ((stMatrixMin == low[FactorForSushiTrend - 1])
or (stMatrixMax == high[FactorForSushiTrend - 1]));
def barssince = if valid[1] then 0 else barssince[1] + 1;
def sushi = SushTrend and valid and barssince >= FactorForSushiTrend and !last[1];#!IsNaN(close[1]);
def diff = (sushi-sushi[1]) != 0;
def lastMax = (if diff and sushi and max then stMatrixMax else lastMax[1]);
def lastMin = (if diff and sushi then stMatrixMin else lastMin[1]);
def SushicrossUp = Crosses(close, lastMax, CrossingDirection.ABOVE);
def SushicrossDn = Crosses(close, lastMin, CrossingDirection.BELOW);
def Sushidirection;
if SushicrossUp {
Sushidirection = 1;
} else
if SushicrossDn {
Sushidirection = -1;
} else {
Sushidirection = Sushidirection[1];
}
def sushiTrend = if Sushidirection > 0 then lastMin else lastMax;
def sushiChange = sushiTrend and Sushidirection!=Sushidirection[1];
def sushiLongTrigger = SushTrend and Sushidirection == 1 and Sushidirection[1] != 1;
def sushiShortTrigger = SushTrend and Sushidirection ==-1 and Sushidirection[1] !=-1;
plot stUp = if last or !ShowTrendLine then na else
if Sushidirection > 0 then sushiTrend else na; # 'Sushi Trend'
stUp.SetDefaultColor(GlobalColor("up"));
plot stDn = if last or !ShowTrendLine then na else
if Sushidirection < 0 then sushiTrend else na; # 'Sushi Trend'
stDn.SetDefaultColor(GlobalColor("dn"));
plot LongSushiDot = if ShowTrendLine and sushiLongTrigger then sushiTrend else na;
LongSushiDot.SetPaintingStrategy(PaintingStrategy.POINTS);
LongSushiDot.AssignValueColor(GlobalColor("up"));
LongSushiDot.SetLineWeight(3);
plot ShortSushiDot = if ShowTrendLine and sushiShortTrigger then sushiTrend else na;
ShortSushiDot.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortSushiDot.AssignValueColor(GlobalColor("dn"));
ShortSushiDot.SetLineWeight(3);
def stPlot = if last or !ShowTrendLine then na else if !sushiChange then sushiTrend else na;
AddCloud(bodyMiddle, stPlot, Color.DARK_GREEN, Color.DARK_RED);
AddChartBubble(ShowSignals and sushiLongTrigger and If(UseMovAvgFilter, src > MovAvg, 1),
If(ShowTrendLine, sushiTrend, low), "Bull", Color.GREEN, no);
AddChartBubble(ShowSignals and sushiShortTrigger and If(UseMovAvgFilter, src < MovAvg, 1),
If(ShowTrendLine, sushiTrend, high), "Bear", Color.RED, yes);
#--- ZigZag
def triggerUp = if SushTrend then sushiLongTrigger else LongTrigger;
def triggerDn = if SushTrend then sushiShortTrigger else ShortTrigger;
def zigzagDir = if SushTrend then If(Sushidirection == 1, -1, 1) else direction;
def ZigZagSrc = if SushTrend then sushiTrend else supertrend;
plot zigzag = if !ShowZigZag then na else
if triggerUp then ZigZagSrc else if triggerDn then ZigZagSrc else
if IsNaN(close[-1]) then
if zigzagDir > 0 then Highest(src, Period) else Lowest(src, Period) else na;
zigzag.AssignValueColor(if zigzagDir[1] < 0 then Color.WHITE else Color.GRAY);
zigzag.SetStyle(Curve.SHORT_DASH);
zigzag.EnableApproximation();
#--- END CODE
def lastUp = if triggerUp then ZigZagSrc else If(lastUp[1] == 0, ZigZagSrc, lastUp[1]);
def lastDn = if triggerDn then ZigZagSrc else If(lastDn[1] == 0, ZigZagSrc, lastDn[1]);
def centerUp;
def centerDn;
if (lastUp != lastUp[1]) {
centerUp = (If(centerUp[1] == 0, lastUp, centerUp[1]) + lastUp) / 2;
} else {
centerUp = If(centerUp[1] == 0, lastUp, centerUp[1]);
}
if (lastDn != lastDn[1]) {
centerDn = (If(centerDn[1] == 0, lastDn, centerDn[1]) + lastDn) / 2;
} else {
centerDn = If(centerDn[1] == 0, lastDn, centerDn[1]);
}
def midSupUp = ma(averageType, centerUp , Period);
def midSupDn = ma(averageType, centerDn , Period);
def midSup = (midSupUp + midSupDn) / 2;
plot MidLine = if IsNaN(close) or midSup == 0 then na else midSup;
MidLine.SetHiding(!SupertrendCloud);
MidLine.AssignValueColor(if midSup < src then GlobalColor("blue") else Color.PLUM);
def MidLineUp = midSupUp;
def MidLineDn = midSupDn;
def trendUp = SupertrendCloud and midSup < src and midSupUp < src and midSupDn < src;
def trendDn = SupertrendCloud and midSup >= src and midSupUp >= src and midSupDn >= src;
AddCloud(if trendUp then midSupDn else na, midSupUp, GlobalColor("blue"));
AddCloud(if trendDn then midSupDn else na, midSupUp, Color.PLUM);
AddCloud(if (!trendDn and !trendUp and SupertrendCloud) then midSupDn else na, midSupUp, Color.DARK_GRAY);
#--- Bar Color
def BarUpEx = midSup < src and midSupUp < src and midSupDn < src;
def BarDnEx = midSup >= src and midSupUp >= src and midSupDn >= src;
def BarUp = midSup < src and midSupDn < src;
def BarDn = midSup >= src and midSupUp >= src;
AssignPriceColor(if !BarsColor then Color.CURRENT else
if BarUpEx then Color.GREEN else
if BarUp then Color.DARK_GREEN else
if BarDnEx then Color.RED else
if BarDn then Color.DARK_RED else Color.GRAY);
#--- END of CODE
Last edited: