Chebyshev Filter For ThinkOrSwim

cando13579

Member
VIP
The author states: The Chebyshev filters are powerful smoothing techniques that can be used in technical analysis to remove noise from time series data. They offer a sharper transition between the passband and the stopband compared to other filter types, which helps in preserving the essential features of the data while effectively reducing noise.

kNOFPcR.png


Here is the original Tradingview code:
https://www.tradingview.com/script/wn1YfGVm-Chebyshev-type-I-and-II-Filter/

The new ThinkOrSwim code can be found in the next post.
 
Last edited by a moderator:
check the below:

CSS:
#// 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
 

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
234 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