# RCI with Stochastic For ThinkOrSwim

#### Lucygoldenliu

##### New member
I have conversion issue of thinkscript when I converted following Stochastic indicator for thinkorswim platform. Could you please help me to correct the errors.

Last edited by a moderator:
I have conversion issue of thinkscript when I converted following Stochastic indicator for thinkorswim platform. Could you please help me to correct the errors.

Ruby:
``````//@version=5
indicator("Stochastic", shorttitle="Stochastic", overlay = false)

itvs = input(9, 'short interval')
itvm = input(16, 'middle interval')
itvl = input(48, 'long interval')
itvMul = input(9, 'Multi interval')

src5t = input(close, 'source')

resCustom = input.timeframe(title='TimeFrame', defval='240')
res5t = resCustom

ord(seq, idx, itv) =>
p = seq[idx]
o = 1
s = 0
for i = 0 to itv - 1 by 1
if p < seq[i]
o += 1
o
else
if p == seq[i]
s += 1
o + (s - 1) / 2.0
o

d(itv) =>
sum = 0.0
for i = 0 to itv - 1 by 1
sum += math.pow(i + 1 - ord(src5t, i, itv), 2)
sum
sum

rci(itv) =>
(1.0 - 6.0 * d(itv) / (itv * (itv * itv - 1.0))) * 100.0

outRCI = request.security(syminfo.tickerid, res5t, rci(itvMul))

plot(((rci(itvs) + 100)/200)*100, title="RCI short", color=color.yellow, linewidth=2)
plot(((rci(itvm) + 100)/200)*100, title="RCI middle", color=color.red, linewidth =4)
plot(((rci(itvl) + 100)/200)*100, title="RCI long", color=color.blue, linewidth =5)
plot(((outRCI + 100)/200)*100, title="RCI S1", linewidth=3, color=#FFFFFF)``````

Ruby:
``````# Superior Traffic Candles
declare lower;

input itvs = 9;
input itvm = 16;
input itvl = 48;
input itvMul = 9;
input src5t = close;

def resCustom = 240;
def res5t = resCustom;

def ord(seq, idx, itv) {
def p = seq[idx];
def o = 1;
def s = 0;
for (int i = 0; i < itv; i++) {
if (p < seq[i]) {
o += 1;
} else {
if (p == seq[i]) {
s += 1;
}
}
}
o + (s - 1) / 2.0;
}

def d(itv) {
def sum = 0.0;
for (int i = 0; i < itv; i++) {
sum += Power(i + 1 - ord(src5t, i, itv), 2);
}
sum;
}

def rci(itv) {
(1.0 - 6.0 * d(itv) / (itv * (itv * itv - 1.0))) * 100.0;
}

def outRCI = rci(itvMul);

plot(((rci(itvs) + 100) / 200) * 100, "RCI short", color = color.yellow, linewidth = 2);
plot(((rci(itvm) + 100) / 200) * 100, "RCI middle", color = color.red, linewidth = 4);
plot(((rci(itvl) + 100) / 200) * 100, "RCI long", color = color.blue, linewidth = 5);
plot(((outRCI + 100) / 200) * 100, "RCI S1", color = color.white, linewidth = 3);``````
check the below

CSS:
``````#//@// @sakura10gatu
#indicator("RCI with Stochastic", shorttitle="Stochastic", overlay = false)
# Converted by Sam4Cok@Samer800 - UseThinkScript.com member request
declare lower;
input over_bought = 80.0;
input over_sold = 20.0;
input source = FundamentalType.CLOSE;#, 'source')
input shortInterval = 9;#, 'short interval')
input middleInterval = 16;#, 'middle interval')
input longInterval = 48;#, 'long interval')
input htfInterval = 9;#, 'Multi interval')
input htfAggregation = AggregationPeriod.FOUR_HOURS;#ame(title='TimeFrame', defval='240')

def src = Fundamental(FundamentalType = source);
def htfSrc = Fundamental(FundamentalType = source, Period = htfAggregation);

Script rci {
input src5t = close;
input itv = 10;
def sum = fold i = 0 to itv with q do
q + Sqr(i + 1 - (fold j = 0 to itv with o=1 do
if src5t[i] < src5t[j] then o + 1 else o));
def rci = (1.0 - 6.0 * sum / (itv * (itv * itv - 1.0))) * 100.0;
plot out = rci;
}
def shortRCI = rci(src, shortInterval);
def MiddRCI = rci(src, middleInterval);
def longRCI = rci(src, longInterval);
def s1RCI = rci(htfSrc, htfInterval);

plot rciShort = ((shortRCI + 100)/200)*100;   # "RCI short", color=color.yellow, linewidth=2)
plot rciMidd = ((MiddRCI + 100)/200)*100;     # "RCI middle", color=color.red, linewidth =4)
plot rciLong = ((longRCI + 100)/200)*100;     # "RCI long", color=color.blue, linewidth =5)
plot rciS1 = ((s1RCI + 100)/200)*100;         # "RCI S1", linewidth=3

rciMidd.SetLineWeight(2);
rciLong.SetLineWeight(3);
rciS1.SetLineWeight(2);
rciShort.SetDefaultColor(Color.YELLOW);
rciMidd.SetDefaultColor(Color.MAGENTA);
rciLong.SetDefaultColor(Color.CYAN);
rciS1.SetDefaultColor(Color.WHITE);

plot midLine = 50;
midLine.SetDefaultColor(Color.GRAY);
midLine.SetStyle(Curve.SHORT_DASH);

plot overbought = over_bought;
overbought.SetDefaultColor(Color.DARK_RED);

plot oversold = over_sold;
oversold.SetDefaultColor(Color.DARK_GREEN);

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

Can you create ascanner for this please?

87k+ Posts
279 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?