Skip to content

othmarodev/position-size-calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Position Size Calculator + Trade Planner

Pro position-size calculator with full trade planner.
Live FX, crypto, and metals prices. Multi-currency. Single HTML file.

Live demo

Live data 16 instruments 8 currencies Single file MIT


✦ What it does

Plans a complete trade order in one place — give it your balance, risk %, direction, stop, and R:R target, and it returns Entry · SL · TP prices ready to paste into your broker, plus risk metrics, lot breakdown, and a visual price ladder.

  • 📡 Live prices — FX (Frankfurter ECB), Crypto (Binance + CoinGecko fallback), Metals (goldprice.org → Gemini → Kraken cascade)
  • 💱 Multi-currency accounts — USD · EUR · GBP · CHF · JPY · AUD · CAD · NZD with automatic conversion
  • 📊 16 instruments — 9 FX pairs, 2 metals (XAU, XAG), 3 indexes (US30, NDX, SPX500), 2 crypto (BTC, ETH)
  • 🎯 Two stop modes — Pips distance OR explicit Entry/SL prices (direction auto-detected)
  • ⚖️ R:R target — presets (1:1, 1:1.5, 1:2, 1:3, 1:5) + custom input
  • 🛡️ Manual lot override — type any lot size and all metrics recalculate around it
  • 📋 Copy-to-clipboard — one button copies the full order plan
  • 📈 Visual price ladder — SL · Entry · TP positions at a glance
  • 🌐 Bilingual — ES / EN toggle, full UI translation
  • 📱 Mobile-first — responsive down to 360px
  • Gold market awareness — detects CME Globex closed hours, freezes price + warns

✦ Try it

Live demo on GitHub Pages

Or clone and open index.html in any browser. No build, no install.

git clone https://github.com/othmarodev/position-size-calculator.git
cd position-size-calculator
open index.html

✦ The math

Risk $       = Balance × (Risk% / 100)
Entry        = Live market price (or your typed limit)
SL price     = Entry ∓ (Stop pips × Pip Size)         [- for Long, + for Short]
TP price     = Entry ± (Stop pips × Pip Size × R:R)   [+ for Long, - for Short]
Pip Value $  = Lot × Pip Size × Conv(quote → account ccy)
Lot Size     = Risk $ / (Stop pips × Pip Value $)
Margin       = (Units × Entry) / Leverage
Profit $     = Risk $ × R:R                            (if TP fills)

Currency conversion uses cross-rates from a single USD-based table refreshed daily from the ECB via Frankfurter.

✦ Live data sources

Source What Refresh Reliability
Frankfurter (ECB) FX rates Daily High — official central bank data
Binance BTC, ETH 10s polling High — direct exchange ticker
CoinGecko BTC, ETH fallback 10s polling Medium — aggregator
goldprice.org XAU, XAG 30s polling High — spot reference
Gemini PAXG XAU fallback 30s polling Medium — tokenized gold ±0.5%
Kraken XAUT XAU fallback 2 30s polling Medium — tokenized gold ±0.3%
CoinGecko PAXG/KAG Metals secondary 10s polling Medium
Indexes (US30, NDX, SPX500) constant estimate Low — verify with broker

All sources are CORS-open and require no auth. Indexes use constant estimates because no good public API exists — for serious index sizing, verify your broker's contract specs.

✦ Tech

  • Pure vanilla — single 1400-line index.html
  • One dependency — Tailwind via CDN (for the dense styling). No npm, no build, no framework.
  • Custom canvas-free design — pure HTML/CSS for the price ladder and all visual elements
  • Bilingual i18n — embedded ES/EN dictionary, instant switching
  • Pause when hiddenvisibilitychange pauses polling when the tab isn't active

✦ Browser support

ES2018+. Tested on Chrome, Safari, Firefox, Edge. Works on iOS Safari and Chrome mobile.

✦ Origin

Originally a tool inside TraderLoft — a cinematic 3D hub for trading products. Extracted as a standalone open-source utility because position sizing is fundamental, and most online calculators are either bloated, ad-laden, or wrong about pip values across instruments.

✦ Disclaimer

This is a planning tool, not financial advice. Live prices have a slight delay vs your broker execution. Always verify specs and exact prices before sending an order. The author assumes no responsibility for trading losses.

✦ License

MIT — see LICENSE. Use it, fork it, embed it, ship it.


Built with code, curiosity, and ☕ — from 🇨🇷 San José, Costa Rica · by Othmaro Fallas

About

Pro position-size calculator + trade planner. Live FX/crypto/metals prices, multi-currency, leverage/margin, direction + R:R → Entry/SL/TP ready to paste. Single-file HTML.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages