Constance Brown Altered RSI For ThinkOrSwim

vaghmar

New member
Author states:
Welles Wilder created the RSI momentum oscillator in the 1970s. It is a momentum oscillator that ranges from 0 to 100. The traditional idea is to buy when the oscillator is below 30 and to sell when it is above 70. However, this strategy often only catches extreme moves and misses majority of the trend.

In comes Constance Brown RSI . She theorized that in an uptrend, the buy zone exists when RSI is between 40 and 50. The sell zone in an uptrend exists between 80 and 90. In a downtrend, the sell zone exists between 55 and 65. The buy zone in a downtrend exists between 20 and 30.

I have added a moving average feature to determine trend. When the short trend is above the long trend, it is considered an uptrend. It is in a downtrend otherwise. Using short length moving averages will often produce a lot of false signals. I recommend using the 50 and 100 as they will produce less noise.

There will be times when the oscillator breaks beyond the ranges described (for ex: seeing a reading below 40 in an uptrend). This tends to happen in periods of high volatility . Refer to the traditional RSI rules in such cases.
su8720e.png


I request the conversion experts on this esteemed website to see if conversion to the following RSI tradingview script is possible.
please find time to evaluate it to see if this conversion is attainable. If yes, please find time to help me out. Thanks in advance.
https://www.tradingview.com/script/s3mrd1tU-Constance-Brown-RSI/
 
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/s3mrd1tU-Constance-Brown-RSI/

I request the conversion experts on this esteemed website to see if conversion to the following RSI tradingview script is possible.

I especially request Samar800 (Sam4Cok) member to please find time to evaluate it to see if this conversion is attainable. If yes, please find time to help me out. Thanks in advance.
https://www.tradingview.com/script/s3mrd1tU-Constance-Brown-RSI/
check the below with additional features.

CSS:
#/ This source code is subject to the terms of the Mozilla Public License 2.0 at https://mo
#// © Decam9
#study(title = "Constance Brown Altered RSI", shorttitle = "CB Altered RSI", overlay = false)
#Converted and mod by Sam4Cok@Samer800    - 01/2024
Declare lower;
#//Plot the RSI
input selectRSI = {default Regular, Slow, Rapid, Harris, "Ehlers Smoothed", RSX};
input rsiSource = close;    # "RSI Source"
input rsiLength = 14;       # "RSI Length"
input signalLength = 9;
input ShortTrendLength = 100;
input LongTrendLength = 200;

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

#// rsx RSI
script rsi_rsx {
input src = close;
input len = 14;
    def nRSI = rsi(Price=src, Length=len);
    def src_out = 100 * src;
    def mom0 = (src_out-src_out[1]);
    def moa0 = AbsValue(mom0);
    def Kg = 3 / (len + 2.0);
    def Hg = 1 - Kg;
    def f28 = CompoundValue(1, Kg * mom0 + Hg * f28[1], nRSI);
    def f30 = CompoundValue(1, Hg * f30[1] + Kg * f28, nRSI);
    def mom1 = f28 * 1.5 - f30 * 0.5;
    def f38 = CompoundValue(1, Hg * f38[1] + Kg * mom1, nRSI);
    def f40 = CompoundValue(1, Kg * f38 + Hg * f40[1], nRSI);
    def mom2 = f38 * 1.5 - f40 * 0.5;
    def f48 = CompoundValue(1, Hg * f48[1] + Kg * mom2, nRSI);
    def f50 = CompoundValue(1, Kg * f48 + Hg * f50[1],  nRSI);
    def mom_out = f48 * 1.5 - f50 * 0.5;
    def f58 = CompoundValue(1, Hg * f58[1] + Kg * moa0, nRSI);
    def f60 = CompoundValue(1, Kg * f58 + Hg * f60[1], nRSI);
    def moa1 = f58 * 1.5 - f60 * 0.5;
    def f68 = CompoundValue(1, Hg * f68[1] + Kg * moa1, nRSI);
    def f70 = CompoundValue(1, Kg * f68 + Hg * f70[1], nRSI);
    def moa2 = f68 * 1.5 - f70 * 0.5;
    def f78 = CompoundValue(1, Hg * f78[1] + Kg * moa2, nRSI);
    def f80 = CompoundValue(1, Kg * f78 + Hg * f80[1], nRSI);
    def moa_out = f78 * 1.5 - f80 * 0.5;
    def rsiout = max(min((mom_out / moa_out + 1.0) * 50.0, 100), 0);
    plot rsx = rsiout;
}

#// Slow RSI
script rsi_slo {
    input src = close;
    input per = 14;
    def _rsival;
    def nRSI = rsi(Price=src,Length= per);
    def up = fold k = 0 to per with p do
                if (src[k] - GetValue(src, k + 1)) > 0 then p + (src[k] - GetValue(src, k + 1)) else p;
    def dn = fold i = 0 to per with q do
                if (src[i] - GetValue(src, i + 1)) > 0 then q else q - (src[i] - GetValue(src, i + 1));
    if (up + dn == 0) {
        _rsival = CompoundValue(1, _rsival[1] + (1 / Max(per, 1)) * (50 - _rsival[1]), nRSI);
    } else {
        _rsival = CompoundValue(1, _rsival[1] + (1 / Max(per, 1)) * (100 * up / (up + dn) - _rsival[1]), nRSI);
    }
    plot out = _rsival;
}
# // Rapid RSI
script rsi_rap {
    input src = close;
    input per = 14;
    def sump = fold k = 0 to per with p do
                if (src[k] - GetValue(src, k + 1)) > 0 then p + (src[k] - GetValue(src, k + 1)) else p;
    def sumn = fold i = 0 to per with q do
                if (src[i] - GetValue(src, i + 1)) < 0 then q - (src[i] - GetValue(src, i + 1)) else q;
    def out = if sumn > 0 then 100 - 100 / (1 + sump / sumn) else 50;
    plot rsi_cut = out;
}
#// Harris RSI
script rsi_har {
    input src = close;
    input per = 14;
    def avUp = fold k = 0 to per with p do
                if (src[k] - GetValue(src, k + 1)) > 0 then p + (src[k] - GetValue(src, k + 1)) else p;
    def avDn = fold i = 0 to per with q do
                if (src[i] - GetValue(src, i + 1)) > 0 then q else q - (src[i] - GetValue(src, i + 1));
    def Up    = fold k1 = 0 to per with p1 do
                if (src[k1] - GetValue(src, k1 + 1)) > 0 then p1 + 1 else p1;
    def Dn    = fold i1 = 0 to per with q1 do
                if (src[i1] - GetValue(src, i1 + 1)) > 0 then q1 else q1 + 1;
    def avgUp = if (up != 0) then avUp / up else avgUp[1];
    def avgDn = if (dn != 0) then avDn / dn else avgDn[1];
    def rs = if rs[1]==0 then 1 else
             if avgDn != 0 then avgUp / avgDn else rs[1];
    def out = 100-100 / (1.0 + rs);
    plot rsi_har = out;
}
# //Ehlers' Smoothed RSI
script rsi_ehl {
    input src = close;
    input per = 14;
    def bar_index = if isNaN(close) then bar_index[1] else bar_index[1] + 1;
    def _src = if (bar_index > 2) then (src + 2 * src[1] + src[2]) / 4.0 else src;
    def Up = fold k = 0 to per with p do
                if (_src[k] - GetValue(_src, k + 1)) > 0 then p + (_src[k] - GetValue(_src, k + 1)) else p;
    def Dn = fold i = 0 to per with q do
                if (_src[i] - GetValue(_src, i + 1)) > 0 then q else q - (_src[i] - GetValue(_src, i + 1));
    def out = 50 * (up-dn) / (up+dn) + 50;
    plot rsi_ehl = out;
}
def Regular = rsi(Price = rsiSource,Length = rsiLength);
def Slow    = rsi_slo(rsiSource, rsiLength);
def Rapid   = rsi_rap(rsiSource, rsiLength);
def Harris  = rsi_har(rsiSource, rsiLength);
def Ehlers  = rsi_ehl(rsiSource, rsiLength);
def RSX     = rsi_rsx(rsiSource, rsiLength);

def nRSI1;
Switch (selectRSI) {
Case Slow    : nRSI1 = Slow;
Case Rapid   : nRSI1 = Rapid;
Case Harris  : nRSI1 = Harris;
Case "Ehlers Smoothed" : nRSI1 = Ehlers;
Case RSX     : nRSI1 = RSX;
Default :      nRSI1 = Regular;
}
def nRSI = nRsi1;
def Signal = ExpAverage(nRsi, signalLength);

plot rsiLine = nRsi;    # "RSI"
plot sigLine = Signal;  # "Signal"
rsiLine.SetDefaultColor(Color.MAGENTA);
sigLine.SetDefaultColor(Color.GRAY);
#//Trend Determination
def Ma1 = ShortTrendLength;
def Ma2 = LongTrendLength;
def isUptrend = Average(close,Ma1) >= Average(close,Ma2);

#//Bullzone Resistance
plot BullOBT = if isUptrend then 90 else na;    # "Bullish Resistance"
plot BullOBB = if isUptrend then 80 else na;    # "Bullish Resistance"
#//Bearzone Resistance
plot BearOBT = if isUptrend then na else 65;    # "Bearish Resistance"
plot BearOBB = if isUptrend then na else 55;    # "Bearish Resistance"
#//Bullzone Support
plot BullOST = if isUptrend then 50 else na;    # "Bullish Support"
plot BullOSB = if isUptrend then 40 else na;    # "Bullish Support"
#//Bearzone Support
plot BearOST = if isUptrend then na else 30;    # "Bearish Support"
plot BearOSB = if isUptrend then na else 20;    # "Bearish Support"

BullOBT.SetDefaultColor(Color.GREEN);
BullOBB.SetDefaultColor(Color.DARK_GREEN);
BullOST.SetDefaultColor(Color.DARK_GREEN);
BullOSB.SetDefaultColor(Color.GREEN);

BearOBT.SetDefaultColor(Color.RED);
BearOBB.SetDefaultColor(Color.DARK_RED);
BearOST.SetDefaultColor(Color.DARK_RED);
BearOSB.SetDefaultColor(Color.RED);

AddCloud(if nRsi >= BullOBT then nRsi else na, BullOBT, Color.GREEN);
AddCloud(if nRsi >= BullOBB then nRsi else na, BullOBB, Color.DARK_GREEN);
AddCloud(if nRsi <= BearOSB then BearOSB else na, nRsi, Color.RED);
AddCloud(if nRsi <= BearOST then BearOST else na, nRsi, Color.DARK_RED);
#-- End of CODE
 
check the below with additional features.

CSS:
#/ This source code is subject to the terms of the Mozilla Public License 2.0 at https://mo
#// © Decam9
#study(title = "Constance Brown Altered RSI", shorttitle = "CB Altered RSI", overlay = false)
#Converted and mod by Sam4Cok@Samer800    - 01/2024
Declare lower;
#//Plot the RSI
input selectRSI = {default Regular, Slow, Rapid, Harris, "Ehlers Smoothed", RSX};
input rsiSource = close;    # "RSI Source"
input rsiLength = 14;       # "RSI Length"
input signalLength = 9;
input ShortTrendLength = 100;
input LongTrendLength = 200;

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

#// rsx RSI
script rsi_rsx {
input src = close;
input len = 14;
    def nRSI = rsi(Price=src, Length=len);
    def src_out = 100 * src;
    def mom0 = (src_out-src_out[1]);
    def moa0 = AbsValue(mom0);
    def Kg = 3 / (len + 2.0);
    def Hg = 1 - Kg;
    def f28 = CompoundValue(1, Kg * mom0 + Hg * f28[1], nRSI);
    def f30 = CompoundValue(1, Hg * f30[1] + Kg * f28, nRSI);
    def mom1 = f28 * 1.5 - f30 * 0.5;
    def f38 = CompoundValue(1, Hg * f38[1] + Kg * mom1, nRSI);
    def f40 = CompoundValue(1, Kg * f38 + Hg * f40[1], nRSI);
    def mom2 = f38 * 1.5 - f40 * 0.5;
    def f48 = CompoundValue(1, Hg * f48[1] + Kg * mom2, nRSI);
    def f50 = CompoundValue(1, Kg * f48 + Hg * f50[1],  nRSI);
    def mom_out = f48 * 1.5 - f50 * 0.5;
    def f58 = CompoundValue(1, Hg * f58[1] + Kg * moa0, nRSI);
    def f60 = CompoundValue(1, Kg * f58 + Hg * f60[1], nRSI);
    def moa1 = f58 * 1.5 - f60 * 0.5;
    def f68 = CompoundValue(1, Hg * f68[1] + Kg * moa1, nRSI);
    def f70 = CompoundValue(1, Kg * f68 + Hg * f70[1], nRSI);
    def moa2 = f68 * 1.5 - f70 * 0.5;
    def f78 = CompoundValue(1, Hg * f78[1] + Kg * moa2, nRSI);
    def f80 = CompoundValue(1, Kg * f78 + Hg * f80[1], nRSI);
    def moa_out = f78 * 1.5 - f80 * 0.5;
    def rsiout = max(min((mom_out / moa_out + 1.0) * 50.0, 100), 0);
    plot rsx = rsiout;
}

#// Slow RSI
script rsi_slo {
    input src = close;
    input per = 14;
    def _rsival;
    def nRSI = rsi(Price=src,Length= per);
    def up = fold k = 0 to per with p do
                if (src[k] - GetValue(src, k + 1)) > 0 then p + (src[k] - GetValue(src, k + 1)) else p;
    def dn = fold i = 0 to per with q do
                if (src[i] - GetValue(src, i + 1)) > 0 then q else q - (src[i] - GetValue(src, i + 1));
    if (up + dn == 0) {
        _rsival = CompoundValue(1, _rsival[1] + (1 / Max(per, 1)) * (50 - _rsival[1]), nRSI);
    } else {
        _rsival = CompoundValue(1, _rsival[1] + (1 / Max(per, 1)) * (100 * up / (up + dn) - _rsival[1]), nRSI);
    }
    plot out = _rsival;
}
# // Rapid RSI
script rsi_rap {
    input src = close;
    input per = 14;
    def sump = fold k = 0 to per with p do
                if (src[k] - GetValue(src, k + 1)) > 0 then p + (src[k] - GetValue(src, k + 1)) else p;
    def sumn = fold i = 0 to per with q do
                if (src[i] - GetValue(src, i + 1)) < 0 then q - (src[i] - GetValue(src, i + 1)) else q;
    def out = if sumn > 0 then 100 - 100 / (1 + sump / sumn) else 50;
    plot rsi_cut = out;
}
#// Harris RSI
script rsi_har {
    input src = close;
    input per = 14;
    def avUp = fold k = 0 to per with p do
                if (src[k] - GetValue(src, k + 1)) > 0 then p + (src[k] - GetValue(src, k + 1)) else p;
    def avDn = fold i = 0 to per with q do
                if (src[i] - GetValue(src, i + 1)) > 0 then q else q - (src[i] - GetValue(src, i + 1));
    def Up    = fold k1 = 0 to per with p1 do
                if (src[k1] - GetValue(src, k1 + 1)) > 0 then p1 + 1 else p1;
    def Dn    = fold i1 = 0 to per with q1 do
                if (src[i1] - GetValue(src, i1 + 1)) > 0 then q1 else q1 + 1;
    def avgUp = if (up != 0) then avUp / up else avgUp[1];
    def avgDn = if (dn != 0) then avDn / dn else avgDn[1];
    def rs = if rs[1]==0 then 1 else
             if avgDn != 0 then avgUp / avgDn else rs[1];
    def out = 100-100 / (1.0 + rs);
    plot rsi_har = out;
}
# //Ehlers' Smoothed RSI
script rsi_ehl {
    input src = close;
    input per = 14;
    def bar_index = if isNaN(close) then bar_index[1] else bar_index[1] + 1;
    def _src = if (bar_index > 2) then (src + 2 * src[1] + src[2]) / 4.0 else src;
    def Up = fold k = 0 to per with p do
                if (_src[k] - GetValue(_src, k + 1)) > 0 then p + (_src[k] - GetValue(_src, k + 1)) else p;
    def Dn = fold i = 0 to per with q do
                if (_src[i] - GetValue(_src, i + 1)) > 0 then q else q - (_src[i] - GetValue(_src, i + 1));
    def out = 50 * (up-dn) / (up+dn) + 50;
    plot rsi_ehl = out;
}
def Regular = rsi(Price = rsiSource,Length = rsiLength);
def Slow    = rsi_slo(rsiSource, rsiLength);
def Rapid   = rsi_rap(rsiSource, rsiLength);
def Harris  = rsi_har(rsiSource, rsiLength);
def Ehlers  = rsi_ehl(rsiSource, rsiLength);
def RSX     = rsi_rsx(rsiSource, rsiLength);

def nRSI1;
Switch (selectRSI) {
Case Slow    : nRSI1 = Slow;
Case Rapid   : nRSI1 = Rapid;
Case Harris  : nRSI1 = Harris;
Case "Ehlers Smoothed" : nRSI1 = Ehlers;
Case RSX     : nRSI1 = RSX;
Default :      nRSI1 = Regular;
}
def nRSI = nRsi1;
def Signal = ExpAverage(nRsi, signalLength);

plot rsiLine = nRsi;    # "RSI"
plot sigLine = Signal;  # "Signal"
rsiLine.SetDefaultColor(Color.MAGENTA);
sigLine.SetDefaultColor(Color.GRAY);
#//Trend Determination
def Ma1 = ShortTrendLength;
def Ma2 = LongTrendLength;
def isUptrend = Average(close,Ma1) >= Average(close,Ma2);

#//Bullzone Resistance
plot BullOBT = if isUptrend then 90 else na;    # "Bullish Resistance"
plot BullOBB = if isUptrend then 80 else na;    # "Bullish Resistance"
#//Bearzone Resistance
plot BearOBT = if isUptrend then na else 65;    # "Bearish Resistance"
plot BearOBB = if isUptrend then na else 55;    # "Bearish Resistance"
#//Bullzone Support
plot BullOST = if isUptrend then 50 else na;    # "Bullish Support"
plot BullOSB = if isUptrend then 40 else na;    # "Bullish Support"
#//Bearzone Support
plot BearOST = if isUptrend then na else 30;    # "Bearish Support"
plot BearOSB = if isUptrend then na else 20;    # "Bearish Support"

BullOBT.SetDefaultColor(Color.GREEN);
BullOBB.SetDefaultColor(Color.DARK_GREEN);
BullOST.SetDefaultColor(Color.DARK_GREEN);
BullOSB.SetDefaultColor(Color.GREEN);

BearOBT.SetDefaultColor(Color.RED);
BearOBB.SetDefaultColor(Color.DARK_RED);
BearOST.SetDefaultColor(Color.DARK_RED);
BearOSB.SetDefaultColor(Color.RED);

AddCloud(if nRsi >= BullOBT then nRsi else na, BullOBT, Color.GREEN);
AddCloud(if nRsi >= BullOBB then nRsi else na, BullOBB, Color.DARK_GREEN);
AddCloud(if nRsi <= BearOSB then BearOSB else na, nRsi, Color.RED);
AddCloud(if nRsi <= BearOST then BearOST else na, nRsi, Color.DARK_RED);
#-- End of CODE
Thank you Samer800 for your help. You are so humble and kind. Wish you the best. Regards.
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
275 Online
Create Post

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