Plot Yesterday's Date

Q

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!
 
Welkin

Welkin

Active member
VIP
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:
Q

qaw

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

Welkin

Active member
VIP
@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.
 
Q

qaw

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

Welkin

Active member
VIP
@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:
Q

qaw

New member

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

Top