# 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.

mashume

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

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.

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.

87k+ Posts
419 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?