Author Message:
The HyperTrend indicator aims to provide a real-time estimate of an underlying linear trend in the price. Support and resistance extremities are constructed from this estimate which can provide trade opportunities within the overall trend.
More details: https://www.tradingview.com/v/Bcufg8oX/
CODE:
CSS:
#// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
#https://www.tradingview.com/v/Bcufg8oX/
#// © LuxAlgo
#indicator("HyperTrend [LuxAlgo]", "LuxAlgo - HyperTrend", overlay = true)
# converted and mod by Sam4Cok@Samer800 - 07/2023
#//Settings
input useChartTimeframe = {default"Yes", "No"};
input manualTimeframe = AggregationPeriod.FIFTEEN_MIN;
input source = close;
input atrLength = 200;
input multiplicativeFactor = 5; # 'Multiplicative Factor'
input slope = 14; # 'Slope'
input showWidthBand = yes;
input widthPercentage = 80; # 'Width %'
def na = Double.NaN;
def width = widthPercentage / 100;
DefineGlobalColor("upL", CreateColor(0,137,123));
DefineGlobalColor("dnL", CreateColor(255,82,82));
DefineGlobalColor("up", CreateColor(5,50,86));
DefineGlobalColor("dn", CreateColor(77,8,7));
#-- MTF
def src;def hi; def lo;
Switch (useChartTimeframe) {
case "Yes" :
src = source;
hi = high;
lo = low;
case "No" :
src = close(Period=manualTimeframe);
hi = high(Period=manualTimeframe);
lo = low(Period=manualTimeframe);
}
#//Calculation
def tr = TrueRange(hi, src, lo);
def nATR = WildersAverage(tr, atrLength);
#def nATR = atr(LENGTH = atrLength);
def atr = if isNaN(nATR) then (high - low) else nATR * multiplicativeFactor;
def hold;
def os;
def avg;
def absAvg = AbsValue(src - avg[1]);
def srcAvg = (src + avg[1]) / 2;
def osTrend = os[1] * (hold[1] / multiplicativeFactor / slope);
avg = CompoundValue(1, if absAvg > atr then srcAvg else avg[1] + osTrend, src);
def avgChange = avg - avg[1];
def varOs = sign(avgChange);
os = if isNaN(varOs) then 1 else varOs;
def osChange = os != os[1];
hold = if osChange then atr else hold[1];
def upper = avg + width * hold;
def lower = avg - width * hold;
#//Plots
def css = os == 1;
def plot_upper = if osChange or !showWidthBand then na else upper;
plot plot_avg = if osChange then na else avg;
def plot_lower = if osChange or !showWidthBand then na else lower;
plot_avg.AssignValueColor(if css then GlobalColor("upL") else GlobalColor("dnL"));
def upAvg = (plot_upper + plot_avg) / 2;
def dnAvg = (plot_lower + plot_avg) / 2;
AddCloud(plot_upper, plot_avg, GlobalColor("dn"), GlobalColor("dn"), yes);
AddCloud(plot_avg, plot_lower, GlobalColor("up"), GlobalColor("up"), yes);
AddCloud(plot_upper, upAvg, GlobalColor("dn"), GlobalColor("dn"), no);
AddCloud(dnAvg, plot_lower, GlobalColor("up"), GlobalColor("up"), no);
#AddChartBubble(css and !css[1], low, "B", Color.GREEN, no);
#AddChartBubble(!css and css[1], high, "S", Color.RED, yes);
#-- END Of Code