Plot Yesterday's Date

qaw

New member
Code:
plot yesterday = GetYYYYMMDD()[1];

I have tried changing the number in the [ ] but the date plotted is always today. Help pls!
 
The problem you're having is that [1] is getting the date of the previous bar for the aggregation your chart is set to, not the previous day.
What you need to do is find a point on the chart when the date is not the same value as the date of the previous bar
Code:
def YYYYMMDD = GetYYYYMMDD();
def yesterdaytest = if YYYYMMDD != YYYYMMDD[1] then YYYYMMDD[1] else yesterdaytest[1];
plot yesterday = yesterdaytest;
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@qaw The script you have provided also doesn't work on any candlestick chart that has an aggregation period of less than 1 day. On daily/weekly/monthly aggregation chart it works properly.
 
@qaw The script you have provided also doesn't work on any candlestick chart that has an aggregation period of less than 1 day. On daily/weekly/monthly aggregation chart it works properly.
it does work, made labels and even repeated the method a 2nd time for the day before yesterday.... try it again.
nR7EZO6.png
 
@Welkin My mistake Welkin. It does work. Sorry about it!

IF you are able to help, I do have one more issue. The code below doesn't work.

Code:
def YYYYMMDD = GetYYYYMMDD();
def yesterdaytest = if YYYYMMDD != YYYYMMDD[1] then YYYYMMDD[1] else yesterdaytest[1];
def yesterday = yesterdaytest;
def today = yesterday + 1;

def GlobeX = GetTime() > RegularTradingEnd(yesterday) and  GetTime() < RegularTradingStart(today);

However if I enter the date manually it will work. Example below.

Code:
def YYYYMMDD = GetYYYYMMDD();
def yesterdaytest = if YYYYMMDD != YYYYMMDD[1] then YYYYMMDD[1] else yesterdaytest[1];
def yesterday = yesterdaytest;
def today = yesterday + 1;


def GlobeX = GetTime() > RegularTradingEnd(20200929) and  GetTime() < RegularTradingStart(20200930);

I'm coding a previous after market high and low before the start of the next trading day. It's an adapted version of another code posted on this forum. I excluded the remainder to not make it messy. If you require the full code let me know. Thanks!
 
@Welkin My mistake Welkin. It does work. Sorry about it!

IF you are able to help, I do have one more issue. The code below doesn't work.

Code:
def YYYYMMDD = GetYYYYMMDD();
def yesterdaytest = if YYYYMMDD != YYYYMMDD[1] then YYYYMMDD[1] else yesterdaytest[1];
def yesterday = yesterdaytest;
def today = yesterday + 1;

def GlobeX = GetTime() > RegularTradingEnd(yesterday) and  GetTime() < RegularTradingStart(today);

However if I enter the date manually it will work. Example below.

Code:
def YYYYMMDD = GetYYYYMMDD();
def yesterdaytest = if YYYYMMDD != YYYYMMDD[1] then YYYYMMDD[1] else yesterdaytest[1];
def yesterday = yesterdaytest;
def today = yesterday + 1;


def GlobeX = GetTime() > RegularTradingEnd(20200929) and  GetTime() < RegularTradingStart(20200930);

I'm coding a previous after market high and low before the start of the next trading day. It's an adapted version of another code posted on this forum. I excluded the remainder to not make it messy. If you require the full code let me know. Thanks!
I'm pretty sure what you're wanting has already been done, check the onenote archive:
https://onedrive.live.com/redir?res...biusJQ|49928a40-424d-4236-994b-880532bf227c/)
if you can't find it there, i'll take a stab at it.
 
Last edited:

Edit: I have tried the code from the link and it does not work for stocks like Tesla on a 1 min chart.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
413 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

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?
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.
Back
Top