thinkScript GetDay() and GetWeek() Functions

marketstreet

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:

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

XeoNoX

Well-known member
VIP
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:

Code:
# High in last quarter

# Mobius

# Chat Room Request 06.30.2020



def month = getMonth();

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

addVerticalLine(QtrStart);

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

Top