Author message:
This indicator is based on HUll (shown ) plus log trend
to control it you need to play with the following :
TF is in minute time - I use this method as it allow us to calibrate it more precisely then regular way of Hull indicator
[Samer800] I added the trend cloud.
CODE:
CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at
#// © RafaelZioni
#https://www.tradingview.com/script/tBSMkraL-HZlog/
#indicator('HZlog ', overlay=true)
# Converted and mod by Sam4Cok@Samer800 - 10/2022
input ShowBubbles = no;
input ShowTrendCloud = yes;
input src = close;
input tf = 3600;
input threshold = 00.0017;
input TrndFactor = 200;
def timeframe = GetAggregationPeriod();
def time = timeframe;
def len = Floor(tf / (time / 60000) * 7);
def na = Double.NaN;
#z(src, len) =>
script z {
input src = close;
input len = 3600;
def n;
def s;
n = fold i = 0 to len - 1 with p do
#wr = (len - i) * len
p + (len - i) * len;
s = fold j = 0 to len - 1 with q do
q + src[j] * (len - j) * len;
def z = s / n;
plot return = z;
}
def zhma = z(src,Floor(Sqrt(len)));
def lineColor = if zhma > zhma[2] then 1 else 0;
plot zLine = zhma;
zLine.AssignValueColor(if lineColor then CreateColor(0, 230, 118) else CreateColor(255, 82, 82));
zLine.SetLineWeight(2);
def vl = zhma[0];
def ll = zhma[2];
AddCloud(vl, ll, Color.DARK_GREEN, Color.DARK_RED, yes);
#------Trend--------
def c5 = zhma;
def f2 = TrndFactor;
#//
def up = c5 - Log(f2);
def dn = c5 + Log(f2);
#//
def trend;
def hb;
def hl;
def lb;
def l1;
def c;
c = c[1] + 1;
def n = dn;
def x = up;
if c == 1 {
if x >= hb[1] {
hb = x;
hl = c5;
l1 = l1[1];
lb = lb[1];
trend = 1;
} else {
hb = hb[1];
hl = hl[1];
lb = n;
l1 = c5;
trend = -1;
}
} else {
if c > 1 {
if trend[1] > 0 {
hl = Max(hl[1], c5);
if x >= hb[1] {
hb = x;
trend = trend[1];
l1 = l1[1];
lb = lb[1];
} else {
lb = If(n < hb[1] - hb[1] * threshold, n, lb[1]);
l1 = If(n < hb[1] - hb[1] * threshold, c5, l1[1]);
trend = If(n < hb[1] - hb[1] * threshold, -1, trend[1]);
hb = hb[1];
}
} else {
l1 = Min(l1[1], c5);
if n <= lb[1] {
lb = n;
trend = trend[1];
hb = hb[1];
hl = hl[1];
} else {
hb = If(x > lb[1] + lb[1] * threshold, x, hb[1]);
hl = If(x > lb[1] + lb[1] * threshold, c5, hl[1]);
trend = If(x > lb[1] + lb[1] * threshold, 1, trend[1]);
lb = lb[1];
}
}
} else {
lb = lb[1];
hb = hb[1];
l1 = l1[1];
hl = hl[1];
trend = trend[1];
}
}
#---- Trend Cloud ----
def v = if !ShowTrendCloud then na else If(trend == 1, hb, If(trend == -1, lb, na));
AddCloud(zhma, v, Color.DARK_GREEN, Color.DARK_RED, yes);
#---- Bubbles-----
def long = trend == 1 and trend[1] == -1;
def short = trend == -1 and trend[1] == 1;
def buy = ShowBubbles and long;
def sell = ShowBubbles and short;
AddChartBubble(buy, low, "Buy", Color.GREEN, no);
AddChartBubble(sell, high, "Sell", Color.RED, yes);
#---- End Code