Simple and reliable Forex Calculator tools for trading analysis.
Choose your preferred package manager:
# npm package
npm install @neabyte/forex-calculator
# Deno module
deno add jsr:@neabyte/forex-calculatorCalculate optimal lot size based on account risk and stop loss distance.
import { calculateLotSize } from '@neabyte/forex-calculator'
const result = calculateLotSize({
pairName: 'XAUUSD',
openPrice: 2000,
stopPrice: 1990,
leverage: 100,
riskUSD: 100
})
console.log(result)
/*
{
info: { symbol: 'XAUUSD', timestamp: '...', type: 'METAL' },
margin: { leverage: '1:100', required: 200 },
position: { lot: 0.1, pipValue: 1, units: 10 },
risk: { amount: 100, stopDistance: 10, stopPoints: 100 }
}
*/Calculate the exact profit or loss in USD and pips for any position.
import { calculateProfit } from '@neabyte/forex-calculator'
const result = calculateProfit({
pairName: 'EURUSD',
sidePosition: 'BUY',
lotSize: 1.0,
entryPrice: 1.1,
exitPrice: 1.105
})
console.log(result)
/*
{
isProfit: true,
pips: 50,
profitUSD: 500,
sidePosition: 'BUY',
symbol: 'EURUSD',
type: 'FOREX'
}
*/Support for multiple methodologies to find support and resistance.
import { calculatePivotPoints } from '@neabyte/forex-calculator'
const result = calculatePivotPoints({
high: 1.1,
low: 1.09,
close: 1.095,
method: 'FIBONACCI'
})
console.log(result)
/*
{
method: 'FIBONACCI',
p: 1.095,
r1: 1.09882,
r2: 1.10118,
r3: 1.105,
s1: 1.09118,
s2: 1.08882,
s3: 1.085
}
*/Project account growth or analyze risk with built-in simulators.
import { simulateCompounding, calculateExpectancy } from '@neabyte/forex-calculator'
// Project compounding growth
const compound = simulateCompounding({
startBalance: 1000,
profitPerTrade: 10,
totalTrades: 2
})
console.log(compound)
/*
[
{ period: 1, startBalance: 1000, endBalance: 1100, profit: 100 },
{ period: 2, startBalance: 1100, endBalance: 1210, profit: 110 }
]
*/
// Calculate mathematical edge
const edge = calculateExpectancy({
winRate: 50,
avgWinUSD: 100,
avgLossUSD: 50
})
console.log(edge) // { expectancy: 25, potentialProfit: 1250, status: 'POSITIVE' }Simulate trading a strategy over a specific period of time.
import { calculateBacktest } from '@neabyte/forex-calculator'
const result = calculateBacktest({
initBalance: 1000,
riskAmount: 10,
tradePerDay: 1,
totalDays: 5,
winRate: 60,
rewardRatio: 2
})
console.log(result.summary)
/*
{
actualWinRate: 60,
finalBalance: 1040,
initBalance: 1000,
isProfitable: true,
netProfit: 40,
totalTrades: 5,
totalWins: 3,
...
}
*/calculateLotSize(params): ReturnsLotSizeResult. Calculates margin, lot size, and risk metrics.calculateProfit(params): ReturnsProfitResult. Calculates PnL and pip distance.calculatePivotPoints(params): ReturnsPivotResult. SupportsCLASSIC,FIBONACCI,CAMARILLA,WOODIES,DEMARKS.
simulateCompounding(params): Project account growth over multiple trades.calculateDrawdown(params): Analyze potential balance decay during losing streaks.calculateExpectancy(params): Determine strategy edge (Statistical Expectancy).
calculateBacktest(params): Comprehensive strategy simulation over a time period.
The library supports a wide range of symbols across different asset classes.
| Symbol | Contract Size | Pip Size |
|---|---|---|
| AUDJPY, CADJPY, CHFJPY, EURJPY, GBPJPY, NZDJPY, USDJPY | 100,000 | 0.01 |
| AUDNZD, AUDUSD, EURAUD, EURGBP, EURNZD, EURUSD, GBPCAD, GBPNZD, GBPUSD, NZDUSD, USDCAD, USDCHF | 100,000 | 0.0001 |
| Symbol | Type | Contract Size | Pip Size |
|---|---|---|---|
| XAUUSD | Gold | 100 | 0.1 |
| XAGUSD | Silver | 5000 | 0.01 |
| Symbol | Contract Size | Pip Size |
|---|---|---|
| US30, NAS100, SPX500, GER40, JPN225, UK100 | 1 | 1.0 |
| USOIL, UKOIL | 100 | 0.01 |
| XNGUSD | 10,000 | 0.001 |
| Symbol | Contract Size | Pip Size |
|---|---|---|
| BTCUSD, ETHUSD | 1 | 1.0 |
| SOLUSD | 1 | 0.01 |
The library validates inputs and throws clear error messages:
try {
calculatePivotPoints({ high: 0, low: 100, close: 105, method: 'CLASSIC' })
} catch (e) {
console.error(e.message) // "Prices must be greater than 0"
}This project is licensed under the MIT license. See the LICENSE file for more info.