Trading metric
Average Down Calculator
Enter each purchase and this blends them into one average cost, then adds the round-trip fees to show the price you would actually need to break even. Works the same for averaging up, and for a dollar-cost-averaging schedule.
| Detail | Value |
|---|---|
| Total quantity | 200.0000 |
| Total cost | 9,950.00 |
| Average cost per unit | 49.7500 |
| Break-even price including fees | 49.8496 |
| Fee cost to break even | 19.92 |
| Average moved from the first entry by | 5.06% |
| Entries counted | 2 |
How average cost is calculated
The average is weighted by quantity, not by price. Add the cost of every purchase, which is each quantity multiplied by its price, then divide by the total number of units. A hundred units at fifty-two forty and a hundred at forty-seven ten gives a total cost of nine thousand nine hundred and fifty across two hundred units, so the average is forty-nine seventy-five.
Because it is weighted, the size of each purchase matters as much as its price. Buying a small amount at a much lower price barely moves the average, while buying a large amount at a slightly lower price moves it considerably. This is worth knowing before you assume a second purchase has meaningfully changed your position: the calculator reports how far the average moved from your first entry precisely so that assumption is testable.
The break-even price is a separate calculation and a more useful one. Fees are charged on the way in and again on the way out, so the exit price has to clear the average cost plus both. That is why the break-even figure sits above the average cost rather than equal to it, and why a low percentage fee matters more than it looks on a position that is averaged into several times, since each purchase pays its own entry fee.
What the arithmetic does not tell you
A lower average cost is a smaller number, and it is easy to read that as progress. It is worth being precise about what has actually changed. The average came down because more was bought, so the position is larger and the amount at stake is higher. The price at which the position breaks even is closer, and the loss if it continues to fall is greater. Both statements are true at once, and only one of them appears in the average.
This is why averaging down is a genuinely contested idea rather than a technique with a settled answer. As a planned schedule with sizes decided in advance, it is one thing. As a reaction to a position that is losing, decided in the moment, it is a different thing that happens to produce the same arithmetic. The calculator cannot tell which one you are doing, and the number it returns looks identical either way.
The practical point that follows is about the stop rather than the average. If you had a level at which you intended to exit, adding to the position does not move that level, but it does mean more units are exposed to it, so the loss at that level is larger than it was. Recalculating the total amount at risk after each addition is the check that keeps the two facts visible together. Our position size calculator and risk/reward ratio calculator work from the blended average once you have it.
Whether to average into a position at all is entirely your decision, and nothing here is a recommendation either way. This page computes an average and a break-even price, which is arithmetic, and arithmetic has no opinion.
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
Coding this in Pine Script surfaces two things the calculator does not. First, pyramiding defaults to a single entry per position, so a strategy that tries to add without raising it has its additional entries silently ignored. This is one of the more common reasons a scaling strategy shows a single entry where you expected several.
Second, strategy.position_avg_price holds the blended average for you, which is the right reference for a stop on a scaled position. A stop measured from the original entry means something different once the average has moved, and plotting the average makes that visible. The larger benefit of writing the rule as code is that the addition becomes explicit: a level, a size, and a maximum number of entries, decided in advance rather than in the moment. Our guide to position sizing in Pine Script covers how the sizing side of that works.
//@version=6
strategy("Averaging in, and its two costs", overlay = true,
// pyramiding must be raised or additional entries are ignored,
// which is why a scaling strategy often shows only one entry.
pyramiding = 3)
atrValue = ta.atr(14)
entrySignal = ta.crossover(ta.sma(close, 10), ta.sma(close, 30))
// First entry.
if entrySignal and strategy.position_size == 0
strategy.entry("Long1", strategy.long)
// Add only when price has fallen a defined amount below the current
// average, so the rule is explicit rather than discretionary.
addLevel = strategy.position_avg_price - atrValue * 1.5
if strategy.position_size > 0 and strategy.opentrades < 3 and close < addLevel
strategy.entry("Long" + str.tostring(strategy.opentrades + 1), strategy.long)
// The stop belongs on the whole position and is measured from the
// blended average, not from the original entry.
if strategy.position_size > 0
strategy.exit("Exit", stop = strategy.position_avg_price - atrValue * 3)
plot(strategy.position_size > 0 ? strategy.position_avg_price : na,
"Average entry", color = color.orange, style = plot.style_linebr)PineScripter is an AI built specifically for Pine Script. You describe what you want in plain English and it writes TradingView-ready 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.