Reverse Engineering RSI

TraderJ

New member
Hello, I'm new to the forum. I base a lot of my trades off extended RSI levels ( to the up or downside ) when they come in contact with Fibonacci levels. I scale in and try to average my price as close to the current price when the RSI recovers (returns above/below 30 or 70). Right now I am guessing how much farther the price will move before the reversal. Does anyone know how to calculate for example: If the RSI went from 30 down to 12, the price of the stock at 30 RSI is $20, what would the price be when the RSI is 12? I'm trying to make my entries more precise. Does anyone know how to calculate this. I would love to have a chart that calculates this in TOS. Thanks in advance
 
I guess to simplify the question, has anyone created a RS (relative strength) type average for real time use. RS = (Avg Gain)/(Avg Loss) for 14 day period on a stock.
 

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

I believe I found the average to use to covert from a scale of 0 to 100 to the real price. I have averaging to points and dividing by 100 and multiplying the unknown distance on the RSI. It seems to be getting me close to the conversion. Here is the average i'm using which I found in the stock TOS RSI code:

Code:
declare lower;

input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI = 50 * (ChgRatio + 1);

plot TC = TotChgAvg / 100;

Any input would be appreciated or tell me to F off. Thanks
 
adding upper/lower band might help per your usage (code not mine)

Code:
#RevesedEngineeredRSI_Upper_Lowerbands mod by LAR
input length = 11;
input price = close;
input rsiValue = 65.0;
input smoothingType = {default Wilders, EMA};

def coeff = rsiValue / (100 - rsiValue);
def chg = price - price[1];
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[1], Double.NaN);

RevEngRSI.SetDefaultColor(Color.BLACK);

input rsiValue1 = 35.0;

def coeff1 = rsiValue1 / (100 - rsiValue1);
def chg1 = price - price[1];
def diff1;
switch (smoothingType) {
case Wilders:
    diff1 =  (length - 1) * (WildersAverage(Max(-chg1, 0), length) * coeff1 - WildersAverage(Max(chg1, 0), length));
case EMA:
    diff1 =  (length - 1) * (ExpAverage(Max(-chg1, 0), length) * coeff1 - ExpAverage(Max(chg1, 0), length)) / 2;
}

def value1 = price + if diff1 >= 0 then diff1 else diff1 / coeff1;
plot RevEngRSI1 = compoundValue(1, value1[1], Double.NaN);

RevEngRSI1.SetDefaultColor(Color.BLACK);

input rsiValue2 = 50.0;
input smoothingType2 = {default Wilders, EMA};

def coeff2 = rsiValue2 / (100 - rsiValue2);
def chg2 = price - price[1];
def diff2;
switch (smoothingType2) {
case Wilders:
    diff2 =  (length - 1) * (WildersAverage(Max(-chg2, 0), length) * coeff2 - WildersAverage(Max(chg2, 0), length));
case EMA:
    diff2 =  (length - 1) * (ExpAverage(Max(-chg2, 0), length) * coeff2 - ExpAverage(Max(chg2, 0), length)) / 2;
}

def value2 = price + if diff2 >= 0 then diff2 else diff2 / coeff2;
plot RevEngRSI2 = compoundValue(1, value2[1], Double.NaN);

RevEngRSI2.SetDefaultColor(Color.BLACK);

addcloud(revEngRSI,revEngRSI2,color.green,color.green);
AddCloud(revEngRSI2, data2 = RevEngRSI1, color2 = Color.red, color1 = Color.red);
 
I wanted to know if anyone has an indicator which shows, if the rsi for example is 50 and the stock price is $100 how will i be able to tell the price of the stock when it higher. for instance if the is a pullback from 50 to 40 what would be the price of the stock when it would it goes back to 50. hope you can understand what i mean

Quote Reply
 
I think you are looking for the built-in TOS indicator called ReverseEngineeringRSI. Pick the number you want to know the price the next bar would need to be to hit the number you are looking for.
 
I guess to simplify the question, has anyone created a RS (relative strength) type average for real time use. RS = (Avg Gain)/(Avg Loss) for 14 day period on a stock.
I use a 3-period RSI of HLC3 to day trade futures with mostly tick charts- works great, also solid with day charts
 
with /nq, I start with 750 and modiy to 500 or 1000 depending on volume. Im looking for a smooth rolling pattern and adjust accordingly. I find it helpful to add a centerline and watch for crossovers to enter/exit trades. My study script:
Ruby:
declare lower;
input audioalert = yes;
input length = 3;
input over_Bought = 75;
input over_Sold = 25;
input price = hlc3;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;

#Calculate 3-bar RSI
def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
plot mid = 50;
mid.SetLineWeight(2);
mid.setDefaultColor(createcolor(150,50,0));

plot RSI = 50 * (ChgRatio + 1);
def OverSold = over_Sold;
def OverBought = over_Bought;
#plot UpSignal = if RSI crosses above OverSold then OverSold else Double.NaN;
#plot DownSignal = if RSI crosses below OverBought then OverBought else Double.NaN;
plot UpSignal = if RSI crosses above mid then OverSold else Double.NaN;
plot DownSignal = if RSI crosses below mid then OverBought else Double.NaN;


RSI.SetDefaultColor(Color.GRAY);

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);
UpSignal.SetDefaultColor(Color.blue);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
upSignal.setLineWeight(3);
DownSignal.SetDefaultColor(Color.dark_red);
downSignal.setLineWeight(3);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

AddCloud(RSI, OverBought, Color.BLUE, Color.LIGHT_GRAY);
AddCloud(OverSold, RSI, Color.DARK_RED, Color.LIGHT_GRAY);

#ALERTS
alert(audioalert and rsi crosses overbought, "",alert.bar, sound.ding);
alert(audioalert and rsi crosses oversold, "",alert.bar, sound.ding);
alert(audioalert and rsi crosses mid, "",alert.BAR, sound.chimes);
 
Last edited by a moderator:
Hello,

Not sure if reverse engineer is the right way to describe this.

A partial code of the RSI is below. I am trying to find a way to find the close price if RSI is an input, i.e., if RSI is at 20 from now with length = 14, what would close price be, and have it plotted.

So based on the below, if RSI = 20, then ChgRatio = -0.6. And let's say if NetChgAvg or TotChgAvg is a constant input, then we can solve for other. And if both NetChgAvg and TotChgAvg are known, can 'price' be solved?

Code:
input length = 14;
input price = close;
input averageType = AverageType.WILDERS;

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

plot RSI = 50 * (ChgRatio + 1);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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