RCI with EMA&MACD test For ThinkOrSwim

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

Could you please help to convert RCI with EMA&MACD indicator from Tradingview into Thinkscript?
https://www.tradingview.com/script/eGYuz8Xi/

Ruby:
//
// @sakura10gatu
//
//@version=3

//
study(title = "RCI with EMA&MACD test", shorttitle = "RCI with EMA&MACD test")


//rci
//itv09 = input(9, "interval 18")
itv18 = input(18, "RCI 1")
itv27 = input(27, "RCI 2")
itv36 = input(36, "RCI 3")
itv45 = input(56, "RCI 4")
itv56 = input(81, "RCI 5")

src = input(close, "source")
upperband=input(title="High line[%]",defval=80,type=integer)
lowerband=input(title="Low line[%]",defval=-80,type=integer)

           
ord(seq, idx, itv) =>
    p = seq[idx]
    o = 1
    for i = 0 to itv - 1
        if p < seq[i]
            o := o + 1
    o

d(itv) =>
    sum = 0.0
    for i = 0 to itv - 1
        sum := sum + pow((i + 1) - ord(src, i, itv), 2)
    sum

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

hline(upperband,color=gray,linestyle=dashed)
hline(lowerband,color=gray,linestyle=dashed)

//plot( rci(itv09), color=orange, style=line, title="rci09", linewidth=1)
plot( rci(itv18), color=red, style=line, title="rci1", linewidth=1)
plot( rci(itv27), color=blue, style=line, title="rci2", linewidth=1)
plot( rci(itv36), color=teal, style=line, title="rci3", linewidth=1)
plot( rci(itv45), color=green, style=line, title="rci4", linewidth=1)
plot( rci(itv56), color=navy, style=line, title="rci5", linewidth=2)
check the below.

CSS:
#//@// @sakura10gatu
# study(title = "RCI with EMA&MACD test", shorttitle = "RCI with EMA&MACD test")
# Converted by Sam4Cok@Samer800 - UseThinkScript.com member request - 12/2023
declare lower;
input upperBand = 80.0;
input lowerBand = -80.0;
input source = close;#, 'source')
input itv18 = 18; #, "RCI 1")
input itv27 = 27; #, "RCI 2")
input itv36 = 36; #, "RCI 3")
input itv45 = 56; #, "RCI 4")
input itv56 = 81; #, "RCI 5")


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 rci1 = rci(source, itv18);
def rci2 = rci(source, itv27);
def rci3 = rci(source, itv36);
def rci4 = rci(source, itv45);
def rci5 = rci(source, itv56);

plot rciLine1 = rci1;     # "RCI 1"
plot rciLine2 = rci2;     # "RCI 2"
plot rciLine3 = rci3;     # "RCI 3"
plot rciLine4 = rci4;     # "RCI 4"
plot rciLine5 = rci5;     # "RCI 5"

rciLine5.SetLineWeight(2);
rciLine1.SetDefaultColor(Color.RED);
rciLine2.SetDefaultColor(Color.CYAN);
rciLine3.SetDefaultColor(Color.VIOLET);
rciLine4.SetDefaultColor(Color.GREEN);
rciLine5.SetDefaultColor(Color.PLUM);

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

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

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


#-- END of CODE
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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