#// Indicator for TOS
#// © peacefulLizard50262
#indicator("Chebyshev type I and II", "CHBV", true)
# Converted by Sam4Cok@Samer800 - 12/2024
input timeframe = AggregationPeriod.MIN;
input Source = FundamentalType.CLOSE; #, "Source"
input length = 50; #, 'Length'
input ripple = 7.5; #, "Ripple"
input ChebyshevType = {Default "I", "II"}; # "Style"
def na = Double.NaN;
def last = isNaN(close);
def cap = GetAggregationPeriod();
def tf = Max(cap, timeframe);
Script fractional_complement {
input x = 7.5;
def ripple = (10 - ((9/10 * x) % 9)) * power(10, -1 - floor(x/10));
plot out = ripple;
}
#// Custom cosh function
Script cosh {
input x = 1;
def cosh = (exp(x) + exp(-x)) / 2;
plot out = cosh;
}
#// Custom acosh function
Script acosh {
input x = 1;
def acosh = if x < 1 then 0 else log(x + sqrt(x * x - 1));
plot out = acosh;
}
#// Custom sinh function
Script sinh {
input x = 1;
def sinh = (exp(x) - exp(-x)) / 2;
plot out = sinh;
}
#// Custom asinh function
Script asinh {
input x = 1;
def asinh = log(x + sqrt(x * x + 1));
plot out = asinh;
}
#// Custom inverse tangent function
Script atan {
input x = 1;
def atan = Double.Pi / 2 - atan(1 / x);
plot out = atan;
}
def fractional_complement = fractional_complement(ripple);
#chebyshev(float src, float len, float ripple, string style) =>
def a; def b; def g;
Switch (ChebyshevType) {
Case "II" :
a = cosh(1 / length * acosh(1 / fractional_complement));
b = sinh(1 / length * asinh(fractional_complement));
g = (a - b) / (a + b);
Default :
a = cosh(1 / length * acosh(1 / (1 - fractional_complement)));
b = sinh(1 / length * asinh(1 / fractional_complement));
g = (a - b) / (a + b);
}
def chebyshev = if isNaN(chebyshev[1]) then Fundamental(Source, period = tf) else
if !chebyshev[1] then Fundamental(Source, period = tf) else
(1 - g) * Fundamental(Source, period = tf) + g * chebyshev[1];
plot CHBV = if !last and chebyshev then chebyshev else na;
CHBV.SetLineWeight(2);
CHBV.SetDefaultColor(Color.CYAN);
#-- END of CODE