Help with extending Pivots to the right indefinitely

hedgestan

New member
VIP
Hi, I'm trying to figure out how to extend the Woodies Pivot from the previous time period to the right. This is the standard Woodies Pivot Script.

This study is using the yearly timeframe to plot pivots.

Code:
``````#
# TD Ameritrade IP Company, Inc. (c) 2009-2020
#

input timeFrame = {default DAY, "2 DAYS", "3 DAYS", "4 DAYS", WEEK, MONTH, "OPT EXP", QUARTER, YEAR};
input showOnlyToday = no;

def highByPeriod = high(period = timeFrame)[1];
def lowByPeriod = low(period = timeFrame)[1];
def openByPeriod = open(period = timeFrame);
def closeByPeriod = close(period = timeFrame)[-1];

plot R3;
plot R2;
plot R1;
plot PP;
plot S1;
plot S2;
plot S3;

if showOnlyToday and !IsNaN(closeByPeriod)
then {
R1 = Double.NaN;
R2 = Double.NaN;
R3 = Double.NaN;
PP = Double.NaN;
S1 = Double.NaN;
S2 = Double.NaN;
S3 = Double.NaN;
} else {
PP = (highByPeriod + lowByPeriod + 2 * openByPeriod) / 4;
R1 = 2 * PP - lowByPeriod;
S1 = 2 * PP - highByPeriod;
R2 = PP + R1 - S1;
S2 = PP + S1 - R1;
R3 = R2 + R1 - PP;
S3 = S2 + S1 - PP;
}

PP.SetDefaultColor(GetColor(0));
R1.SetDefaultColor(GetColor(5));
R2.SetDefaultColor(GetColor(5));
R3.SetDefaultColor(GetColor(5));
S1.SetDefaultColor(GetColor(6));
S2.SetDefaultColor(GetColor(6));
S3.SetDefaultColor(GetColor(6));

PP.SetStyle(Curve.SHORT_DASH);
R1.SetStyle(Curve.SHORT_DASH);
R2.SetStyle(Curve.SHORT_DASH);
R3.SetStyle(Curve.SHORT_DASH);
S1.SetStyle(Curve.SHORT_DASH);
S2.SetStyle(Curve.SHORT_DASH);
S3.SetStyle(Curve.SHORT_DASH);

def paintingStrategy = if timeframe == timeframe.WEEK then PaintingStrategy.LINE_VS_TRIANGLES else if timeFrame == timeFrame.MONTH or timeFrame == timeFrame."OPT EXP" or timeFrame == timeFrame.QUARTER or timeFrame == timeFrame.YEAR then PaintingStrategy.LINE_VS_SQUARES else PaintingStrategy.LINE_VS_POINTS;

PP.SetPaintingStrategy(paintingStrategy);
R1.SetPaintingStrategy(paintingStrategy);
R2.SetPaintingStrategy(paintingStrategy);
R3.SetPaintingStrategy(paintingStrategy);
S1.SetPaintingStrategy(paintingStrategy);
S2.SetPaintingStrategy(paintingStrategy);
S3.SetPaintingStrategy(paintingStrategy);``````

Hello, I have compiled a study from multiple internet searches and due to my lack of coding knowledge, I don't know how to continue. I would like to have all the open high low and close values extended indefinitely to the right. I was able to find a piece of code that did this perfectly to only the previous day. Can someone please help modify this code so all of the OHLC values on the chart extend all the way like the most recent line in the chart does? thanks!

Edit: I would also like a way to show the actual price value on the left side of the chart. all help is greatly appreciated!

this is what I've got so far.

Code:
``````declare hide_on_daily;
input aP = {default day, week, month, quarter};
input length = 1;
input displace = 1;
input showOnlyLastPeriod = no;

def BeyondlastBar = IsNaN(close[1]);

def PrevDayClose = if !BeyondlastBar then Highest(close(period = aP), length)[1] else PrevDayClose[1];
def closeSource = if (BeyondlastBar and BeyondlastBar) then closeSource[1] else PrevDayClose;
plot CloseLine = if showOnlyLastPeriod and !IsNaN(close(period = aP)[1]) then Double.NaN else closeSource;
CloseLine.SetDefaultColor(Color.WHITE);
CloseLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def PrevDayOpen = if !BeyondlastBar then Highest(open(period = aP), length)[1] else PrevDayOpen[1];
def openSource = if (BeyondlastBar and BeyondlastBar) then openSource[1] else PrevDayOpen;
plot OpenLine = if showOnlyLastPeriod and !IsNaN(open(period = aP)[-1]) then Double.NaN else openSource;
OpenLine.SetDefaultColor(GetColor(1));
OpenLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def PrevDayHigh = if !BeyondlastBar then Highest(high(period = aP), length)[1] else PrevDayhigh[1];
def highSource = if (BeyondlastBar and BeyondlastBar) then highSource[1] else PrevDayhigh;
plot highLine = if showOnlyLastPeriod and !IsNaN(high(period = aP)[1]) then Double.NaN else highSource;
highLine.SetDefaultColor(Color.WHITE);
highLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def PrevDayLow = if !BeyondlastBar then Highest(low(period = aP), length)[1] else PrevDayLow[1];
def LowSource = if (BeyondlastBar and BeyondlastBar) then lowSource[1] else PrevDaylow;
plot LowLine = if showOnlyLastPeriod and !IsNaN(low(period = aP)[1]) then Double.NaN else lowSource;
lowLine.SetDefaultColor(Color.WHITE);
lowLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);``````

Last edited:
both of your explanations are confusing, to my understanding....

youre just trying to make it so the yellow line (from the picture above) is automatically drawn? if thats not what you mean you will have to post screenshots with a better explination.

Not the exact question you're looking for?

87k+ Posts
410 Online

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?