Half-Trend Channel [BigBeluga] for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
ebJQgj5.png


Author Message:
Half Trend Channel [BigBeluga] is a powerful trend-following indicator designed to identify trend direction, fakeouts, and potential reversal points. The combination of upper/lower bands, midline coloring, and specific signals makes it ideal for spotting trend continuation and market reversals.

More Details: https://www.tradingview.com/v/pP2qBbWw/

CODE:

CSS:
#// Indicator for TOS
#// © BigBeluga
#indicator("Half-Trend Channel [BigBeluga]", overlay = true, max_labels_count = 500)
# Converted by Sam4Cok@Samer800     - 01/2025

input timeframe = AggregationPeriod.MIN;
input length    = 10; #, "Length")
input bandMultiplier = 2.0; #, "Bands", step = 0.1)
input showBand = yes;
input BandsTransparency = 30; #, "Bands Transparency")


def na = Double.NaN;
def last = isNaN(close);
def cap = GetAggregationPeriod();
def tf = Max(cap, timeframe);
def n = Min(Max(BandsTransparency, 0), 100);
def rgb = n * 2.55;
def closeMA     = Average(close(Period = tf), length); # // Moving average of close prices
def highestHigh = highest(high(Period = tf), length);  # // Highest high over the period
def lowestLow   = lowest(low(Period = tf), length);    # // Lowest low over the period

def hl_t;
def hl_t1 = if !hl_t[1] then close else hl_t[1];
    hl_t = if closeMA < hl_t1 and highestHigh < hl_t1 then highestHigh else
           if closeMA > hl_t1 and lowestLow   > hl_t1 then lowestLow else hl_t1;
def s_hlt   = HullMovingAvg(hl_t, length);
def tr      = TrueRange(high(Period = tf), close(Period = tf), low(Period = tf));
def stdv    = WildersAverage(tr, 100) * bandMultiplier;
def stdv_p  = stdv * 1.5;
def upper   = s_hlt + stdv;
def upper_p = s_hlt + stdv_p;
def lower   = s_hlt - stdv;
def lower_p = s_hlt - stdv_p;

def sig_up = (hl_t > hl_t1) and (hl_t[1] <= hl_t1[1]);
def sig_dn = (hl_t < hl_t1) and (hl_t[1] >= hl_t1[1]);
def trend_col = if sig_up then 1 else if sig_dn then -1 else trend_col[1];

#// Fake outs
def upLab = if low(Period = tf)[2] > lower_p[2] and low(Period = tf)[1] < lower_p[1] and
               low(Period = tf) > lower_p then low(Period = tf)[1] else 0;
def dnLab = if high(Period = tf)[2] < upper_p[2] and high(Period = tf)[1] > upper_p[1] and
               high(Period = tf) < upper_p then high(Period = tf)[1] else 0;
def upLab1 = upLab[-1];
def dnLab1 = dnLab[-1];
    
plot fakeUp = if upLab1 and !upLab1[1] then upLab1 else na;
plot fakeDn = if dnLab1 and !dnLab1[1] then dnLab1 else na;
fakeUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
fakeDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
fakeUp.SetDefaultColor(CreateColor(0, 196, 196));
fakeDn.SetDefaultColor(CreateColor(196, 0, 196));

#// Reversals
def crossUp = (hl2(Period = tf) > hl2(Period = tf)[2]) and (hl2(Period = tf)[1] <= hl2(Period = tf)[3]);
def crossDn = (hl2(Period = tf) < hl2(Period = tf)[2]) and (hl2(Period = tf)[1] >= hl2(Period = tf)[3]);
def revUp = if crossUp and low(Period = tf) < lower_p then low[1] else 0;
def revDn = if crossDn and high(Period = tf) > upper_p then high[1] else 0;
def revUp1 = revUp[-1];
def revDn1 = revDn[-1];
plot sigUp = if revUp1 and !revUp1[1] then revUp1 else na;
plot sigDn = if revDn1 and !revDn1[1] then revDn1 else na;
sigUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
sigDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
sigUp.SetDefaultColor(Color.CYAN);
sigDn.SetDefaultColor(Color.MAGENTA);

#-- plot

plot HTC = if !last and s_hlt then s_hlt else na;
HTC.SetLineWeight(2);
HTC.AssignValueColor(if trend_col>0 then Color.CYAN else if trend_col<0 then Color.MAGENTA else Color.GRAY);

#-- Band
plot pu1 = if !last and showBand and upper_p then upper_p else na;
plot pu = if !last and showBand and upper then upper else na;
plot pl = if !last and showBand and lower then lower else na;
plot pl1 = if !last and showBand and lower_p then lower_p else na;

pu1.SetDefaultColor(CreateColor(196, 0, 196));
pu.SetDefaultColor(CreateColor(196, 0, 196));
pl.SetDefaultColor(CreateColor(0, 196, 196));
pl1.SetDefaultColor(CreateColor(0, 196, 196));

AddCloud(pu1, pu, CreateColor(rgb, 0, rgb));
AddCloud(pl, pl1, CreateColor(0, rgb, rgb));

#-- 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
375 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