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