thinkScript GetDay() and GetWeek() Functions


New member
How can I create the same functionality as the GetDay(), GetWeek(), GetMonth(), or GetYear() functions for other time frames like Hour, Quarter, etc.?

I have tried constructing synthetic aggregation periods (e.g. combining 3 months for one quarter) but nothing plots correctly. Thank you.

Sample code:

def isToday = getDay() == getLastDay();
Last edited:


Well-known member
For getting the hour you can use secondsfromtime/tilltime

For quarter plotting in thinkscript here is code to do quarterly here is an example by mobius:

# High in last quarter

# Mobius

# Chat Room Request 06.30.2020

def month = getMonth();

def QtrStart = month[1] % 3 == 0 and month % 3 != 0;


def lstBar = if QtrStart

then barNumber()

else lstBar[1];

def fstBar = if QtrStart

then lstBar[1]

else fstBar[1];

def hh = if barNumber() == HighestAll(fstBar)

then high

else if between(barNumber(), highestAll(fstBar), highestAll(lstBar))

then Max(high, hh[1])

else hh[1];

plot hh_ = if barNumber() >= highestAll(fstBar)

then highestAll(if isNaN(close[-1])

then (hh)

else double.nan)

else double.nan;

# End Code

Similar threads