# Request: Watchlist Column - Distance from Pivot Point

#### EMDAU87

##### New member
Hello all,

I apologize if this is in the wrong place. I am looking for a watchlist column that would show me how far a stock's current price is from a pivot point. For example, how far a stock's current price is from Pivot S1, how far a stock's price is from Pivot R1, etc.

I would assume the Pivot calculations would be based upon the previous day's high, low, and close.

Is such a thing possible in thinkscript?

Solution
Hello all,

I apologize if this is in the wrong place. I am looking for a watchlist column that would show me how far a stock's current price is from a pivot point. For example, how far a stock's current price is from Pivot S1, how far a stock's price is from Pivot R1, etc.

I would assume the Pivot calculations would be based upon the previous day's high, low, and close.

Is such a thing possible in thinkscript?

sure, almost anything is possible. somethings just take more formulas.
something like this will find the difference of 1 pivot.
def s1diff = s1 - close;
then it's just a matter of figuring out what you want to see.

what pivot study are you going to use?

you mention column study , as in singular, as in 1 study. but...
Hello all,

I apologize if this is in the wrong place. I am looking for a watchlist column that would show me how far a stock's current price is from a pivot point. For example, how far a stock's current price is from Pivot S1, how far a stock's price is from Pivot R1, etc.

I would assume the Pivot calculations would be based upon the previous day's high, low, and close.

Is such a thing possible in thinkscript?

sure, almost anything is possible. somethings just take more formulas.
something like this will find the difference of 1 pivot.
def s1diff = s1 - close;
then it's just a matter of figuring out what you want to see.

what pivot study are you going to use?

you mention column study , as in singular, as in 1 study. but then you mention displaying 2+ numbers...?
if there are 5 pivots, do you want all 5 distances from each pivot to close, listed side by side, in 1 column?

do you want 5 different column studies? 1 study for each pivot , to list the distance from it to close?

here is a CHART study, with labels and bubbles.
see if this gives you ideas of what you want to see in a column.

Ruby:
``````# pivot_labels_bubbles_00

def bn = barnumber();
def na = double.nan;

# read pivot values from the study, PivotPoints()
def r3 = round(PivotPoints().r3,2);
def r2 = round(PivotPoints().r2,2);
def r1 = round(PivotPoints().r1,2);
def pp = round(PivotPoints().pp,2);
def s1 = round(PivotPoints().s1,2);
def s2 = round(PivotPoints().s2,2);
def s3 = round(PivotPoints().s3,2);

# display differences of close - pivots  in labels

input show_labels = yes;
addlabel(show_labels, "S3: " + s3 + " diff: " + round(s3 - close,2), ( if s3 > close then color.green else color.red) );
addlabel(show_labels, "S2: " + s2 + " diff: " + round(s2 - close,2), ( if s2 > close then color.green else color.red) );
addlabel(show_labels, "S1: " + s1 + " diff: " + round(s1 - close,2), ( if s1 > close then color.green else color.red) );
addlabel(show_labels, "PP: " + pp + " diff: " + round(pp - close,2), ( if pp > close then color.green else color.red) );
addlabel(show_labels, "R1: " + r1 + " diff: " + round(r1 - close,2), ( if r1 - close then color.green else color.red) );
addlabel(show_labels, "R2: " + r2 + " diff: " + round(r2 - close,2), ( if r2 - close then color.green else color.red) );
addlabel(show_labels, "R3: " + r3 + " diff: " + round(r3 - close,2), ( if r3 - close then color.green else color.red) );

input bubble_offset = 3;
def off = bubble_offset + 1;
def x = if (!isnan(close[bubble_offset + 1]) and isnan(close[bubble_offset])) then 1 else 0;
def cls2 = close[off];

input show_bubbles = yes;
addchartbubble(show_bubbles and x, s3[off] , "S3: " + s3[off] + " diff: " + round(s3[off] - cls2,2), ( if s3[off] > cls2 then color.green else color.red), no);
addchartbubble(show_bubbles and x, s2[off] , "S2: " + s2[off] + " diff: " + round(s2[off] - cls2,2), ( if s2[off] > cls2 then color.green else color.red), no);
addchartbubble(show_bubbles and x, s1[off] , "S1: " + s1[off] + " diff: " + round(s1[off] - cls2,2), ( if s1[off] > cls2 then color.green else color.red), no);
addchartbubble(show_bubbles and x, pp[off] , "PP: " + pp[off] + " diff: " + round(pp[off] - cls2,2), ( if pp[off] > cls2 then color.green else color.red), no );
addchartbubble(show_bubbles and x, r1[off] , "R1: " + r1[off] + " diff: " + round(r1[off] - cls2,2), ( if r1[off] > cls2 then color.green else color.red), yes);
addchartbubble(show_bubbles and x, r2[off] , "R2: " + r2[off] + " diff: " + round(r2[off] - cls2,2), ( if r2[off] > cls2 then color.green else color.red), yes);
addchartbubble(show_bubbles and x, r3[off] , "R3: " + r3[off] + " diff: " + round(r3[off] - cls2,2), ( if r3[off] > cls2 then color.green else color.red), yes);

# draw lines at pivot levels, for x bars
#input line_length = 20;
#def xline = if (bn > line_length and ( !isnan(close) and isnan(close[-line_length]))) then 1 else 0;

# draw lines at pivot levels, on the current day
def xline = if getday() == getlastday() then 1 else 0;

plot s3line = if xline then s3 else na;
plot s2line = if xline then s2 else na;
plot s1line = if xline then s1 else na;
plot ppline = if xline then pp else na;
plot r1line = if xline then r1 else na;
plot r2line = if xline then r2 else na;
plot r3line = if xline then r3 else na;
s3line.setdefaultcolor(color.gray);
s2line.setdefaultcolor(color.gray);
s1line.setdefaultcolor(color.gray);
ppline.setdefaultcolor(color.gray);
r1line.setdefaultcolor(color.gray);
r2line.setdefaultcolor(color.gray);
s3line.setdefaultcolor(color.gray);
#``````

chart study , of pivot levels
[/code]

This is wonderful! I was looking for a separate column study for each pivot. I just used S1 as an example. Ideally, I'd like to look and see at a glance where a stock's price is relative to each pivot but on the watchlist itself.

### Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
437 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• 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?