Lot Size Calculator
Created with Create React App
Development
script/setup
script/test
script/dev # or npm run
Deployment
via GitHub Pages:
script/deploy
# or
npm run deploy
docs: https://create-react-app.dev/docs/deployment#github-pages
Understanding the algorithm
Pips at risk * pip value * lots traded = amount at risk
- Account balance is $10,000 USD
- Risk is 1%
- Stop loss is 10 pips
- Convert risk to local currency. If base currency is denmoninator, then bid price. If numerator, then ask price.
- If account currency is denominator, then pip value is 1. So
risk in dollars/pips in dollars == position
. $100/ 10 pips * $1 => 10 mini lots (1 standard) - EUR/CAD. USD/CAD ask is 1/1.2219.
- $100 / 10 pips * 1.2219 = 1.2219 standard or 12.21 mini
- GBP/AUD. AUD/USD bid is 1.4458 so
- 1AUD/1.4458USD =>
1/1.4458=0.6913
=> $1USD = $0.69AUD - position size is therefore .6913 * 100k
- Standard lot is
.6913
. Mini lot is6.913
etc
- 1AUD/1.4458USD =>
- EUR/JPY. USD/JPY ask 135.774
- $100 / 10 pips * 135.774 / 1000 (for yen) = 1.35 standard, 13.5 mini
- If account currency is denominator, then pip value is 1. So
Copilot version
interface Input {
accountBalance: number;
riskPercentage: number;
stopLossPips: number;
baseCurrency: string;
quoteCurrency: string;
bidPrice: number;
askPrice: number;
}
interface Output {
positionSize: number;
pipValue: number;
lotSize: number;
}
function calculatePositionSize(input: Input): Output {
const {
accountBalance,
riskPercentage,
stopLossPips,
baseCurrency,
quoteCurrency,
bidPrice,
askPrice,
} = input;
const riskAmount = accountBalance * (riskPercentage / 100);
const pipValue =
(riskAmount / stopLossPips) *
(quoteCurrency === baseCurrency ? 1 : askPrice);
const lotSize = pipValue / 10;
return {
positionSize: riskAmount / (stopLossPips * pipValue),
pipValue,
lotSize,
};
}