OPEN-SOURCE SCRIPT
Easy Risk Calculator with Fees

This Pine Script creates a position sizing calculator for TradingView that helps traders understand the true cost and risk of a trade when accounting for exchange fees. Here's what it does:
Core Purpose
The script calculates the actual position size, costs, and risk for a trade based on a minimum position value in USDT, while factoring in trading fees that affect both entry and exit prices.
Key Calculations
Position Size Determination:
Takes a desired position value in USDT and adjusts for fees
For longs: divides by entry price × (1 + fee) since you pay fees when buying
For shorts: divides by entry price × (1 - fee) since you receive less when shorting
Risk Analysis:
Calculates the reverse risk - determining how much you'd actually lose based on your position size, rather than starting with a target risk amount
Computes effective entry/exit values - the true USDT value after accounting for fees on both sides of the trade
Expected loss shows the actual dollar amount you'd lose if your stop loss is hit
Risk deviation reveals the percentage difference between your expected loss and calculated risk amount
Visual Output
The script displays a table on the chart showing:
This tool is particularly useful for traders who need to work with minimum position sizes on exchanges and want to understand exactly how fees impact their actual risk exposure.Claude is AI and can make mistakes. Please double-check responses. Sonnet 4.5Claude is AI and can make mistakes. Please double-check responses.
Core Purpose
The script calculates the actual position size, costs, and risk for a trade based on a minimum position value in USDT, while factoring in trading fees that affect both entry and exit prices.
Key Calculations
Position Size Determination:
Takes a desired position value in USDT and adjusts for fees
For longs: divides by entry price × (1 + fee) since you pay fees when buying
For shorts: divides by entry price × (1 - fee) since you receive less when shorting
Risk Analysis:
Calculates the reverse risk - determining how much you'd actually lose based on your position size, rather than starting with a target risk amount
Computes effective entry/exit values - the true USDT value after accounting for fees on both sides of the trade
Expected loss shows the actual dollar amount you'd lose if your stop loss is hit
Risk deviation reveals the percentage difference between your expected loss and calculated risk amount
Visual Output
The script displays a table on the chart showing:
- Trade direction (LONG/SHORT with color coding)
- Entry price and stop loss levels
- Fee percentage used
- Position size in both USDT and units of the asset
- Effective entry and exit values (after fees)
- Expected loss if stopped out
- Deviation from target risk
- Calculated risk amount in USDT
This tool is particularly useful for traders who need to work with minimum position sizes on exchanges and want to understand exactly how fees impact their actual risk exposure.Claude is AI and can make mistakes. Please double-check responses. Sonnet 4.5Claude is AI and can make mistakes. Please double-check responses.
開源腳本
秉持TradingView一貫精神,這個腳本的創作者將其設為開源,以便交易者檢視並驗證其功能。向作者致敬!您可以免費使用此腳本,但請注意,重新發佈代碼需遵守我們的社群規範。
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。
開源腳本
秉持TradingView一貫精神,這個腳本的創作者將其設為開源,以便交易者檢視並驗證其功能。向作者致敬!您可以免費使用此腳本,但請注意,重新發佈代碼需遵守我們的社群規範。
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。