OPEN-SOURCE SCRIPT
Cập nhật [Kpt-Ahab] PnL-calculator

The PnL-Cal shows how much you’re up or down in your own currency, based on the current exchange rate.
Let’s say your home currency is EUR.
On October 10, 2022, you bought 10 Tesla stocks at $219 apiece.
Back then, with an exchange rate of 0.9701, you spent €2,257.40.
If you sold the 10 Tesla shares on April 17, 2025 for $241.37 each, that’s around a 10% gain in USD.
But if you converted the USD back to EUR on the same day at an exchange rate of 1.1398, you’d actually end up with an overall loss of about 6.2%.
Right now, only a single entry point is supported.
If you bought shares on different days with different exchange rates, you’ll unfortunately have to enter an average for now.
For viewing on a phone, the table can be simplified.
Let’s say your home currency is EUR.
On October 10, 2022, you bought 10 Tesla stocks at $219 apiece.
Back then, with an exchange rate of 0.9701, you spent €2,257.40.
If you sold the 10 Tesla shares on April 17, 2025 for $241.37 each, that’s around a 10% gain in USD.
But if you converted the USD back to EUR on the same day at an exchange rate of 1.1398, you’d actually end up with an overall loss of about 6.2%.
Right now, only a single entry point is supported.
If you bought shares on different days with different exchange rates, you’ll unfortunately have to enter an average for now.
For viewing on a phone, the table can be simplified.
Phát hành các Ghi chú
Small fixes and more user-friendly table headings.Phát hành các Ghi chú
Improved color contrastPhát hành các Ghi chú
Display correctionsPhát hành các Ghi chú
FX-only gain/loss formulas updated — now factoring in more than just FX rates.Phát hành các Ghi chú
Description and FunctionalityThe script combines price and currency changes to calculate the actual performance of an investment, including the effect of exchange rate fluctuations.
1. User Inputs
Purchase date, purchase price, and quantity are defined via input fields.
Input of the base currency (e.g., CHF, EUR) and the data provider (e.g., FX_IDC).
Selection of a color scheme for the lines and tables displayed in the chart.
2. Exchange Rate Calculation
The script loads the current exchange rate (syminfo.currency → base currency).
The exchange rate at the time of purchase is stored.
This enables the calculation of the impact of currency fluctuations on the investment performance later on.
3. Chart Displays
Vertical line: Marks the purchase date on the chart.
Horizontal line: Marks the purchase price.
4. Performance Calculation
The script calculates:
Price change (absolute and percentage) without currency effects.
Initial investment (adjusted for the exchange rate at the time of purchase).
Current value (based on the current exchange rate).
Overall performance including exchange rate effects.
Isolated impact of exchange rate changes on performance.
5. Table Display
A dynamic table is shown on the chart.
The display can be either:
Full table (desktop view, detailed information)
Compact table (mobile/small view)
Term Explanation
PnL excl. FX Profit/Loss from price movement only (excluding FX).
PnL incl. FX Actual profit/loss including exchange rate impact.
FX only Portion of the profit/loss caused solely by exchange rate changes.
Corrected invest Adjusted purchase and current value in the base currency.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.