All free tools

Position sizing

Kelly Criterion Calculator

The Kelly criterion returns the fraction of capital that maximizes long-run growth, given an edge. Enter your win probability and payoff ratio to see the Kelly fraction and the more common half-Kelly.

Kelly fraction
32.50%
Share of capital that maximizes long-run growth.
Half Kelly
16.25%
A common, more conservative choice.

What the Kelly criterion is

The Kelly criterion, published by John L. Kelly Jr. in 1956, gives the fraction of your capital to commit to a favorable bet in order to maximize the long-run growth rate of your wealth. For a bet with two outcomes it is f* = p − q / b, where p is the probability of winning, q is the probability of losing (1 − p), and b is the payoff ratio, the size of a win relative to a loss.

The intuition is that you should bet more when your edge is larger and when the payoff is more favorable, but never so much that a losing streak wipes you out. If the formula returns zero or a negative number, it is signaling that there is no positive edge to size, so nothing should be committed. Because full Kelly is notoriously aggressive and very sensitive to errors in your inputs, many people use a fraction of it, such as half-Kelly, to reduce volatility.

Why the Kelly criterion is used and its cautions

Kelly is used as a position-sizing framework that ties bet size directly to the strength of an edge, and it has a strong theoretical foundation for maximizing growth over many repeated bets. In practice its biggest weakness is that it depends entirely on knowing the true win probability and payoff, which in markets are only estimates. Overstating your edge leads Kelly to recommend dangerously large sizes.

This calculator simply evaluates the formula from the numbers you enter. It is an educational tool, not advice on how much to risk, and any sizing decision is 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 evaluated the formula once. In a strategy you might size each entry from a Kelly fraction based on your estimated edge, recalculated against current equity. Pine Script can compute the fraction and pass it as a qty to strategy.entry, but building the estimate of your edge and the surrounding rules is the real work, and where PineScripter helps.

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

winProb = input.float(0.55, "Win probability")
payoff  = input.float(2.0, "Payoff ratio (avg win / avg loss)")

kelly = winProb - (1 - winProb) / payoff
qty = kelly > 0 ? strategy.equity * kelly / close : 0.0
if qty > 0
    strategy.entry("Long", strategy.long, qty=qty)

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.