OPEN-SOURCE SCRIPT
Risk Management & Position size calculator (FinPip)

# Risk Management & Position size calculator (FinPip)
**Size your trades by risk.** Set your capital, risk %, entry and stop-loss — the indicator gives you position size in units, a take-profit level from your reward:risk ratio, and a clear summary on the chart.
Works on any symbol (stocks, forex, crypto, futures). Pine Script v6 · Mozilla Public License 2.0
---
## How to add to your chart
1. In TradingView, open **Indicators** (or search **“Risk Management”** / **“Finpip Risk Manager”**).
2. Select **Risk Management & Position size calculator (FinPip)** and add it to the chart.
3. Open **Settings** (gear on the indicator label) to set your capital, risk %, entry price, and stop-loss price.
---
## What you get
- **Entry, Stop-Loss & Take-Profit** — Drawn as horizontal lines on the chart (direction is Long if Entry > SL, Short if Entry < SL).
- **Position size** — Number of units (shares, lots, contracts) so that if price hits your SL, you lose only your chosen risk amount.
- **Info panel** — Capital, Risk %, Risk $, Reward $, R:R, Size (units), Risk/Unit, Entry/SL/TP prices, and direction. You can move the panel to any corner and change text size.
---
## Settings (inputs)
**Risk & Capital**
- **Total Account Capital ($)** — Capital used for risk (default 10000).
- **Risk per Trade (%)** — % of capital to risk on this trade (default 2.5%).
**Trade Levels**
- **Entry Price** — Your planned or actual entry.
- **Stop-Loss Price** — Exit price if the trade goes against you.
**Profit Target**
- **Reward:Risk Ratio** — Target as multiple of risk (e.g. 4 = 4R). TP is placed at Entry ± (SL distance × R:R).
**Display**
- **Show Info Panel** — On/off for the metrics table.
- **Round to Whole Shares/Units** — On for stocks/shares (whole numbers); off for forex/fractional.
- **Panel Position** — Top Left, Top Right, Bottom Left, Bottom Right.
- **Text Size** — Tiny / Small / Normal / Large.
- **Show Level Labels** — Price labels for Entry, SL, TP on the right.
**Colors** — Customize Entry, SL, TP lines and panel colors.
---
## How it’s calculated
- **Risk $** = Capital × (Risk % ÷ 100)
- **Risk per unit** = |Entry − Stop-Loss|
- **Position size** = Risk $ ÷ Risk per unit (optionally rounded down to whole units)
- **Take-profit** = Entry + (Risk per unit × R:R) for Long, or Entry − (…) for Short
- **Reward $** = Risk $ × R:R
---
## If something looks wrong
- **“Invalid setup — Entry and SL must be different prices”** — Your Entry and Stop-Loss are the same; change one of them.
- **“0 units (rounds to 0)”** — Risk $ is too small for the distance to SL with whole units. Increase capital or risk %, or turn off **Round to Whole Shares/Units** to see fractional size.
---
*Published on TradingView. Open source (MPL 2.0).*
**Size your trades by risk.** Set your capital, risk %, entry and stop-loss — the indicator gives you position size in units, a take-profit level from your reward:risk ratio, and a clear summary on the chart.
Works on any symbol (stocks, forex, crypto, futures). Pine Script v6 · Mozilla Public License 2.0
---
## How to add to your chart
1. In TradingView, open **Indicators** (or search **“Risk Management”** / **“Finpip Risk Manager”**).
2. Select **Risk Management & Position size calculator (FinPip)** and add it to the chart.
3. Open **Settings** (gear on the indicator label) to set your capital, risk %, entry price, and stop-loss price.
---
## What you get
- **Entry, Stop-Loss & Take-Profit** — Drawn as horizontal lines on the chart (direction is Long if Entry > SL, Short if Entry < SL).
- **Position size** — Number of units (shares, lots, contracts) so that if price hits your SL, you lose only your chosen risk amount.
- **Info panel** — Capital, Risk %, Risk $, Reward $, R:R, Size (units), Risk/Unit, Entry/SL/TP prices, and direction. You can move the panel to any corner and change text size.
---
## Settings (inputs)
**Risk & Capital**
- **Total Account Capital ($)** — Capital used for risk (default 10000).
- **Risk per Trade (%)** — % of capital to risk on this trade (default 2.5%).
**Trade Levels**
- **Entry Price** — Your planned or actual entry.
- **Stop-Loss Price** — Exit price if the trade goes against you.
**Profit Target**
- **Reward:Risk Ratio** — Target as multiple of risk (e.g. 4 = 4R). TP is placed at Entry ± (SL distance × R:R).
**Display**
- **Show Info Panel** — On/off for the metrics table.
- **Round to Whole Shares/Units** — On for stocks/shares (whole numbers); off for forex/fractional.
- **Panel Position** — Top Left, Top Right, Bottom Left, Bottom Right.
- **Text Size** — Tiny / Small / Normal / Large.
- **Show Level Labels** — Price labels for Entry, SL, TP on the right.
**Colors** — Customize Entry, SL, TP lines and panel colors.
---
## How it’s calculated
- **Risk $** = Capital × (Risk % ÷ 100)
- **Risk per unit** = |Entry − Stop-Loss|
- **Position size** = Risk $ ÷ Risk per unit (optionally rounded down to whole units)
- **Take-profit** = Entry + (Risk per unit × R:R) for Long, or Entry − (…) for Short
- **Reward $** = Risk $ × R:R
---
## If something looks wrong
- **“Invalid setup — Entry and SL must be different prices”** — Your Entry and Stop-Loss are the same; change one of them.
- **“0 units (rounds to 0)”** — Risk $ is too small for the distance to SL with whole units. Increase capital or risk %, or turn off **Round to Whole Shares/Units** to see fractional size.
---
*Published on TradingView. Open source (MPL 2.0).*
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。