Moving Average Crossover RSI Indicator for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
This script plot the 5 SMA (Simple Moving Average) of the RSI (Relative Strength Index) inside the default RSI indicator. Inspired by the Thandicator by Thanson Stevens on TradingView.



thinkScript Code

Rich (BB code):
#
# TD Ameritrade IP Company, Inc. (c) 2007-2019
# Tweaked by @korygill
# https://usethinkscript.com/d/185-moving-average-crossover-rsi-indicator-for-thinkorswim

declare lower;

input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;
input rsiMALength = 5; #hint rsiMALength: RSI Moving Average Length
input rsiAverageType = AverageType.SIMPLE;

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);
plot OverSold = over_Sold;
plot 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 the RSI Moving Average
def rsiMA = MovingAverage(rsiAverageType, RSI, rsiMALength);
plot prsiMA = rsiMA;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

RSI.DefineColor("OverBought", GetColor(5));
RSI.DefineColor("Normal", GetColor(7));
RSI.DefineColor("OverSold", GetColor(1));
RSI.AssignValueColor(if RSI > over_Bought then RSI.color("OverBought") else if RSI < over_Sold then RSI.color("OverSold") else RSI.color("Normal"));
OverSold.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(8));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

Shareable Link

https://tos.mx/ldVZ7s

Credit:
  • @korygill
 
Last edited:
I

icmoflow

New member
Are you still planning on releasing the AMM indicator that was available to VIP members prior? Thanks Ben
 
H

HighBredCloud

Well-known member
VIP
Enhanced PercentR 5 SMA CrossOver Indicator by @netarchitech fresh out of the oven! Can't wait to test it out in live market! Thank You for improving this concept...This indicator gives clear signals with the breakout arrows and the longer lasting colors of the PercentR in the OB/OS conditions...The signals also tend to come on quicker vs regular RSI SMA CrossOver...Anyone looking at the RSI 5 SMA CrossOver should check this thing out and pair it with the MACD/FREMA also enhanced by @netarchitech

 
H

HighBredCloud

Well-known member
VIP
Please share study, if that's ok . 🙏

@AGD please see the PercentR study below.

Code:

Code:
# filename: Mov_Avg_Crossover_PercentR

declare lower;

input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
input showBreakoutSignals = yes;
input PercentRMALength = 5; #hint rsiMALength: RSI Moving Average Length
input PercentRAverageType = AverageType.SIMPLE;

def highest = Highest(high, length);
def divisor = highest - Lowest(low, length);

plot "%R" = if divisor equals 0 then 0 else 100 - 100 * (highest - close) / divisor;
"%R".DefineColor("OverBought", GetColor(5));
"%R".DefineColor("Normal", GetColor(7));
"%R".DefineColor("OverSold", GetColor(1));
"%R".AssignValueColor(if "%R" > over_Bought then "%R".color("OverBought") else if "%R" < over_Sold then "%R".color("OverSold") else "%R".color("Normal"));
"%R".SetLineWeight(2);

# plot the PercentR Moving Average
def PercentRMA = MovingAverage(PercentRAverageType, "%R", PercentRMALength);
plot PercentRMovAvg = PercentRMA;
PercentRMovAvg.SetDefaultColor(GetColor(6));
PercentRMovAvg.SetLineWeight(2);

plot OverBought = over_Bought;
OverBought.SetDefaultColor(GetColor(8));
OverBought.HideTitle();

plot OverSold = over_Sold;
OverSold.SetDefaultColor(GetColor(8));
OverSold.HideTitle();

# plot the Breakout Signals
plot UpSignal = if "%R" crosses above OverSold then OverSold else Double.NaN;
UpSignal.SetHiding(!showBreakoutSignals);
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpSignal.HideTitle();

plot DownSignal = if "%R" crosses below OverBought then OverBought else Double.NaN;
DownSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownSignal.HideTitle();
 
H

HighBredCloud

Well-known member
VIP
Mobius MACD/FREMA enhanced by @netarchitech

Code:

Code:
# MACD with a more Normal Distribution
# Mobius
# V01.09.2015
#Hint: Plots a Gaussian distribution. If Normal Distribution is met, then at minimum, 68.2% of the close values should be inside a One Standard Deviation Envelope and 95.4% of the close values should be inside a 2 Standard Deviation Envelope.

# V11.01.2019 - netarchitech added standard TOS Breakout Signals per HighBredCloud request
# V11.01.2019 - netarchitech added Ehlers and Mobius Forward/Reverse EMA per HighBredCloud request

declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input showBreakoutSignals = no;

# Four Pole Filter
script g{
input length = 4;
input betaDev = 2;
input price = OHLC4;
def c;
def w;
def beta;
def alpha;
def G;
c = price;
w = (2 * Double.Pi / length);
beta = (1 - Cos(w)) / (Power(1.414, 2.0 / betaDev) - 1 );
alpha = (-beta + Sqrt(beta * beta + 2 * beta));
G = Power(alpha, 4) * c +
4 * (1 – alpha) * G[1] – 6 * Power( 1 - alpha, 2 ) * G[2] +
4 * Power( 1 - alpha, 3 ) * G[3] - Power( 1 - alpha, 4 ) * G[4];
plot Line = G;
}
# Modified MACD
plot Value = g(length = fastLength) - g(length = slowLength);
plot Avg = g(price = Value, length = MACDLength);
plot Diff = Value - Avg;
plot ZeroLine = 0;

Value.SetDefaultColor(GetColor(1));
#Value.SetLineWeight(2);
Avg.SetDefaultColor(GetColor(8));
#Avg.SetLineWeight(2);
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));
ZeroLine.SetDefaultColor(GetColor(0));

plot UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
plot DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);


# Forward / Reverse EMA
# (c) 2017 John F. Ehlers
# Ported to TOS 07.16.2017
# Mobius

# Inputs:
input AA = .1;

# Vars:
def CC;
def RE1;
def RE2;
def RE3;
def RE4;
def RE5;
def RE6;
def RE7;
def RE8;
def EMA;
plot Signal;
plot plot0;

CC = if CC[1] == 0 then .9 else 1 – AA;
EMA = AA * Close + CC * EMA[1];
RE1 = CC * EMA + EMA[1];
RE2 = Power(CC, 2) * RE1 + RE1[1];
RE3 = Power(CC, 4) * RE2 + RE2[1];
RE4 = Power(CC, 8) * RE3 + RE3[1];
RE5 = Power(CC, 16) * RE4 + RE4[1];
RE6 = Power(CC, 32) * RE5 + RE5[1];
RE7 = Power(CC, 64) * RE6 + RE6[1];
RE8 = Power(CC, 128) * RE7 + RE7[1];

Signal = EMA – AA * RE8;
Signal.AssignValueColor(if Signal > Signal[1]
                        then Color.GREEN
                        else Color.RED);
Signal.SetLineWeight(3);
Plot0 = if isNaN(close) then double.nan else 0;
Plot0.SetDefaultColor(Color.GRAY);

#addCloud(0, Signal, color.RED, color.GREEN);
 
T

Trading51

Active member
2019 Donor
Could someone add a second RSI moving average option to this, please? thank you

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2019
# Tweaked by [USER=212]@korygill[/USER]
# https://usethinkscript.com/d/185-moving-average-crossover-rsi-indicator-for-thinkorswim

declare lower;

input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;
input rsiMALength = 5; #hint rsiMALength: RSI Moving Average Length
input rsiAverageType = AverageType.SIMPLE;

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);
plot OverSold = over_Sold;
plot 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 the RSI Moving Average
def rsiMA = MovingAverage(rsiAverageType, RSI, rsiMALength);
plot prsiMA = rsiMA;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

RSI.DefineColor("OverBought", GetColor(5));
RSI.DefineColor("Normal", GetColor(7));
RSI.DefineColor("OverSold", GetColor(1));
RSI.AssignValueColor(if RSI > over_Bought then RSI.color("OverBought") else if RSI < over_Sold then RSI.color("OverSold") else RSI.color("Normal"));
OverSold.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(8));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
 
Last edited by a moderator:
markos

markos

Well-known member
VIP
Hi, please use the search function, there are many examples of how to do this. Thanks.
 
T

tomsk

Well-known member
VIP
@markos Actually that was a rather odd request if you think about it. RSI is a bounded oscillator with values between -100 and +100. There is really no way to calculate when that would ever cross a moving average. AMZN currently has an RSI of 56 and a EMA(5) of 1789. They won't cross anytime soon
 
T

Tostechnical

Member
@tomsk yes it will. The EMA that is used in this indicator is using RSI as the input instead of close. Your example has close as an input not RSI. If you set EMA's input as RSI it will cross RSI
 
T

tomsk

Well-known member
VIP
I was responding to a generic query from @manishji that had no prior reference to any study. Anything's possible I suppose
 
T

Tostechnical

Member
ahhh I was assuming @manishji was referring to the indicator at the top of the thread.
 
markos

markos

Well-known member
VIP
Yup @tomsk anything is possible. Until I got to this site, I had never considered slowing down that classic indicator :) JC at simplerstuff must have sold it recently 🤣
 
J

Jim C

New member
@korygill What I am trying to do is scan for a number of periods where the prsiMA is above or below the RSI. So in example RsiMA> RSI for 20 days.

Can someone point me in the right direction please?

Thanks in advance!

Jim
 
Last edited by a moderator:
J007RMC

J007RMC

Well-known member
2019 Donor
VIP
A detrended macd
Code:
# Detrended MACD
# Mobius
# V01.04.2015

declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;

plot Value = MovingAverage(averageType, close + (close - close[(fastlength-1)/2]), fastLength) - MovingAverage(averageType, close + (close - close[(slowLength-1)/2]), slowLength);
plot Avg = MovingAverage(averageType, Value, MACDLength);

plot Diff = Value - Avg;
plot ZeroLine = 0;

plot UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
plot DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));
ZeroLine.SetDefaultColor(GetColor(0));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
# End Code Detrended MACD
 

Similar threads

Top