Fast/Slow Degree Oscillator For ThinkOrSwim

Join useThinkScript to post your question to a community of 21,000+ developers and traders.


Well-known member
I'm getting stuck on the second for loop (for function F, ThinkOrSwim throws an error saying that no variable i exists, despite being declared in the loop).


study("Fast/Slow Degree Oscillator","FSDO",overlay=false)
length = input(100),fast = input(3),slow = input(2),len = input(14,"Signal Length"),src = input(close)
f(x,d) =>
    sum = 0.,pi = atan(1)*4
    for i = 1 to d
        b = 1/i * sin(x*i*pi)
        sum := sum + b
    pol = x*x + iff(d == 0,0,sum)
filt(x,p,d) =>
    sum = 0.
    for i = 1 to p
        w = f(i/p,d) - f((i-1)/p,d)
        sum := sum + x[i-1] * w
a = filt(src,length,fast)
b = filt(src,length,slow)
os = a - b
signal = ema(os,len)
hist = os - signal
find below.

# @alexgrover
#study("Fast/Slow Degree Oscillator","FSDO",overlay=false)
# converted and mod by [email protected]    - 03/2023

Declare lower;
input BarColor = yes;
input threshold = 0.5;
input src = close;
input length = 100;
input fastLength = 3;
input slowLength = 2;
input SignalLength = 14;      # "Signal Length"

DefineGlobalColor("hiUp" , CreateColor(0,216,216));
DefineGlobalColor("Up"   , CreateColor(0,89,89));
DefineGlobalColor("HiLo" , CreateColor(216,0,216));
DefineGlobalColor("Lo"   , CreateColor(89,0,89));
def na = Double.NaN;
def last = isNaN(close);
plot thUp = if last then na else threshold;
plot thDn = if last then na else - threshold;
#filt(x,p,d) =>
Script filt {
input x = close;
input p = 100;
input d = 3;
    def pi = Double.Pi;#atan(1)*4;
    def sum;# = 0.
        sum = fold j = 1 to p + 1 with r do
              r + (GetValue(x, j-1) *
               ((j*j/p/p + (fold i2 = 1 to d + 1 with q2 do
                           q2 +  1/i2 * sin(j/p * i2 * pi)) -
               ((j-1)*(j-1)/p /p + (fold i = 1 to d + 1 with q do
                                      q  +  1/i  * sin((j-1)/p * i * pi))))));
    plot out = sum;
def a = filt(src,length,fastLength);
def b = filt(src,length,slowLength);
def os = a - b;
def signal = ExpAverage(os,SignalLength);
def hist = os - signal;
plot Osc = os;            # "Oscillator"
plot Sig = signal;        # "Signal"
plot Histogram = hist;    # "Histogram"

Histogram.AssignValueColor(if hist>=0 then if hist>hist[1] then GlobalColor("hiUp") else GlobalColor("Up") else
                                           if hist<hist[1] then GlobalColor("HiLo") else GlobalColor("Lo"));

#-- Bar Color
AssignPriceColor(if !BarColor then Color.CURRENT else
                 if os>=thUp then if signal>signal[1] then GlobalColor("hiUp") else GlobalColor("Up") else
                 if os<=thDn then  if signal<signal[1] then GlobalColor("HiLo") else GlobalColor("Lo") else Color.GRAY);


Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
274 Online
Create Post

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.