♥ 0 |
Due to the limitation of using secondary aggregation on scans, I want to calculate the 200 weekly MA in a different way: I am trying to get 200 weekly MA with your suggested method. def newWeek = GetWeek() <> GetWeek()[1]; def closeLastWeek = if firstdayofweek then close else plot = average(closelastweek, 200); But the result doesn’t equal the 200 weekly MA. Any idea to solve it?
Marked as spam
|
Private answer
I updated the title of your question so that it correctly describes the context of your request. There is no solution to this request and I will take a few minutes to explain the issues and what is lacking in the Thinkorswim language to make something like this possible. First off, this is not a "suggested method" that I have published for computing a moving average. That section of code you copied was for a completely different purpose. It was provided along with a solution for a chart strategy to buy on the first trading day of the week. I applaud your effort to try and make it work for this solution but there are issues that make this entirely impossible on Thinkorswim. Specifically, Thinkorswim lacks the ability to create a custom sized array. A solution of this type requires that you create a custom sized array of 200 elements. In a real programming language we could do what you are trying to do. But Thinkorswim is a very basic scripting language. The next hurdle that makes this impossible to do on Thinkorswim is actually more important. The historical data available to scans on Thinkorswim are limited based on the selected time frame. Details here: https://toslc.thinkorswim.com/center/howToTos/thinkManual/Scan/Stock-Hacker/studyfilters You will find that you would need to use the daily time frame at the very minimum in order to have access to 200 weeks worth of historical data for your scan. You did not mention which time frame you were trying to apply this too. But daily time frame is the bare minimum. I suggest you reconsider why you are trying to do this in the first place. If you want to find stocks that are trading above or below the 200 week moving average, just use a weekly time frame for your Study Filter. If you want to find stocks that have just crossed their 200 week moving average, just use the weekly time frame. There are very few reasons I can think of that would truly require building this scan on a lower time frame. But you did not include any of those details so I cannot offer any other suggestions to help you achieve your goals. There is a very slim chance something like this can be created using the "fold" looping structure in Thinkorswim. But the mental gymnastics required to work out that code would be enough to drive a really good programmer stark raving mad.
Marked as spam
|
Please log in to post questions.