# Risk / Position Calculator based on prior bar range

#### Jaaackjack

##### New member
VIP
Amazing!! Is it possible to use this script
and come up with a position size calculator based off of a \$ of risk that I input into the study?

So it would take my risk \$ amount and calculate how many shares I could buy based off of the risk being the prior bar's range?

I look to take entries after the break of the prior bar's high or low so this would be phenomenal

Is it possible to create a label that displays the max number of shares I can trade based on my input risk \$ amount with a stop the size of the prior bar's range?

For example if I want to go short with a protective stop above or below the prior bar on \$500 of risk, and the prior bar's range is \$0.13, then I could short up to 3,846 shares. My entry trigger's at the break of the prior bar's high or low.

Any help much appreciated! I've looked around and searched through the forums but I can't find anything that factors risk based on the prior bar's range. Though there is 1 study that uses the current bar's range, however that doesn't help me for my entries and stops since it's based on prior bar not current bar.

Last edited by a moderator:
Solution
For anyone that could use a risk calculator / position size calculator based on the prior bar's range and a customizeable amount of risk - I had chatGPT write a script for this and it's perfect, exactly what I needed.

What a time to be alive.

Code below and screen shot for reference

input riskAmount = 100;

declare lower;

# Calculate the prior bar's range
def priorBarRange = high[1] - low[1];

# Calculate the number of shares you can trade
def sharesToTrade = riskAmount / priorBarRange;

# Create a label to display the shares to trade
For anyone that could use a risk calculator / position size calculator based on the prior bar's range and a customizeable amount of risk - I had chatGPT write a script for this and it's perfect, exactly what I needed.

What a time to be alive.

Code below and screen shot for reference

input riskAmount = 100;

declare lower;

# Calculate the prior bar's range
def priorBarRange = high[1] - low[1];

# Calculate the number of shares you can trade
def sharesToTrade = riskAmount / priorBarRange;

# Create a label to display the shares to trade

#### Attachments

• thinkorswim_iUiqVZjfZd.png
32.5 KB · Views: 197

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