Custom color coded RSI on watchlist - help

kici

New member
VIP
Hello,

Looking for help on creating code on my current watchlist if RSI is crossed above 80 or below 20. If its above 80 make it Green color, red for below 20, and gray for neutral (in between)

Appreciate the help

And thanks everyone for all the amazing stuff you've done on this forum
 

rad14733

Moderator
Staff member
VIP
@kici How far have you gotten with your code...??? You say you want to create it but have you actually started or actually wanting someone to code it for you...??? It's really not a hard piece of code and can be adapted from other Custom Watchlist Column code if you take the time to review a few existing scripts... We'll help you along if you get stuck...
 

kici

New member
VIP
@kici How far have you gotten with your code...??? You say you want to create it but have you actually started or actually wanting someone to code it for you...??? It's really not a hard piece of code and can be adapted from other Custom Watchlist Column code if you take the time to review a few existing scripts... We'll help you along if you get stuck...
Could you point me at some so I can take a stab at it and see what can be done,

Thanks appreciate it
 

Christopher84

Well-known member
VIP
Could you point me at some so I can take a stab at it and see what can be done,

Thanks appreciate it
This should do the trick. Definitely look at how the code is put together. Its fairly easy to replicate this type of stuff on other indicators you may use. Hope this helps!

Code:
input length = 14;
input over_Bought = 80;
input over_Sold = 20;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;

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);


def OB = RSI >= Over_Bought;
def OS = RSI <= Over_Sold;

AssignBackgroundColor(if OB then color.light_red else if OS then color.dark_green else color.black);
 
Last edited:

Christopher84

Well-known member
VIP
This should do the trick. Definitely look at how the code is put together. Its fairly easy to replicate this type of stuff on other indicators you may use. The "meat" of the code starts with the line that says plot RSI. One plot is expected (what you plot will determine the # you see on your watchlist). Then define the OB/OS and assign the background color for your OB/OS conditions. The front part of the code is already in TOS, so just copy and paste pretty much. Hope this helps!

Code:
input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;

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);


def OB = RSI >= Over_Bought;
def OS = RSI <= Over_Sold;

AssignBackgroundColor(if OB then color.light_red else if OS then color.dark_green else color.black);
 

kici

New member
VIP
Thanks @Christopher84

Can you explain to me what these lines mean:

def NetChgAvg = MovingAverage(averageType, price - price[1], length);

I'm confused on the -> MovingAverage ( the brackets inside i understand )

same with the:

def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);

AbsValue? I am speculating it has something to do with where the RSI currently is or?


plot RSI = 50 * (ChgRatio + 1);

Why are we times 50 here, where does that number come from?

Thanks for taking your time, just trying to understand things better :)
 

Christopher84

Well-known member
VIP
Thanks @Christopher84

Can you explain to me what these lines mean:

def NetChgAvg = MovingAverage(averageType, price - price[1], length);

I'm confused on the -> MovingAverage ( the brackets inside i understand )

same with the:

def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);

AbsValue? I am speculating it has something to do with where the RSI currently is or?


plot RSI = 50 * (ChgRatio + 1);

Why are we times 50 here, where does that number come from?

Thanks for taking your time, just trying to understand things better :)
plot RSI = 50 * (ChgRatio + 1); Is just the formula to determine RSI. Inside the brackets are the various components used in its calculation (averageType(the type of average specified in the inputs), price (current price) - price[1](price one period back), length (the period of time specified in your inputs)). AbsValue stands for absolute value. So in practice "absolute value" means to remove any negative sign in front of a number, and to think of all numbers as positive (or zero). In other words the absolute value of 6 and -6 is the exact same, 6. Absolute value comes in handy when you are trying to measure change and don't want negative values. If you right click on RSI under studies and select view, you will see the code/formula for RSI (which is the same as what I posted above).
 

rad14733

Moderator
Staff member
VIP
@kici Like I mentioned earlier, use the site search to locate Custom Watchlist Column code... Or just spend time scanning topics here in the forums... You surely won't come away knowing less... Put in the time rather than expecting instant gratification... I'm just being blatantly honest with you so don't take it any other way... The best way to learn is to, well, learn... Reviewing exiting code is one of the best ways to go about doing just that...
 

Similar threads

Top