# Plotting future and past offsets

#### Englewood85

##### New member
I am plotting this:

Code:
``plot opening = open [-1];``

The thinkScript documentation says that a negative offset refers to future candlesticks and that a positive offset refers to previous candlesticks. However when I run this script, the opening price for any given day is not plotted on the next candlestick forward, but instead it is plotted on the previous candlestick.

I can't make sense out of this. Can somebody explain how this works?

Solution
But why is the script plotting the opening price on the previous candlestick?

That's by design.

Please note: The [] has at least two roles:
1. Offsets of past/future data
2. Displacers of data to the left or the right.
These roles are not in contradiction with each other, and you can use them interchangeably, but just make sure you understand what you're doing at the time, since neither one negates the other one, and they remain in agreement.

That is, not only does open[4]] SHIFT the open price 4 bars to the right displace, it also plots the open price from 4 bars in the PAST past offset.

References...
But why is the script plotting the opening price on the previous candlestick?

I plotted both of these:

Code:
``````plot openingPriceNext = open [1];                 #prices shift forward by 1 candlestick

plot openPricePrior = open [-1];                                 #prices shift backward by 1 candlestick``````

The first line shifted the opening prices forward by 1 candlestick (documentation says it should shift backward).
The second line shifted the opening prices backward by 1 candlestick (documentation says it should shift forward).

1. Was thinkScript changed so that the offset now works the way it "should?"
2. If not, they why doesn't the plot for the 1st line shift backward? Why doesn't the plot for the 2nd line shift forward?

Last edited:
But why is the script plotting the opening price on the previous candlestick?

That's by design.

Please note: The [] has at least two roles:
1. Offsets of past/future data
2. Displacers of data to the left or the right.
These roles are not in contradiction with each other, and you can use them interchangeably, but just make sure you understand what you're doing at the time, since neither one negates the other one, and they remain in agreement.

That is, not only does open[4]] SHIFT the open price 4 bars to the right displace, it also plots the open price from 4 bars in the PAST past offset.

References:
https://tlc.thinkorswim.com/center/...dvanced/Chapter-12---Past-Offset-and-Prefetch
https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/C-D/Displacer

1. Was thinkScript changed so that the offset now works the way it "should?"

No. The offset and displace are two peas in the same pod.

2. If not, they why doesn't the plot for the 1st line shift backward? Why doesn't the plot for the 2nd line shift forward?

The [] has two uses
1. Past/Future offset of data
2. Displacing plots on screen. (this is why the script is plotting the opening price on the previous candlestick)

These two uses do not conflict with each other, so you could choose one or the other (just keep in mind that both are true at the same time).

In other words, the offset feature for past/future data can also be used as a "displacer" to reposition data to the left or the right on-screen.

At the same time, [-1] works as an offset to shift the plot back one.

Think of the [] as a continuum with dual usage:

negative numbers = future offset/displace backwards
positive numbers = past offset/displace forwards

Your plots of the PAST should appear to the RIGHT of the data, but your plots of the FUTURE should appear to the LEFT of the data.
Keep in mind that you can't make a request on data that doesn't exist yet, per the thinkscript offset page, and this is why a negative [] will offset your plotted data to the left.

from the thinkscript offset page:
if we specify a future offset in this expression using a negative index:

plot data = close [-1];
the study will wait for a new quote in order to calculate the value for the second latest bar. Basically, this script plots the close price of the next bar as soon as there is a quote for it.

from the thinkscript displacer page:
Displacer
Description
The Displacer study is used to shift the selected price line forward or backward for a defined number of bars.

Think of the bar offsets as a continuum:

3 2 1 0 -1 -2 -3

So, open[-1] = open 1 bar into the future (aka, the next bar)
open[-2] = the open 2 bars into the future
open[-3] = the open 3 bars into the future
... and so on.

As stated previously:
negative numbers = future offset/displace backwards
positive numbers = past offset/displace forwards

To better illustrate this, try the code below in a STUDY.
Notice that the WHITE future plots show up displaced to the left (they have to wait for the future to happen before they can plot)
Notice that the BLUE past plots show up displaced to the right (they are plotting what already happened, so they don't have to wait for data).

Hope this helps.

Code:
``````plot future = open[-4];
future.setpaintingstrategy(paintingStrategy.HORIZONTAL);
future.setDefaultColor(color.white);
future.setLineWeight(5);

plot past = open[4];
past.setpaintingStrategy(paintingSTrategy.horizontal);
past.setDefaultColor(color.blue);
past.setLineWeight(5);``````

87k+ Posts
250 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
• 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?