Help with Position Size Script for 1% Risk Based on Account Size and Stop-Loss

mattastic1

New member
Hey everyone,


I’m looking for some help creating a Thinkscript that can calculate the number of contracts I should trade based on my account size, risk percentage, and stop-loss distance.



Here’s what I’m trying to do:

• Input my account size (manually updated daily is fine).

• Use a fixed risk percentage (e.g., 1% of my account).

• Automatically calculate the number of contracts based on the entry price and stop-loss distance. (On the contracts chart 📈 on thinkorswim if this label could show up so the # of contracts adjusts automatically based on current price)

• And then Display the result as a label on the chart 📈 (e.g., “Contracts to Trade: X”).




Right now, I manually calculate this on google sheets for every trade and sometimes that is where emotionally I break a rule “since I didn’t update the latest price let’s say from $1.30 to $1.10 for example (my current stop loss is based on a 20% Stop Loss upon entry) so if that same percentage stop loss method can be used on the CHART WINDOW AS A LABEL… and dynamic price I feel like it will be a huge help for me or anyone who needs that disciplined entry!! ,

I’m assuming someone has automated it. Is it possible to also pull the entry price or stop-loss from the chart or current market data to make it more dynamic?


Any ideas or examples to get started? Thanks in advance!

This is what the code somewhat could be like:

Thinkscript Code

# Input parameters
input AccountSize = 10000; # Set your account size (update daily if needed)
input RiskPercent = 1.0; # Set your risk percentage per trade (e.g., 1%)
input EntryPrice = 1.20; # Adjust to your planned entry price
input StopLossPrice = (20% of the current price) # Adjust to your planned stop-loss price


# Calculations
def DollarRisk = AccountSize * (RiskPercent / 100);
def StopLossDistance = EntryPrice - StopLossPrice;
def Contracts = if StopLossDistance > 0 then Round(DollarRisk / (StopLossDistance * 100), 0) else Double.NaN;


# Display labels
AddLabel(yes, "Contracts to Trade: " + Contracts, Color.GREEN);
AddLabel(yes, "Risk per Trade: $" + AsDollars(DollarRisk), Color.CYAN);
AddLabel(yes, "Stop-Loss Distance: " + StopLossDistance, Color.YELLOW);

Something like that…
 

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
373 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