RSI with Self-Adjusting Linear Regression Bands (Expo) for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
RYYElHm.png

Author Message:
RSI with Self-Adjusting Linear Regression Bands (Expo) makes use of RSI and Linear Regression to create an RSI that follows the current trend. The indicator has an upper and lower self-adjusting Linear Regression Band that act as RSI boundaries.
HOW TO USE
The indicator can be used in multiple ways, for instance, to find overbought and oversold areas. Or to identify trends as well as pullbacks in trends.

CODE:

CSS:
#//The information contained in my scripts/indicators/ideas does not constitute financial advice or a solicitation to buy or sell
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © Zeiierman
#study("RSI with Self-Adjusting Linear Regression Bands (Expo)", shorttitle="RSI + Linreg Bands (Expo)"
#//Credit to: RafaelZioni
#//Adjustment on the following code
#//https://es.tradingview.com/script/wwWnxGus-Linear-Regression-Trend-bands/
# Converted by Sam4Cok@Samer800        - 05/2023
declare lower;
input rsiSource = close;                 # "RSI Source"
input rsiLength = 14;                    # "RSI Length"
input LinearRegressionPeriod = 100;      # "Linear Regression Period"
input deviations = 2.5;                  # "Deviation"
input Overbought = 80;                   # "> Overbought"
input Oversold = 20;                     # "> Oversold"

def na = Double.NaN;
DefineGlobalColor("up", CreateColor(33,150,243));
DefineGlobalColor("dn", CreateColor(255,82,82));
#// --- Calc
def aRSI = RSI(Price = rsiSource, Length = rsiLength);
def nRSI = WMA(aRSI, 5);
def bar_index = AbsValue(CompoundValue(1, BarNumber(), 0));
def LinRegPrd = LinearRegressionPeriod;

#    closeI = (rsi[i])
def Ex = fold i = 0 to LinRegPrd with p do
         p + i;
def Ey = fold i1 = 0 to LinRegPrd with p1 do
         p1 + nRSI[i1];
def Ex2 = fold i2 = 0 to LinRegPrd with p2 do
          p2 + (i2 * i2);
def Exy = fold i3 = 0 to LinRegPrd with p3 do
          p3 + (nRSI[i3] * i3);
def ExEx = Ex * Ex;

#/slope
def slope;# = na
if Ex2!=ExEx {
    slope = ((LinRegPrd * Exy) - (Ex * Ey)) / ((LinRegPrd * Ex2) - ExEx);
    } else {
    slope = slope[1];
}

def ilinearRegression = ((Ey - slope * Ex) / LinRegPrd);
def intercept = ilinearRegression + bar_index * slope;
def deviation = power(nRSI, 2) - (intercept - slope * bar_index);

def deviationNew   = deviations * sqrt(deviation / LinRegPrd);
def startingPointY = wma((ilinearRegression + slope / LinRegPrd),5);

#// RSI_Adjust Up and Down
def adjust_up   = startingPointY + stdev(nRSI, 20);
def adjust_down = startingPointY - stdev(nRSI, 20);
 
#// Final Conditions
def a  = startingPointY-deviationNew + adjust_down/20;
def c1 = startingPointY;
def b  = startingPointY+deviationNew - adjust_up/20;

#//lineColor
def col = startingPointY > startingPointY[1];

#// Rsi Plot
plot prsi= nRSI;    # "RSI"
prsi.AssignValueColor(if col then GlobalColor("up") else GlobalColor("dn"));
prsi.SetLineWeight(2);
#// Curve Plot
def Lower_Curve = wma(a,5);
def Upper_Curve = wma(b,5);

plot LowerCurve = Lower_Curve;    # "Lower Curve"
plot MidCurve = c1;               # "Mid Curve"
plot UpperCurve = Upper_Curve;    # "Upper Curve"

LowerCurve.SetDefaultColor(Color.DARK_RED);
MidCurve.SetDefaultColor(Color.GRAY);
UpperCurve.SetDefaultColor(Color.DARK_GREEN);
MidCurve.SetStyle(Curve.SHORT_DASH);

AddCloud(if prsi>=UpperCurve then prsi else na, UpperCurve, Color.GREEN);
AddCloud(if prsi<=LowerCurve then LowerCurve else na, prsi, Color.RED);



#-- END OF CODE
 

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
426 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