Worden Stochastics For ThinkOrSwim

Thanks to the work of @Svanoy we can do this. This thread : https://usethinkscript.com/threads/rank-volume-1-10.9504/#post-86497 had the key to figuring out ranks, and then this was simple. It seems like an interesting oscillator.

Code:
declare lower;

input length = 12;
input k = 3;
input d = 5;
input OS = 20;
input OB = 80;

def rank = fold i=1 to length with rankcounter=0 do if close>GetValue(close,i) then rankcounter+1 else rankcounter;

def w = ( 100 / ( length – 1 ) ) * Rank;

plot Worden = SimpleMovingAvg(w, k);
plot signal = SimpleMovingAvg(Worden, d);

plot OverSold = OS;
plot OverBought = OB;

Worden.SetDefaultColor(color.yellow);
signal.SetDefaultColor(color.blue);
OverSold.SetDefaultColor(color.gray);
OverBought.SetDefaultColor(color.gray);

Happy Trading,
mashume
 
Last edited:
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.

Happy Trading,
mashume
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
574 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

What are the benefits of VIP Membership?
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.
Back
Top