Referencing Daily High On A 1 Minute Aggregation


Category:
0
0

Hey everyone!

 

Pete, thank you so much for helping me with my “Display time between bars” question. I have a watchlist full of stocks. I have a custom column with the code below. The watchlist is set to a 1minute chart aggregation. I want the watchlist to sort the stocks that are at their intraday high but also had a trade within the past 2 minutes. This is the start to my code but it seems like ToS will not calculate the values because of the Daily aggregation period. Any ideas?

 

def data1 = GetTime() / 1000 / 60;
def data2 = data1 – data1[1];

def agg = AggregationPeriod.DAY;
def hi = high(period = agg);
def lo = low(period = agg);

plot data = hi;

Marked as spam
Posted by (Questions: 8, Answers: 5)
Asked on August 3, 2020 3:33 pm
135 views
0
Private answer

That is correct, we cannot use secondary aggregation periods within anything on Thinkorswim except for chart studies and chart strategies.

The only solution is to use recursion. We need to check for the first bar of a new trading session, then capture the high and low on that bar. Then use recursion to check each of the following bars to see if the current high is greater than the previous highest bar for the session, likewise for the low.

def newDay = GetDay() <> GetDay()[1];
rec trackHigh = if newDay then high else if high > trackHigh[1] then high else trackHigh[1];
rec trackLow = if newDay then low else if low > 0 and low < trackLow[1] then low else trackLow[1];
plot currentSessionHigh = trackHigh;
#plot currentSessionLow = trackLow;

In a watchlist you can only plot one value so I have included a plot statement for both but the session low is commented out so it will not create an error.

Marked as spam
Posted by (Questions: 37, Answers: 4086)
Answered on August 3, 2020 6:26 pm