# Reverse engineering RMI

#### SJP07

##### Member
VIP
Hello!

The thinkorswim platform has a reverse engineering RSI and MACD indicator and I was wondering if someone could create a reverse engineering relative momentum index indicator for the upper chart. Below is the thinkorswim RMI code. Thanks in advance!

declare lower;
input length = 20;
input momentum = 5;

Assert(momentum > 0, "'momentum' must be positive: " + momentum);

def emaInc = ExpAverage(Max(close - close[momentum], 0), length);
def emaDec = ExpAverage(Max(close[momentum] - close, 0), length);
plot RMI = if emaDec == 0 then 0 else 100 - 100 / (1 + emaInc / emaDec);
plot OverBought = 70;
plot OverSold = 30;

Solution
Reverse Relative Momentum Index (RMI)

per member: @SJP07's request:
Ruby:
``````declare lower;
input length = 19;

def alpha = 2 / (length + 1);
def coeff = 1 - alpha;
def rmi = reference RelativeMomentumIndex() ;

def re1 = coeff * rmi + rmi;
def re2 = Power(coeff, 2) * re1 + re1;
def re3 = Power(coeff, 4) * re2 + re2;
def re4 = Power(coeff, 8) * re3 + re3;
def re5 = Power(coeff, 16) * re4 + re4;
def re6 = Power(coeff, 32) * re5 + re5;
def re7 = Power(coeff, 64) * re6 + re6;
def re8 = Power(coeff, 128) * re7 + re7;

plot ReverseRMI = rmi - alpha * re8;
plot ZeroLine = 0;
plot OverBought = 70;
plot OverSold = 30;

ReverseRMI.SetDefaultColor(GetColor(5));
ZeroLine.SetDefaultColor(GetColor(7));``````

#### MerryDay

Staff member
Staff
VIP
Reverse Relative Momentum Index (RMI)

per member: @SJP07's request:
Ruby:
``````declare lower;
input length = 19;

def alpha = 2 / (length + 1);
def coeff = 1 - alpha;
def rmi = reference RelativeMomentumIndex() ;

def re1 = coeff * rmi + rmi;
def re2 = Power(coeff, 2) * re1 + re1;
def re3 = Power(coeff, 4) * re2 + re2;
def re4 = Power(coeff, 8) * re3 + re3;
def re5 = Power(coeff, 16) * re4 + re4;
def re6 = Power(coeff, 32) * re5 + re5;
def re7 = Power(coeff, 64) * re6 + re6;
def re8 = Power(coeff, 128) * re7 + re7;

plot ReverseRMI = rmi - alpha * re8;
plot ZeroLine = 0;
plot OverBought = 70;
plot OverSold = 30;

ReverseRMI.SetDefaultColor(GetColor(5));
ZeroLine.SetDefaultColor(GetColor(7));``````

#### SJP07

##### Member
VIP
Reverse Relative Momentum Index (RMI)

per member: @SJP07's request:
Ruby:
``````declare lower;
input length = 19;

def alpha = 2 / (length + 1);
def coeff = 1 - alpha;
def rmi = reference RelativeMomentumIndex() ;

def re1 = coeff * rmi + rmi;
def re2 = Power(coeff, 2) * re1 + re1;
def re3 = Power(coeff, 4) * re2 + re2;
def re4 = Power(coeff, 8) * re3 + re3;
def re5 = Power(coeff, 16) * re4 + re4;
def re6 = Power(coeff, 32) * re5 + re5;
def re7 = Power(coeff, 64) * re6 + re6;
def re8 = Power(coeff, 128) * re7 + re7;

plot ReverseRMI = rmi - alpha * re8;
plot ZeroLine = 0;
plot OverBought = 70;
plot OverSold = 30;

ReverseRMI.SetDefaultColor(GetColor(5));
ZeroLine.SetDefaultColor(GetColor(7));``````
Thanks!!! I appreciate the work you've done.

I notice that this is a lower study script. I was looking for something that's more like this, but for RMI:

#
# TD Ameritrade IP Company, Inc. (c) 2009-2021
#

input length = 14;
input price = close;
input rsiValue = 50.0;
input smoothingType = {default Wilders, EMA};

def coeff = rsiValue / (100 - rsiValue);
def chg = price - price;
def diff;
switch (smoothingType) {
case Wilders:
diff = (length - 1) * (WildersAverage(Max(-chg, 0), length) * coeff - WildersAverage(Max(chg, 0), length));
case EMA:
diff = (length - 1) * (ExpAverage(Max(-chg, 0), length) * coeff - ExpAverage(Max(chg, 0), length)) / 2;
}

def value = price + if diff >= 0 then diff else diff / coeff;
plot RevEngRSI = compoundValue(1, value, Double.NaN);

RevEngRSI.SetDefaultColor(GetColor(8)); ## 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
• 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.