Previous month close for scanner


Category:
0
0

Hi Pete,

I am trying to build a scanner to find stocks where 30m candle is crossing previous month close. I am stuck right now as it does not allow me to use aggregation period for 30m time frame scan. How do I get previous month’s close in my code?

Thank you.

Sunil.

Marked as spam
Posted by (Questions: 1, Answers: 0)
Asked on May 28, 2021 1:43 pm
127 views
0
Private answer

This sort of solution has already been provided in various forms, but not for the monthly time frame. The method is the same, we just use a function named "GetMonth()" in place of "GetDay()" or "GetWeek()".

There is a limit to the amount of historical data available to the Study Filters of any scan. The historical data limit is based on the time frame selected. For the 30 minute time frame, the Study Filter is only able to look back about 11 trading days. This is not sufficient to accomplish what you have requested using the 30 minute time frame.

Details Here:

https://tlc.thinkorswim.com/center/howToTos/thinkManual/Scan/Stock-Hacker/studyfilters

Of all the links to the Thinkorswim language reference, this one is the most commonly used in this forum. Many users of Thinkorswim are not aware of the historical data limits for Study Filters in custom scans.

I can provide the code for this. However due to the limitations just explained, it will only work for time frames of 1 hour or higher. Anything less than 1 hour time frame will fail.

def newMonth = GetMonth() <> GetMonth()[1];
rec monthlyClose = if newMonth then close[1] else monthlyClose[1];
rec previousMonthlyClose = if newMonth then monthlyClose[1] else previousMonthlyClose[1];
plot scan = close[1] < previousMonthlyClose[1] and close > previousMonthlyClose;

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on May 28, 2021 3:05 pm