npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

pipcalc

v1.0.0

Published

Pip value, position size, risk/reward and drawdown maths for forex, gold, indices and crypto traders. Zero dependencies, with a CLI.

Readme

pipcalc

Pip value, position size, risk/reward and drawdown maths for traders. Forex, gold, indices and crypto. Zero dependencies, fully typed, with a command-line tool.

CI npm License: MIT

$ npx pipcalc size EURUSD --balance 10000 --risk 1 --stop-pips 20
0.5 lots (50,000 units) risks $100.00 of the $100.00 you set.

The same maths runs the order ticket and the free calculators on Candleben, where you can practise trading on real past charts.

Why

Most blown accounts aren't bad entries. They're the wrong size. pipcalc answers the questions you should ask before every trade:

  • How many lots can I take so a stop-out costs exactly 1%?
  • What is one pip worth on this pair, at this size?
  • With this stop and target, how often do I need to win just to break even?
  • I'm down 30%. What do I need to get back?

Install

npm install pipcalc

Or use the CLI without installing: npx pipcalc help.

Library

import { sizeFor, instrument, pipValue, usdPerQuoteUnit, riskReward, recoveryNeeded } from "pipcalc";

// Position size straight from prices: risk 1% of $10,000 with a 20-pip stop.
sizeFor({ symbol: "EURUSD", balance: 10_000, riskPercent: 1, entry: 1.1, stop: 1.098 });
// → { lots: 0.5, units: 50000, riskUsd: 100, targetRiskUsd: 100 }

// Gold, with the stop $10 away.
sizeFor({ symbol: "XAUUSD", balance: 5_000, riskPercent: 1, entry: 2400, stop: 2390 });
// → { lots: 0.05, units: 5, riskUsd: 50, targetRiskUsd: 50 }

// Pairs quoted in another currency need a price or a rate.
sizeFor({ symbol: "USDJPY", balance: 10_000, riskPercent: 1, stopPips: 30, price: 150 });
sizeFor({ symbol: "EURJPY", balance: 10_000, riskPercent: 1, stopPips: 30, rates: { USDJPY: 150 } });

// Pip value
pipValue(instrument("EURUSD")!, 1);                                    // → 10   ($ per pip, 1 lot)
pipValue(instrument("USDJPY")!, 1, usdPerQuoteUnit("USDJPY", 150)!);   // → 6.67

// Risk/reward
riskReward(1.1, 1.095, 1.11);
// → { side: "BUY", risk: 0.005, reward: 0.01, ratio: 2, breakevenWinRate: 0.333 }

// Drawdown
recoveryNeeded(50); // → 100 (lose half, you need to double)

API

| Function | What it gives you | | --- | --- | | sizeFor({ symbol, balance, riskPercent, stopPips \| entry+stop, price?, rates?, lotStep? }) | The largest lot size that risks no more than riskPercent. Rounded down to the lot step (0.01 by default). | | positionSize(balance, riskPercent, stopPips, pipValuePerLot, contractSize, lotStep?) | The same, from raw numbers. | | instrument(symbol) | Pip size and lot size. Any six-letter forex pair, plus gold, silver, oil, US30, NAS100, SPX500, GER40, BTCUSD and ETHUSD. | | pipValue(instrument, lots, usdPerQuote?) | Dollars per pip. | | pips(instrument, from, to) | Pips between two prices. | | usdPerQuoteUnit(symbol, price, rates?) | What one unit of the quote currency is worth in dollars. Returns null if a cross needs a rate you didn't give. | | riskReward(entry, stop, target) | Side, ratio and the break-even win rate. | | expectancy(winRate, avgWinR, avgLossR?) | Average result per trade in R. Above 0 is an edge. | | recoveryNeeded(drawdownPercent) | Percentage gain needed to get back to even. | | afterLosingStreak(balance, riskPercent, losses) | Balance after a run of losses. | | INSTRUMENTS, LOT | The built-in markets, and lot names (standard, mini, micro, nano). |

Functions return null rather than throwing when an input doesn't make sense, such as a zero stop or a target on the losing side.

Check your broker's contract specs. Pip and lot sizes for gold, indices and crypto vary between brokers. The built-ins are common defaults, and you can pass your own { symbol, pipSize, contractSize } to any function.

CLI

pipcalc size XAUUSD --balance 5000 --risk 1 --entry 2400 --stop 2390
# 0.05 lots (5 units) risks $50.00 of the $50.00 you set.

pipcalc value USDJPY --price 150
# $6.67 per pip on 1 lot of USDJPY (1 pip = 0.01).

pipcalc rr 1.1000 1.0950 1.1100
# BUY: 1 : 2.00 risk/reward. You need to win 33.3% of trades to break even.

pipcalc expectancy --win-rate 40 --avg-win 2
# +0.20R per trade on average. That's an edge.

pipcalc recover 30
# After a 30% loss you need +42.9% to get back to even.

pipcalc streak --balance 10000 --risk 2 --losses 10
# After 10 losses in a row: $8,170.73.

Results are in US dollars. Crosses take a rate: --rate USDJPY=150.

Try it without code

Prefer a web page? Use the free calculators at candleben.com/tools: position size, pip value and risk/reward. When you're ready, practise the sizing on real past charts on the Candleben replay.

Contributing

Issues and pull requests are welcome, especially more instruments and checks against broker specs.

npm install
npm test      # node --test, needs Node 22.18+ to run the TypeScript tests directly
npm run build

Licence

MIT © Apaxaa Technologies Ltd, makers of Candleben.

For education. Not financial advice. Trading carries a risk of loss.