200 + rsi

Tay310

New member
does anyone have a script to combine the 2 indicators?

Im trying to backtest when price is above the 200 sma and standard rsi indicator crosses above the oversold (30) level.

thank you
 
Solution
Code:
Declare Lower;
input MALength = 200;
input length = 14;
input crossingType = {default above, below};
input threshold = 30;
input averageType = AverageType.WILDERS;
Def Con1 = Close > Average(Close,MALength);
def Con2 = crosses(RSI(length=length, averageType=averageType).RSI, threshold, crossingType == CrossingType.above);
Plot Signal = if Con1 and Con2 then 1 else 0;
Code:
Declare Lower;
input MALength = 200;
input length = 14;
input crossingType = {default above, below};
input threshold = 30;
input averageType = AverageType.WILDERS;
Def Con1 = Close > Average(Close,MALength);
def Con2 = crosses(RSI(length=length, averageType=averageType).RSI, threshold, crossingType == CrossingType.above);
Plot Signal = if Con1 and Con2 then 1 else 0;
 
Solution
Code:
Declare Lower;
input MALength = 200;
input length = 14;
input crossingType = {default above, below};
input threshold = 30;
input averageType = AverageType.WILDERS;
Def Con1 = Close > Average(Close,MALength);
def Con2 = crosses(RSI(length=length, averageType=averageType).RSI, threshold, crossingType == CrossingType.above);
Plot Signal = if Con1 and Con2 then 1 else 0;
hey thanks for the reply. I think i may be missing something. But when i copy and paste the code, nothing shows up on my chart. the strategy does however appear accurately on the 'Edit study and strategies' page. How do i load so i can see the results (arrows and/or labels) on the chart? thanks again
 
Last edited by a moderator:
hey thanks for the reply. I think i may be missing something. But when i copy and paste the code, nothing shows up on my chart. the strategy does however appear accurately on the 'Edit study and strategies' page. How do i load so i can see the results (arrows and/or labels) on the chart? thanks again
The script will plot a 1 whenever the 2 conditions apply. It will plot a 0 for all of the other bars. I feel like a genie, you have 2 more wishes, be CAREFUL of what you wish for!
 
Can I make a request? I would like 1 indicator that is composed of 2 RSI indicators which I would like to be ale to change the values and colors of. Default values would be 25 and 100 for the RSI lengths. Colors make no matter for default as long as they are changeable. I also need an EMA with changeable moving average types such as simple, EMA, HULL and changeable length with a default of 25 EMA. I would like to have signals when the 25 RSI crosses above and below the 100 RSI. The other rule is longs only above the 25 EMA and shorts vice versa.

Is this possible to put all into 1 indicator? I would like to be able to scan for the RSI crossover signals if that matters how you go about coding this. Thanks in advance for any help.
 
Can I make a request? I would like 1 indicator that is composed of 2 RSI indicators which I would like to be ale to change the values and colors of. Default values would be 25 and 100 for the RSI lengths. Colors make no matter for default as long as they are changeable. I also need an EMA with changeable moving average types such as simple, EMA, HULL and changeable length with a default of 25 EMA. I would like to have signals when the 25 RSI crosses above and below the 100 RSI. The other rule is longs only above the 25 EMA and shorts vice versa.

Is this possible to put all into 1 indicator? I would like to be able to scan for the RSI crossover signals if that matters how you go about coding this. Thanks in advance for any help.
https://usethinkscript.com/threads/jt_multitrend.6998/page-2#posts "Posts #25 & #26" show how different EMA's and Butterworth Filters work with band restrictions for long and short conditions

Colors are assigned to conditions "Value or Price" through the use of setdefaultcolor(Color.Red) or the use of an If statement. Colors are not changeable through an input per se on their own, they would have to use an If then Statement.

SetDefaultColor( Color.Blue);

AssignValueColor(if A > B then Color.Blue else Color.Red);

AssignPriceColor( "Same as above")

or you can add an input APC= 2;

AssignPriceColor( if APC == 1 and A>B then Color.Blue else if APC ==1 and A<B then Color.Red else if APC == 2 and A>C then Color.Cyan else if APC ==2 and A<C then Color.Magenta else Color.Current);

The Color.Current comes into play if the APC input would be set for 0 or a number greater than 2
so you see that Colors are assigned to conditions, if the conditions change then an input could "Change a Color", but you have to ASSIGN it first!
 
@henry1224 Thank you for the tips. I will see what I can figure out from here. Thanks.
Did you come up with this?
Code:
declare lower;

input length1 = 25;
input length2 = 100;
input EMALength = 25;
Input price = Close;
input Dotsize = 3;
input averageType = AverageType.WILDERS;
def NetChgAvgA = MovingAverage(averageType, price - price[1], length1);
def TotChgAvgA = MovingAverage(averageType, AbsValue(price - price[1]), length1);
def ChgRatioA = if TotChgAvgA != 0 then NetChgAvgA / TotChgAvgA else 0;
def RSIA = 50 * (ChgRatioA + 1);
def NetChgAvgB = MovingAverage(averageType, price - price[1], length2);
def TotChgAvgB = MovingAverage(averageType, AbsValue(price - price[1]), length2);
def ChgRatioB = if TotChgAvgB != 0 then NetChgAvgB / TotChgAvgB else 0;
def RSIB = 50 * (ChgRatioB + 1);
Def EXPA = ExpAverage(Close,EMALength);
Def Con1 = If RSIA >= RSIB then 1 else 0;
Def Con2 = if Close>= EXPA then 1 else 0;

plot A1_Dot = if IsNaN(Close) then Double.NaN else 1;
A1_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A1_Dot.SetLineWeight(DotSize);
A1_Dot.AssignValueColor(if Con1 == 1 and Con2 ==1 then Color.Cyan else if Con1 ==0 and Con2 ==0 then Color.Magenta else Color.Yellow);
 
Ahhh, Sortaaa. :cool::cool::cool: Truthfully I didn't attempt to figure this out yet, but I looked at what you shared and I thank you. I don't think that is quite what I had in mind, but here is the link to the YT video showing this concept. YT Video here I thought it looked promising. I realize I can just put 2 occurrences of RSI with different lengths on a chart with an EMA, but an all in one I thought with signal might make it clearer and easier to scan for. Feel free to add any thoughts on the concept, and thanks again @henry1224
 
Did you come up with this?
Code:
declare lower;

input length1 = 25;
input length2 = 100;
input EMALength = 25;
Input price = Close;
input Dotsize = 3;
input averageType = AverageType.WILDERS;
def NetChgAvgA = MovingAverage(averageType, price - price[1], length1);
def TotChgAvgA = MovingAverage(averageType, AbsValue(price - price[1]), length1);
def ChgRatioA = if TotChgAvgA != 0 then NetChgAvgA / TotChgAvgA else 0;
def RSIA = 50 * (ChgRatioA + 1);
def NetChgAvgB = MovingAverage(averageType, price - price[1], length2);
def TotChgAvgB = MovingAverage(averageType, AbsValue(price - price[1]), length2);
def ChgRatioB = if TotChgAvgB != 0 then NetChgAvgB / TotChgAvgB else 0;
def RSIB = 50 * (ChgRatioB + 1);
Def EXPA = ExpAverage(Close,EMALength);
Def Con1 = If RSIA >= RSIB then 1 else 0;
Def Con2 = if Close>= EXPA then 1 else 0;

plot A1_Dot = if IsNaN(Close) then Double.NaN else 1;
A1_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
A1_Dot.SetLineWeight(DotSize);
A1_Dot.AssignValueColor(if Con1 == 1 and Con2 ==1 then Color.Cyan else if Con1 ==0 and Con2 ==0 then Color.Magenta else Color.Yellow);
You can also plot this as an upper indicator, Coloring the EMA to reflect the change in RSI
Code:
declare Upper;

input length1 = 25;
input length2 = 100;
input EMALength = 25;
Input Price = Close;
Input arrows = no;
Input Dotsize = 3;
input averageType = AverageType.WILDERS;
def NetChgAvgA = MovingAverage(averageType, price - price[1], length1);
def TotChgAvgA = MovingAverage(averageType, AbsValue(price - price[1]), length1);
def ChgRatioA = if TotChgAvgA != 0 then NetChgAvgA / TotChgAvgA else 0;
def RSIA = 50 * (ChgRatioA + 1);
def NetChgAvgB = MovingAverage(averageType, price - price[1], length2);
def TotChgAvgB = MovingAverage(averageType, AbsValue(price - price[1]), length2);
def ChgRatioB = if TotChgAvgB != 0 then NetChgAvgB / TotChgAvgB else 0;
def RSIB = 50 * (ChgRatioB + 1);
Plot EXPA = ExpAverage(Close,EMALength);
Def Con1 = If RSIA >= RSIB then 1 else 0;
Def Con2 = if Close>= EXPA then 1 else 0;
EXPA.AssignValueColor(if Con1 == 1 and Con2 ==1 then Color.Cyan else if Con1 ==0 and Con2 ==0 then Color.Magenta else Color.Yellow);

plot ArrowDown = if arrows and (Con1 ==0 and Con2 ==0 and Con1[1] ==1 and Con2[1] ==0) or (arrows and Con1 ==0 and Con2 ==0 and Con1[1] == 0 and Con2[1] == 1) then High else double.nan;
ArrowDown.setpaintingStrategy(paintingStrategy.Arrow_Down);
ArrowDown.setDefaultColor(color.Magenta);
ArrowDown.setLineWeight(dotsize);

plot ArrowUp = if arrows and (Con1 ==1 and Con2 ==1 and Con1[1] ==1 and Con2[1] ==0) or (arrows and Con1 ==1 and Con2 ==1 and Con1[1] == 0 and Con2[1] == 1) then Low else double.nan;
ArrowUp.setpaintingStrategy(paintingStrategy.Arrow_Up);
ArrowUp.setDefaultColor(color.Cyan);
ArrowUp.setLineWeight(dotsize);
 
Not sure what the difference is, but your signals don't match at all to when I place 2 instances of RSI and use 25 and 100 for their lengths- signals are the crossovers of the 2 RSI overlayed on top of each other when they are signals on the right side of the 25 EMA
 
Not sure what the difference is, but your signals don't match at all to when I place 2 instances of RSI and use 25 and 100 for their lengths- signals are the crossovers of the 2 RSI overlayed on top of each other when they are signals on the right side of the 25 EMA
Here is the code for 2 RSI
Code:
declare lower;

input length1 = 25;
input length2 = 100;
input EMALength = 25;
Input price = Close;
input Dotsize = 3;
input arrows = no;
input averageType = AverageType.WILDERS;
def NetChgAvgA = MovingAverage(averageType, price - price[1], length1);
def TotChgAvgA = MovingAverage(averageType, AbsValue(price - price[1]), length1);
def ChgRatioA = if TotChgAvgA != 0 then NetChgAvgA / TotChgAvgA else 0;
Plot RSIA = 50 * (ChgRatioA + 1);
def NetChgAvgB = MovingAverage(averageType, price - price[1], length2);
def TotChgAvgB = MovingAverage(averageType, AbsValue(price - price[1]), length2);
def ChgRatioB = if TotChgAvgB != 0 then NetChgAvgB / TotChgAvgB else 0;
Plot RSIB = 50 * (ChgRatioB + 1);
RSIA.SetDefaultColor(Color.Cyan);
RSIB.SetDefaultColor(Color.Magenta);
AddCloud(RSIA,RSIB,Color.Cyan,Color.Magenta);
plot ArrowDown = if arrows and RSIA crosses below RSIB then RSIB else double.nan;
ArrowDown.setpaintingStrategy(paintingStrategy.Arrow_Down);
ArrowDown.setDefaultColor(color.Magenta);
ArrowDown.setLineWeight(dotsize);

plot ArrowUp = if arrows and RSIA crosses Above RSIB then RSIB else double.nan;
ArrowUp.setpaintingStrategy(paintingStrategy.Arrow_Up);
ArrowUp.setDefaultColor(color.Cyan);
ArrowUp.setLineWeight(dotsize);

0uDipXa.gif
 
Here is the code for 2 RSI
Code:
declare lower;

input length1 = 25;
input length2 = 100;
input EMALength = 25;
Input price = Close;
input Dotsize = 3;
input arrows = no;
input averageType = AverageType.WILDERS;
def NetChgAvgA = MovingAverage(averageType, price - price[1], length1);
def TotChgAvgA = MovingAverage(averageType, AbsValue(price - price[1]), length1);
def ChgRatioA = if TotChgAvgA != 0 then NetChgAvgA / TotChgAvgA else 0;
Plot RSIA = 50 * (ChgRatioA + 1);
def NetChgAvgB = MovingAverage(averageType, price - price[1], length2);
def TotChgAvgB = MovingAverage(averageType, AbsValue(price - price[1]), length2);
def ChgRatioB = if TotChgAvgB != 0 then NetChgAvgB / TotChgAvgB else 0;
Plot RSIB = 50 * (ChgRatioB + 1);
RSIA.SetDefaultColor(Color.Cyan);
RSIB.SetDefaultColor(Color.Magenta);
AddCloud(RSIA,RSIB,Color.Cyan,Color.Magenta);
plot ArrowDown = if arrows and RSIA crosses below RSIB then RSIB else double.nan;
ArrowDown.setpaintingStrategy(paintingStrategy.Arrow_Down);
ArrowDown.setDefaultColor(color.Magenta);
ArrowDown.setLineWeight(dotsize);

plot ArrowUp = if arrows and RSIA crosses Above RSIB then RSIB else double.nan;
ArrowUp.setpaintingStrategy(paintingStrategy.Arrow_Up);
ArrowUp.setDefaultColor(color.Cyan);
ArrowUp.setLineWeight(dotsize);

0uDipXa.gif
The rsi's are on the same scale and match up

Def Con1 = If RSIA >= RSIB then 1 else 0;
Def Con2 = if Close>= EXPA then 1 else 0;
EXPA.AssignValueColor(if Con1 == 1 and Con2 ==1 then Color.Cyan else if Con1 ==0 and Con2 ==0 then Color.Magenta else Color.Yellow);


The conditions state when RSIa is greater than or equal to RSIb then 1 else 0

Condition 2 states the Close is Greater than or equal to the EMA then 1 else 0

Both conditions have to be +1 for LONG and 0 for Short
 

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