Count price movement in percent and then cluster them?

strategynode

New member
I was wondering if there is a way to do the following -- (End result should be labels)

I want to calculate the % move of each candle for say 12 bars and then 3 labels based on that data

Label for All bars (The numbers below is just for example purposes)
Between 10% - 5% = 3 out of 12
Between 5% - 2% = 5 out of 12
Less Than 2% = 4 out of 12

The color of the bar or direction doesn't really matter if we could do another set of labels based on the direction on top of the cumulative that would be really cool

Label for Green Bar
Total Green Bars ( 5 out of 12)
Between 10% - 5% = 1 out of 5
Between 5% - 2% = 2 out of 5
Less Than 2% = 2 out of 5

Label for Red Bar
Total Red Bars ( 7 out of 12)
Between 10% - 5% = 2 out of 7
Between 5% - 2% = 2 out of 7
Less Than 2% = 3 out of 7

Any guidance will be very helpful. Thank You.
 
If the candles you're watching are really moving 5% to 10% per candle, that's some WILD volatility. But that aside...

If it were me coding it, I'd create series for each of your sets, such that if the range of the candle falls within the range, the series value is set to 1 and if it is not within range, the series is set to 0.
Code:
def small_mover = if (close - close[1]) / close[1] <= 0.02 then 1 else 0;
and repeat for each of the series you wish to create.
To create labels for them then, all that is required is to do a sum over your intended length:
Code:
input length = 12;
addLabel(yes, "Less than 2%: " + sum(small_mover, length) + " out of " + length, color.pink);

You will, of course, want to be a bit more thorough with your binning and how you present the data, but this should get you going in one direction that may pan out.

Happy Trading,
mashume

P.S. All code written here, in the post editor, and NOT in ThinkOrSwim. It may not run at all.
 

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

If the candles you're watching are really moving 5% to 10% per candle, that's some WILD volatility. But that aside...

If it were me coding it, I'd create series for each of your sets, such that if the range of the candle falls within the range, the series value is set to 1 and if it is not within range, the series is set to 0.
Code:
def small_mover = if (close - close[1]) / close[1] <= 0.02 then 1 else 0;
and repeat for each of the series you wish to create.
To create labels for them then, all that is required is to do a sum over your intended length:
Code:
input length = 12;
addLabel(yes, "Less than 2%: " + sum(small_mover, length) + " out of " + length, color.pink);

You will, of course, want to be a bit more thorough with your binning and how you present the data, but this should get you going in one direction that may pan out.

Happy Trading,
mashume

P.S. All code written here, in the post editor, and NOT in ThinkOrSwim. It may not run at all.
I am so sorry I just saw after two months that you had replied. Thank you so much for this I really appreciate even thou its two months late thank you hope you feel appreciated for your response.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
343 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