ATR-Adaptive, Smoothed Laguerre RSI [Loxx] For ThinkOrSwim

Lerning2Code

New member
ki3x471.png

ATR-Adaptive, Smoothed Laguerre RSI is an adaptive Laguerre RSI indicator with smoothing to reduce noise
Instead of using fixed periods for Laguerre RSI calculation, this indicator uses an ATR (average True Range) adapting method to adjust the calculation period. This makes the RSI more responsive in some periods (periods of high volatility), and smoother in order periods (periods of low volatility).

https://www.tradingview.com/script/0tppbG2J-ATR-Adaptive-Smoothed-Laguerre-RSI-Loxx/

Please convert, I think an RSI Laguerre that is filtered by ATR would be helpful for adjusting to whichever market regime we may be in
 
Last edited by a moderator:

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

https://www.tradingview.com/script/0tppbG2J-ATR-Adaptive-Smoothed-Laguerre-RSI-Loxx/

Please convert, I think an RSI Laguerre that is filtered by ATR would be helpful for adjusting to whichever market regime we may be in
check the below:

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https:/
#// © loxx
#indicator("ATR-Adaptive, Smoothed Laguerre RSI [Loxx]",  shorttitle = "ATRASLRSI [Loxx]"
# Converted by Sam4Cok@Samer800    - 01/2024
Declare lower;

input Source = Close;
input SmoothingPeriod = 5;#, "Source Smoothing Period"
input atrLength = 15;#, "ATR Period"
input UpperBoundary = 85;#, "Upper Boundary"
input LowerBoundary = 15;#, "Lower Boundary"
input colorBars = no;#, "Color bars?"

def na = Double.NaN;
def last = isNaN(close);

Script lagfiltosc {
input src = close;
input per = 15;
    def _gamma = 1.0 - 10.0 / (per + 9.0);
    def L0 = CompoundValue(1, (1 - _gamma) * src + _gamma * L0[1], 0);
    def L1 = CompoundValue(1, -_gamma * L0 + L0[1] + _gamma * L1[1], 0);
    def L2 = CompoundValue(1, -_gamma * L1 + L1[1] + _gamma * L2[1], 0);
    def L3 = CompoundValue(1, -_gamma * L2 + L2[1] + _gamma * L3[1], 0);
    def CU1 = if (L0 >= L1) then L0 - L1 else 0;
    def CD1 = if (L0 >= L1) then 0 else L1 - L0;
    def CU2 = if (L1 >= L2) then CU1 + L1 - L2 else CU1;
    def CD2 = if (L1 >= L2) then CD1 else CD1 + L2 - L1;
    def CU = if (L2 >= L3) then CU2 + L2 - L3 else CU2;
    def CD = if (L2 >= L3) then CD2 else CD2 + L3 - L2;
    def out = if (CU + CD != 0) then CU / (CU + CD) else 0;
    plot return = out;
}

def atr = atr(Length = atrLength);
def prevMax = fold j = 2 to atrLength + 1 with p =atr do
    if p < atr[j] then atr[j] else p;
def prevMin = fold k = 2 to atrLength + 1 with q =atr do
    if q > atr[k] then atr[k] else q;

def srcout = ExpAverage(Source, SmoothingPeriod);
def _max = if prevMax > atr then prevMax else atr;
def _min = if prevMin < atr then prevMin else atr;
def _coeff = if (_min != _max) then 1 - (atr - _min) / (_max - _min) else 0.5;

def val = lagfiltosc(srcout, atrLength * (_coeff + 0.75));
def valc = if (val > UpperBoundary/100) then 1 else
           if (val < LowerBoundary/100) then 2 else 0;

plot plval = val * 100;
plval.SetLineWeight(2);
plval.AssignValueColor(if valc == 1 then Color.GREEN else
                       if valc == 2 then Color.RED else color.GRAY);
plot plup = if last then na else UpperBoundary;
plot pldn = if last then na else LowerBoundary;
plup.SetStyle(Curve.SHORT_DASH);
pldn.SetStyle(Curve.SHORT_DASH);
plup.SetDefaultColor(Color.GRAY);
pldn.SetDefaultColor(Color.GRAY);

#-- cloud & bar color
AddCloud(if valc == 1 then plval else na, plup, Color.GREEN);
AddCloud(if valc == 2 then pldn else na, plval, Color.RED);

AssignPriceColor(if !colorbars then Color.CURRENT else
                 if valc == 1 then Color.GREEN else
                 if valc == 2 then Color.RED else Color.GRAY);

#-- END of CODE
 
check the below:

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https:/
#// © loxx
#indicator("ATR-Adaptive, Smoothed Laguerre RSI [Loxx]",  shorttitle = "ATRASLRSI [Loxx]"
# Converted by Sam4Cok@Samer800    - 01/2024
Declare lower;

input Source = Close;
input SmoothingPeriod = 5;#, "Source Smoothing Period"
input atrLength = 15;#, "ATR Period"
input UpperBoundary = 85;#, "Upper Boundary"
input LowerBoundary = 15;#, "Lower Boundary"
input colorBars = no;#, "Color bars?"

def na = Double.NaN;
def last = isNaN(close);

Script lagfiltosc {
input src = close;
input per = 15;
    def _gamma = 1.0 - 10.0 / (per + 9.0);
    def L0 = CompoundValue(1, (1 - _gamma) * src + _gamma * L0[1], 0);
    def L1 = CompoundValue(1, -_gamma * L0 + L0[1] + _gamma * L1[1], 0);
    def L2 = CompoundValue(1, -_gamma * L1 + L1[1] + _gamma * L2[1], 0);
    def L3 = CompoundValue(1, -_gamma * L2 + L2[1] + _gamma * L3[1], 0);
    def CU1 = if (L0 >= L1) then L0 - L1 else 0;
    def CD1 = if (L0 >= L1) then 0 else L1 - L0;
    def CU2 = if (L1 >= L2) then CU1 + L1 - L2 else CU1;
    def CD2 = if (L1 >= L2) then CD1 else CD1 + L2 - L1;
    def CU = if (L2 >= L3) then CU2 + L2 - L3 else CU2;
    def CD = if (L2 >= L3) then CD2 else CD2 + L3 - L2;
    def out = if (CU + CD != 0) then CU / (CU + CD) else 0;
    plot return = out;
}

def atr = atr(Length = atrLength);
def prevMax = fold j = 2 to atrLength + 1 with p =atr do
    if p < atr[j] then atr[j] else p;
def prevMin = fold k = 2 to atrLength + 1 with q =atr do
    if q > atr[k] then atr[k] else q;

def srcout = ExpAverage(Source, SmoothingPeriod);
def _max = if prevMax > atr then prevMax else atr;
def _min = if prevMin < atr then prevMin else atr;
def _coeff = if (_min != _max) then 1 - (atr - _min) / (_max - _min) else 0.5;

def val = lagfiltosc(srcout, atrLength * (_coeff + 0.75));
def valc = if (val > UpperBoundary/100) then 1 else
           if (val < LowerBoundary/100) then 2 else 0;

plot plval = val * 100;
plval.SetLineWeight(2);
plval.AssignValueColor(if valc == 1 then Color.GREEN else
                       if valc == 2 then Color.RED else color.GRAY);
plot plup = if last then na else UpperBoundary;
plot pldn = if last then na else LowerBoundary;
plup.SetStyle(Curve.SHORT_DASH);
pldn.SetStyle(Curve.SHORT_DASH);
plup.SetDefaultColor(Color.GRAY);
pldn.SetDefaultColor(Color.GRAY);

#-- cloud & bar color
AddCloud(if valc == 1 then plval else na, plup, Color.GREEN);
AddCloud(if valc == 2 then pldn else na, plval, Color.RED);

AssignPriceColor(if !colorbars then Color.CURRENT else
                 if valc == 1 then Color.GREEN else
                 if valc == 2 then Color.RED else Color.GRAY);

#-- END of CODE
Thank you so much!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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