So in TC2000, the Wordens have their own version of Stochastics. Here is some background on it. Has anyone converted this for ThinkOrSwim? My guess it's not too hard to do. Thanks!
TL;DR: please update your code with the new version above. Below is the story of why.
I believe I introduced a mathematical error into this via copy paste and not thinking.
When I ran it as originally posted, and at the default length, it looked passably correct. When I adjusted the length to 30 I noticed that the indicator line maxed out at 70. This was strange. Turns out it was maxed at 88 with the default length of 12.
It's a simple order of operations error, a lack of parentheses, and the difference between 0 and 1 indexed lists.
Code:
def w = (100/length – 1) * Rank;
should have been
Code:
def w = (100/(length – 1)) * Rank;
That gets us the canonical formula for the Worden Stochastic. HOWEVER I used a 1 indexed list of positions not a zero indexed. If you think abuout that for a minute, you'll see this with a length of 26 and the highest value candle (number 26):
Code:
w = ( 100 / ( length - 1 ) ) * rank
w = ( 100 / ( 26 - 1 ) ) * 26
w = ( 100 / ( 25 ) ) * 26
w = 4 * 26
w = 104
Not Good.
So we actually, for this implementation, need to replace the original code with:
Code:
def w = ( 100 / ( length - 1 ) ) * ( Rank - 1 );
And then our maths should all work out for an indicator that will go from 0 to 100. If we had just used a zero indexed list it might have been simpler, but that's life. But since code isn't life, we'll change to a zero-indexed ranking list and save ourselves a little bit of processor cycling for the extra subtraction:
Code:
def rank = fold i=1 to length with rankcounter=0 do if close>GetValue(close,i) then rankcounter+1 else rankcounter;
If your strategy for this used crossovers, nothing really changed. but if you relied on OS and OB levels, it's a different story.
For all of you who made it this far through my pre-coffee rambling, thank you. This one actually kept me awake for a while puzzling it out.
useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.
How do I get started?
We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.
If you are new, or just looking for guidance, here are some helpful links to get you started.
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.