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

Englewood85

New member
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.

This means that [-1] is asking about the NEXT candlestick.
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);

eE4puuj.png
 
Solution

Similar threads

Top