RSI Level as Horizontal Line

azakusa

New member
Anyone have any ideas on the code needed to make a simple horizontal line that follows RSI value? I have a thinkscript study which I located somewhere on the internet that follows price value in real time. Now looking to add the same to the RSI study.

Problem is that I am not much of a coder. I have played around with mixing the code below with the RSI code, but no luck. I can hack stuff by cut and pasting but understand little of the actual functionality behind it.

If its any help here is the script I am using to follow price value:

Code:
#Plots a Horizontal Line that follows the price value selected
input price=close;
input offset=0;
input length = 300;

def sma = SimpleMovingAvg(price, 1, length);
rec line = if IsNaN(sma) then line[1] else sma[offset];
plot priceline=if isnan(sma) then line else double.nan;
priceline.setpaintingStrategy(paintingStrategy.LINE);
priceline.setlineWeight(3);
priceline.setdefaultColor(color.green);
priceline.hideBubble();

Any clues, ideas or a flat out solution would be hugely appreciated!

Thank you all.
 
Solution
something like this?

Code:
#Plots a Horizontal Line that follows the price value selected
#
# TD Ameritrade IP Company, Inc. (c) 2007-2021
#

declare lower;

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

rad14733

Well-known member
VIP
@azakusa You had the right idea... If you can't figure out where the following line goes then post your RSI code and I'll add it in... The code is modified from one of several of my PriceLine scripts...

Ruby:
plot rsiLine = HighestAll(if !IsNaN(RSI) and IsNaN(RSI[-1]) then RSI else Double.NaN);
 
Last edited:

azakusa

New member
NICE! I pasted it in at the eof. Seems to work like a charm. Thank you thank you thank you!

Been playing with this on the one minute chart and have noticed that it doesnt actually tick along with the realtime RSI value, but plots after the end of each minute. Is there a way to alter it so that it moves in realtime? Thanks again.
 

rad14733

Well-known member
VIP
@azakusa Mine moves right with my on-chart RSI in all timeframes... Below is an example with the only difference being that my RSI Chart Label is set to Round to the nearest whole number, yet that Left Axis RSI is exact...

T6Bnsst.png


Second example...

zchLxQg.png
 

azakusa

New member
Rad, Thanks for the follow-up. I am not using RSI inside the PA but in the lower. You can see here there are two different bubble values when showing the default TOS RSI and the one with your line of code in it (called plotliner) simultaneously.

rsi-plot-example.png
 

BillW

New member
Did you want something like this? It paints a horizontal line on the right side of the lower RSI that follows price

Code:
input offset=0;


rec line = if IsNaN(RSI) then line[1] else RSI[offset];
plot priceline=if isnan(RSI) then line else double.nan;
priceline.setpaintingStrategy(paintingStrategy.LINE);
priceline.setlineWeight(3);
priceline.setdefaultColor(color.green);
priceline.hideBubble();
 

rad14733

Well-known member
VIP
@BillW @azakusa This is the exact code I run in my customized version if RSI...

Ruby:
#Plot moving rsiLine across chart at current RSI level
plot rsiLine = if showrsiLine then HighestAll(if !IsNaN(RSI) and IsNaN(RSI[-1]) then RSI else Double.NaN) else Double.NaN;
rsiLine.AssignValueColor(if RSI > over_Bought then RSI.color("OverBought") else if RSI < over_Sold then RSI.color("OverSold") else RSI.color("Normal"));
rsiLine.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
rsiLine.SetLineWeight(1);
 

azakusa

New member
Not exactly.
I wanted a line that runs across the entire lower RSI panel which plots the RSI value as it changes.
I day trade on the 1 and 2 minute charts mostly and rely on RSI for timing entries and exits. I usually draw a line into the RSI but this can be very distracting. So was hoping to find a way to plot the RSI value as it moves along. Eliminating the need to draw.
 

azakusa

New member
#Plot moving rsiLine across chart at current RSI level plot rsiLine = if showrsiLine then HighestAll(if !IsNaN(RSI) and IsNaN(RSI[-1]) then RSI else Double.NaN) else Double.NaN; rsiLine.AssignValueColor(if RSI > over_Bought then RSI.color("OverBought") else if RSI < over_Sold then RSI.color("OverSold") else RSI.color("Normal")); rsiLine.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES); rsiLine.SetLineWeight(1);
Tried to add this to the lower RSI but got error. Do I paste this code at the end of the default RSI code?
 

rad14733

Well-known member
VIP
Not exactly.
I wanted a line that runs across the entire lower RSI panel which plots the RSI value as it changes.
I day trade on the 1 and 2 minute charts mostly and rely on RSI for timing entries and exits. I usually draw a line into the RSI but this can be very distracting. So was hoping to find a way to plot the RSI value as it moves along. Eliminating the need to draw.

I can't answer why your code is so inaccurate compared to mine... For scalping I keep my RSI on-chart but that's just my personal preference... But my lower, if I run it concurrently, always matches my on-chart exactly and I've never experienced a discrepancy in any timeframe...

As to pasting the code, you are probably missing the showrisLine input... Use this line if you don't want to turn the line off...

Ruby:
plot rsiLine = if HighestAll(if !IsNaN(RSI) and IsNaN(RSI[-1]) then RSI else Double.NaN);

Otherwise add the following line somewhere above the rsiLine code and keep the code intact...

Ruby:
input showrsiLine = yes;
 

germanburrito

Active member
something like this?

Code:
#Plots a Horizontal Line that follows the price value selected
#
# TD Ameritrade IP Company, Inc. (c) 2007-2021
#

declare lower;

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

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




#Plots a Horizontal Line that follows the price value selected

input offset=0;
input length2 = 25;

def sma = SimpleMovingAvg(rsi, 1, length2);
rec line = if IsNaN(sma) then line[1] else sma[offset];
plot priceline=if isnan(sma) then line else double.nan;
priceline.setpaintingStrategy(paintingStrategy.LINE);
priceline.setlineWeight(3);
priceline.setdefaultColor(color.green);
priceline.hideBubble();
 
Solution

Similar threads

Top