Color background based on SlowRSI


Category:
0
0

Howdy,

I’m having trouble with one part of a SLOWRSI indicator code that I want to fill in with colors based on where the indicator level is.  I have done the same with a couple other indicators, but can’t get the bold part of the code correct for this one.  Would appreciate any help.

#slowrsi
input emaLength = 6;
input rsiLength = 14;
input over_bought = 80;
input over_sold = 20;

def ema = ExpAverage(close, emaLength);
def netChgAvg = WildersAverage(close – ema, rsiLength);
def totChgAvg = WildersAverage(AbsValue(close – ema), rsiLength);
def chgRatio = if totChgAvg != 0 then netChgAvg / totChgAvg else 0;

plot SlowRSI = (emaLength,rsiLength,over_bought,over_sold),emaLength);

assignBackgroundColor(if SlowRSI>= 70 then color.ORANGE
else if SlowRSI< 25 then color.BLUE

else if SlowRSI< 41 then color.MAGENTA

else if SlowRSI> 58 then color.LiGHT_GREEN
else color.GREEN);

 

I am not really sure what it is I’m looking for the variables….

Much appreciated

RB

RESOLVED
Marked as spam
Posted by (Questions: 3, Answers: 2)
Asked on March 27, 2020 8:29 pm
88 views
0
Private answer

Pretty simple to fix. That line of code you set to bold text:

plot SlowRSI = (emaLength,rsiLength,over_bought,over_sold),emaLength);

That line of code is completely invalid.Which means that is not at all how you would reference an external chart study. But you don't need to do that anyway. When you look at the code for the SlowRSI that comes with Thinkorswim you will find it uses the following line instead of what you have:

plot SlowRSI = 50 * (chgRatio + 1);

So if you simply copied the code exactly as it is included with Thinkorswim you would have had success. But just in case you didn't follow that explanation, here is the code from the built-in version that computes the SlowRSI:

input emaLength = 6;
input rsiLength = 14;
input over_bought = 80;
input over_sold = 20;
def ema = ExpAverage(close, emaLength);
def netChgAvg = WildersAverage(close – ema, rsiLength);
def totChgAvg = WildersAverage(AbsValue(close – ema), rsiLength);
def chgRatio = if totChgAvg != 0 then netChgAvg / totChgAvg else 0;
plot SlowRSI = 50 * (chgRatio + 1);

You would then add your AssignBackgroundColor() statement to the bottom of that.

If you instead only wanted to reference the study instead of using the full code. Well this is how you reference that external study:

input emaLength = 6;
input rsiLength = 14;
input over_bought = 80;
input over_sold = 20;
plot SlowRSI = reference SlowRSI(emaLength, rsiLength, over_bought, over_sold).SlowRSI;

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on March 28, 2020 9:03 am
0
Pete, Thank you so much! That did the trick! Funny how you can play with something for so long and just seem to sink deeper. How easy it turned out to be ? Below is my completed code with colors assigned to the boxes if anyone is interested. Again, much appreciate your time and help. Be safe and healthy during these strange times! #slowrsi with Colored Boxes input emaLength = 6; input rsiLength = 14; input over_bought = 80; input over_sold = 20; def ema = ExpAverage(close, emaLength); def netChgAvg = WildersAverage(close – ema, rsiLength); def totChgAvg = WildersAverage(AbsValue(close – ema), rsiLength); def chgRatio = if totChgAvg != 0 then netChgAvg / totChgAvg else 0; plot SlowRSI = 50 * (chgRatio + 1); assignBackgroundColor(if SlowRSI>= 70 then color.ORANGE else if SlowRSI< 25 then color.BLUE else if SlowRSI 58 then color.PINK else color.MAGENTA); SlowRSI.assignValueColor(if SlowRsi>1 then color.BLACK else color.black); Sincerely, RB
( at March 28, 2020 3:05 pm)