Trading metric
Profit Factor Calculator
Divide the total money made on winning trades by the total lost on losing trades to get the profit factor, a single number that summarizes a strategy's track record.
What the profit factor is
The profit factor is the ratio of gross profit to gross loss over a set of trades: the total earned on all winners divided by the total given back on all losers, with the loss figure taken as a positive number. A profit factor of 1.4 means the strategy made 1.40 units of profit for every 1.00 unit of loss across the sample.
A value above 1 means gross profits exceeded gross losses over the period, while a value below 1 means the reverse. Because it rolls win rate and the size of wins and losses into a single figure, the profit factor is a compact way to summarize a track record. It says nothing, though, about how those results were distributed, so a single huge winner can flatter the number while hiding a string of losses.
Why the profit factor is used
The profit factor is a staple of strategy reports and backtests because it is easy to read at a glance and comparable across different systems. It is usually examined alongside the number of trades in the sample, the largest winning and losing trades, and the drawdown, since a high profit factor built on very few trades is far less reliable than one built on hundreds.
It describes past results over a specific sample and is not a forecast. How much confidence to place in it is entirely your own judgment.
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
You entered the totals by hand here. When a strategy is coded and backtested on TradingView, the Strategy Tester reports the profit factor for you, and you can also compute it directly from strategy.grossprofit and strategy.grossloss. The work is turning your rules into a strategy that produces those totals in the first place.
//@version=6
strategy("Profit Factor Example", overlay=true)
// ... your entry and exit rules go here ...
pf = strategy.grossloss > 0 ? strategy.grossprofit / strategy.grossloss : na
plot(pf, "Profit factor")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.