Smooth Trail V2 for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
smoothTrailS_CHARTS.png

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
 

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