# Fast/Slow Degree Oscillator For ThinkOrSwim

#### samer800

##### 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).

Code:
``````//@version=4
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
sum
//----
a = filt(src,length,fast)
b = filt(src,length,slow)
os = a - b
signal = ema(os,len)
hist = os - signal
//----
plot(hist,"Histogram",#64b5f6,2,plot.style_histogram,transp=50)
plot(os,"Oscillator",#0cb51a,2,transp=0)
plot(signal,"Signal",#e65100,2,transp=0)``````
find below.

CSS:
``````# @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"

#----Color-----
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;
thUp.SetDefaultColor(Color.GRAY);
thDn.SetDefaultColor(Color.GRAY);
thUp.SetStyle(Curve.SHORT_DASH);
thDn.SetStyle(Curve.SHORT_DASH);
#//----
#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.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Histogram.AssignValueColor(if hist>=0 then if hist>hist then GlobalColor("hiUp") else GlobalColor("Up") else
if hist<hist then GlobalColor("HiLo") else GlobalColor("Lo"));
Osc.SetDefaultColor(Color.GREEN);
Sig.SetDefaultColor(Color.RED);
Histogram.SetLineWeight(2);
Osc.SetLineWeight(2);
Sig.SetLineWeight(2);

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

#--- END CODE``````

### Not the exact question you're looking for?

87k+ Posts
274 Online ## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?