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