All free tools

Risk management

Position Size Calculator

Work out how large a position to take so that a losing trade costs a fixed, chosen slice of your account. Enter your account size, risk per trade, entry, and stop.

Position size
62.50
Units, shares, or contracts to hold.
Amount at risk
250.00
Loss if the stop is hit.
Position value
6,250.00
Implied exposure
0.25x account
Within your account size.

How position sizing works

Risk-based position sizing flips the usual question around. Instead of asking how many units to buy, it starts from how much you are willing to lose on the trade and works backward to the size. First you decide the amount at risk: your account size times your risk percentage. A 1% risk on a 25,000 account is 250.

Next you find the risk per unit, the distance between your entry and your stop. Dividing the amount at risk by the risk per unit gives the position size. If the stop sits 4 away from a 100 entry, and you are risking 250, then 250 ÷ 4 is 62.5 units. Sized this way, being stopped out costs the same fixed slice of the account regardless of how far away the stop is, which keeps losses consistent across trades with different setups.

Why position sizing matters

Consistent position sizing is one of the main tools for keeping the size of losses under control, so that no single trade can do outsized damage. By fixing the percentage risked per trade, it also scales exposure up and down with the account automatically. The implied exposure figure above flags when a position would be larger than your account, which would require margin or leverage to hold.

This is a mechanical calculation from the numbers you enter, not a recommendation about how much to risk or which trades to take. Those choices are entirely your own.

What are TradingView and Pine Script?

TradingView is one of the most widely used charting and market-analysis platforms, where traders and analysts study price movement across stocks, crypto, forex, and futures on interactive charts. Pine Script is TradingView's own lightweight programming language, created so anyone can build custom tools that run directly on those charts.

People use Pine Script to build four main kinds of tools. Indicators calculate and plot values on the chart, exactly like the calculation above, but recomputed automatically on every bar. Strategies add explicit entry and exit rules and can be backtested against historical data in TradingView's Strategy Tester to see how they would have behaved. Screeners scan many symbols at once for conditions you define. Alerts notify you the moment a condition you specified occurs, so you do not have to watch the screen.

The value is precision and automation. Instead of eyeballing a chart, you describe exactly what you want measured, visualized, or notified about, and TradingView runs it consistently across any market and timeframe. That is why traders, analysts, and developers write Pine Script: it turns a manual charting idea into a repeatable tool. These tools are for tracking, visualizing, and testing market ideas; they do not tell you what to trade, and that decision always remains yours.

Writing that code by hand means learning Pine Script's syntax, its type system, and the exact names of hundreds of built-in functions. It is a real programming language, and small mistakes stop a script from compiling in the Pine Editor.

Turn this into Pine Script

Here you sized one trade by hand. In a live strategy you would want every entry sized automatically from your current equity and stop distance, so risk stays constant as the account grows or shrinks. Pine Script does the sizing with a qty passed to strategy.entry, but defining the stop and the entry logic around it is where the real code goes.

Pine Script v6
//@version=6
strategy("Risk-based Sizing", overlay=true)

riskPerc  = input.float(1.0, "Risk % per trade")
stopPrice = input.price(0.0, "Stop price")

riskAmount = strategy.equity * riskPerc / 100
qty = riskAmount / math.abs(close - stopPrice)

strategy.entry("Long", strategy.long, qty=qty)
strategy.exit("Exit", "Long", stop=stopPrice)

PineScripter is an AI built specifically for Pine Script. You describe what you want in plain English and it writes TradingView-ready v5 or v6 code. Because it is specialized on the Pine Script language and its exact function signatures, it tends to produce code that compiles far more reliably than general-purpose models like ChatGPT, which often invent functions that do not exist in Pine Script.

Related free calculators

From the blog

PineScripter is an AI developer tool that helps you write Pine Script code. It is not a financial advisor and will never offer financial, investment, or trading advice. Everything on this page, including the calculator and the explanations, is provided purely for educational and informational purposes. Any decision about how to interpret an indicator or trade a market is entirely your own. See our full disclaimer for more.