Author Message:
The main characteristic that this indicator has is that, not like the normal super trend, it follows the trend better adapting itself in the retracement phases.
The second feature that dictates the best usage of this indicator, is that it shows a zone in which to buy or sell to have the best risk-to-reward ratio.
The indicator also works as the dynamic level of support and resistance and can be used best for trend-following strategies to maximize profits.
CODE:
CSS:
# https://www.tradingview.com/v/KLkg5m41/
#// OmegaTools
#indicator("Smooth Trail V2", overlay=true, timeframe="", timeframe_gaps=true)
# converted and mod by Sam4Cok@Samer800 - 11/2023
input timeframe = {Default "Chart", "Custom"};
input customTimeframe = AggregationPeriod.FIFTEEN_MIN;
input movAvgType = AverageType.HULL;
input Multiplier = 3.00; # "Multiplier"
input Length = 34; # "Length"
input ZoneWidth = 1.00; # "Zone width"
input supertrendWeightage = 3;
input MovAvgWeightage = 1;
input highLowWeightage = 1;
def na = Double.NaN;
def totalWeight = supertrendWeightage + MovAvgWeightage + highLowWeightage;
def tfHL = hl2;
def tfC = close;
def tfH = high;
def tfL = low;
def mtfHL = hl2(Period = customTimeframe);
def mtfC = close(Period = customTimeframe);
def mtfH = high(Period = customTimeframe);
def mtfL = low(Period = customTimeframe);
def h; def c; def l;def hl;
Switch (timeframe) {
Case "Custom" :
hl = mtfHL;
h = mtfH;
c = mtfC;
l = mtfL;
Default :
hl = tfHL;
h = tfH;
c = tfC;
l = tfL;
}
DefineGlobalColor("up", CreateColor(41,98,255));
DefineGlobalColor("dn", CreateColor(233,30,99));
DefineGlobalColor("dup", CreateColor(0,58,220));
DefineGlobalColor("ddn", CreateColor(170,17,69));
#pine_supertrend(src, factor, atrPeriod) =>
script supertrend {
input src = hl2;
input h = high;
input c = close;
input l = low;
input factor = 3;
input Period = 10;
def tr = TrueRange(h, c, l);
def atr = WildersAverage(tr, Period);
def up = src + factor * atr;
def dn = src - factor * atr;
def lowerBand;
def upperBand;
def up1 = if (IsNaN(upperBand[1]) or upperBand[1] == 0) then up else upperBand[1];
def dn1 = if (IsNaN(lowerBand[1]) or lowerBand[1] == 0) then dn else lowerBand[1];
upperBand = if (up < up1) or (c[1] > up1) then up else up1;
lowerBand = if (dn > dn1) or (c[1] < dn1) then dn else dn1;
def trend;# = na
def superTrend;# = na
def prevSuperTrend = If(superTrend[1] == 0, up1 , superTrend[1]);
if (IsNaN(up) or IsNaN(dn)) {
trend = 1;
} else
if prevSuperTrend == up1 {
trend = if c > upperBand then -1 else 1;
} else {
trend = if c < lowerBand then 1 else -1;
}
superTrend = if trend == -1 then lowerBand else upperBand;
plot ST = superTrend;
plot dir = trend;
}
def tr = TrueRange(h, c, l);
def atrs = WildersAverage(tr, 100);
def factor = Round((7 + Multiplier) / 2, 0);
def supertrend = supertrend(hl, h, c, l, factor, Length * 2).st;
def direction = supertrend(hl, h, c, l, factor, Length * 2).dir;
def lengthMovAvg = Round((21 + Length) / 2, 0);
def hullup = MovingAverage(movAvgType, h, lengthMovAvg) + atrs * Round(Multiplier / 2.5, 0);
def hulldn = MovingAverage(movAvgType, l, lengthMovAvg) - atrs * Round(Multiplier / 2.5, 0);
def hline = Highest(c, Length) + atrs;
def lline = Lowest (c, Length) + atrs;
def supert = if c > supertrend then
(supertrend*supertrendWeightage + hulldn*MovAvgWeightage + lline*highLowWeightage)/totalWeight
else if c < supertrend then
(supertrend*supertrendWeightage + hullup*MovAvgWeightage + hline*highLowWeightage)/totalWeight else na;
def supert2 = if c > supert then supert + atrs * ZoneWidth else
if c < supert then supert - atrs * ZoneWidth else na;
def tool = direction > 0 or direction < 0;
def tool2 = if tool then supert2 else na;#, "Zone line"
plot tool1 = if direction > 0 then supert else na; # "Change line"
plot tool12 = if direction < 0 then supert else na; # "Change line"
tool1.SetDefaultColor(GlobalColor("dn"));
tool12.SetDefaultColor(GlobalColor("up"));
AddCloud(tool1, tool2, GlobalColor("ddn"));
AddCloud(tool2, tool12, GlobalColor("dup"));
#-- END of CODE