RSI Adaptive zones (AdaptiveRSI) For ThinkOrSwim

JP782

Active member
The author states:
This script introduces a unified mathematical framework that auto-scales oversold/overbought and support/resistance zones for any period length. It also adds true RSI candles for spotting intrabar signals.

Built on the Logit RSI foundation, this indicator converts RSI into a statistically normalized space, allowing all RSI lengths to share the same mathematical footing.
PFmWWIj.png


Here is the original Tradingview code:
https://www.tradingview.com/v/CMBt48lk/

For the new ThinkOrSwim code, you must scroll down to the next post
 
Last edited by a moderator:
Code:
declare lower;
################################
# Original script by Cwparker23 #

################################

#-----------------
#- DISCLAIMER
#-----------------
#- I am not a certified financial advisor. The content of this page/site and tools are for informational purposes only and does not constitute financial or legal advice. Under no circumstances will the author be responsible for errors or use of this tool and site. User assumes all risks.

# =========================
# Inputs
# =========================
input rsiLength = 14;
input price = close;

# Sigma levels (from video)
input zOB_Top = 2.14;
input zOB_Bot = 1.73;
input zRes_Top = 1.00;
input zRes_Bot = 0.66;
input zSup_Top = -0.66;
input zSup_Bot = -1.00;
input zOS_Top = -1.73;
input zOS_Bot = -2.14;

# =========================
# RSI
# =========================
def r = RSI(price = price, length = rsiLength);
plot RSIline = r;
RSIline.SetLineWeight(2);
RSIline.SetDefaultColor(Color.WHITE);

# =========================
# Helper: sigma -> RSI via tanh (manual)
# =========================
script SigmaToRSI {
input z = 0.0;
input len = 14;

def x = z / Sqrt(len - 1);
def e2x = Exp(2 * x);
def tanh = (e2x - 1) / (e2x + 1);

plot out = 50 + 50 * tanh;
}

# =========================
# Zones
# =========================
plot OB_Top = SigmaToRSI(zOB_Top, rsiLength);
plot OB_Bot = SigmaToRSI(zOB_Bot, rsiLength);

plot Res_Top = SigmaToRSI(zRes_Top, rsiLength);
plot Res_Bot = SigmaToRSI(zRes_Bot, rsiLength);

plot Sup_Top = SigmaToRSI(zSup_Top, rsiLength);
plot Sup_Bot = SigmaToRSI(zSup_Bot, rsiLength);

plot OS_Top = SigmaToRSI(zOS_Top, rsiLength);
plot OS_Bot = SigmaToRSI(zOS_Bot, rsiLength);

plot MidLine = 50;

# =========================
# Styling
# =========================
OB_Top.SetDefaultColor(Color.DARK_GREEN);
OB_Bot.SetDefaultColor(Color.DARK_GREEN);
OS_Top.SetDefaultColor(Color.DARK_RED);
OS_Bot.SetDefaultColor(Color.DARK_RED);

Res_Top.SetDefaultColor(Color.GRAY);
Res_Bot.SetDefaultColor(Color.GRAY);
Sup_Top.SetDefaultColor(Color.GRAY);
Sup_Bot.SetDefaultColor(Color.GRAY);

MidLine.SetDefaultColor(Color.YELLOW);
MidLine.SetLineWeight(2);

# =========================
# Clouds
# =========================
AddCloud(OB_Top, OB_Bot, Color.GREEN, Color.GREEN);
AddCloud(OS_Top, OS_Bot, Color.RED, Color.RED);

AddCloud(Res_Top, Res_Bot, Color.LIGHT_GRAY, Color.LIGHT_GRAY);
AddCloud(Sup_Top, Sup_Bot, Color.LIGHT_GRAY, Color.LIGHT_GRAY);

AddLabel(yes,
"Logit RSI Adaptive Zones | RSI(" + round(RSIline,2) + ")",
Color.GRAY
);


def h = reference RSI(price = high, length = rsiLength) ;
def l = reference RSI(price = low, length = rsiLength);
def o = reference RSI(price = open, length = rsiLength) ;
def c = reference RSI(price = close, length = rsiLength) ;



def isBull = close > open;
def isBear = close <= open;

# Bear candles
AddChart(
high = if isBear then h else Double.NaN,
low = if isBear then l else Double.NaN,
open = if isBear then o else Double.NaN,
close = if isBear then c else Double.NaN,
type = ChartType.CANDLE,
growColor = Color.RED,
fallColor = Color.GREEN,
neutralColor = Color.CURRENT
);

# Bull candles
AddChart(
high = if isBull then h else Double.NaN,
low = if isBull then l else Double.NaN,
open = if isBull then c else Double.NaN,
close = if isBull then o else Double.NaN,
type = ChartType.CANDLE,
growColor = Color.GREEN,
fallColor = Color.RED,
neutralColor = Color.CURRENT
);
 
Last edited by a moderator:

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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