I am VERY green to coding and am struggling to figure out how to get thinkscript to use a close value from a previous period. I want to calculate after hours gap values by using the absvalue (open-priordayclose) but cant seem to figure out how to do that. any help is appreciated very much. thank you!
Assuming you're working on a day chart, this should get you going:
Code:
declare lower;
plot data = open - close[1];
plot zero = 0;
We can use the bracket notation to reference previous candles, so that [1] indicates "1 bar ago". There is an implicit [0] with the open as I used it. That is, if you don't put a number in brackets, it automatically assumes the last candle:
Code:
open == open[0]
and
close == close[0]
You can reference future bars using negative numbers, but be aware that this is the largest single culprit for repainting studies and un-produceable results in backtests. It has uses, but just be careful that [1] is one bar ago and [-1] is one bar from now.
Assuming you're working on a day chart, this should get you going:
Code:
declare lower;
plot data = open - close[1];
plot zero = 0;
We can use the bracket notation to reference previous candles, so that [1] indicates "1 bar ago". There is an implicit [0] with the open as I used it. That is, if you don't put a number in brackets, it automatically assumes the last candle:
Code:
open == open[0]
and
close == close[0]
You can reference future bars using negative numbers, but be aware that this is the largest single culprit for repainting studies and un-produceable results in backtests. It has uses, but just be careful that [1] is one bar ago and [-1] is one bar from now.
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.
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.