OPEN-SOURCE SCRIPT
Portfolio Tracker

Description
The Portfolio Tracker is a utility dashboard designed for traders who need to monitor the performance of a multi-asset portfolio directly from a single chart layout. While TradingView provides excellent charting for individual symbols, tracking the combined Profit & Loss (PnL) of a basket of 20 different securities (stocks, crypto, forex, or indices) usually requires switching tabs, using external spreadsheets, or logging into multiple exchange accounts.
This script solves that problem by allowing users to manually input their position details into a customizable table. It fetches real-time price data for each symbol and calculates the individual and total portfolio performance, including commission costs.
Why This Tool is Useful
This indicator was built to address specific pain points for active traders:
Consolidated View: Instead of checking 20 different charts to see how your positions are doing, you get a single, real-time snapshot of your entire portfolio's health on one screen.
Risk Management: By seeing the "Total PnL" and "Total Investment" in one place, traders can better understand their overall market exposure, rather than focusing on single winning or losing trades.
Flexible Accounting: The ability to switch between "Unit Price" and "Total Cost" inputs accommodates different trading styles—whether you are a scalper entering a single price or an investor averaging down with a specific total capital allocation.
CRITICAL: Input Logic & Warnings
To ensure accurate PnL calculations, users must understand the relationship between Quantity and Cost, especially when using "Total Cost (Manual)" mode.
The Golden Rule: Your Input Cost must always match the Total Quantity entered.
Example Scenario:
Imagine you buy 2 BTC at a price of $90,000 each.
Correct Entry: You must enter Quantity: 2 and Cost: 180000 ($90k x 2).
Result: If BTC drops to $85k, your Portfolio Value is $170k. The script correctly shows a PnL of -$10,000.
Result: If BTC rises to $95k, your Portfolio Value is $190k. The script correctly shows a PnL of +$10,000.
Incorrect Entry: If you enter Quantity: 2 but leave Cost at 90000 (the unit price).
Result: The script thinks you bought 2 BTC for a total of only $90k. It will instantly show a massive, incorrect profit because the math implies you bought 2 coins for the price of 1.
Please double-check your inputs. The script includes a "Sanity Check" feature to help catch these errors, but accurate data entry is the user's responsibility.
Key Features & Benefits
Multi-Asset Tracking (20 Slots): Monitor up to 20 different tickers simultaneously.
Real-Time Valuation: Uses request.security() to fetch the current market price for every symbol in the list. Your PnL updates with every tick of the market.
Flexible Cost Basis Modes:
Auto-Calc Mode: Enter Entry Price and Quantity. (Best for simple, single-entry trades).
Manual Cost Mode: Enter Total Invested Amount. (Best for averaged-down positions).
Advanced Commission Handling: Supports both Global and Individual commission rates. This provides a realistic "Net PnL" by factoring in fees on both the entry (cost basis) and the theoretical exit (current value).
Input Safety ("Sanity Check"): A logic check that compares the user's input against the current market value. If a user switches to "Total Cost" mode but leaves a small "Unit Price" value in the input field, the script flags the row to prevent irrational PnL percentages (e.g., >100,000%).
Clean & Customizable UI: The table can be positioned in 9 different locations, and inputs are hidden from the chart status line to keep the visual workspace clean.
How It Works
The script operates using a systematic loop that processes user inputs through a series of mathematical validations:
Data Acquisition: The script collects all 20 user inputs and utilizes request.security() to fetch the real-time close price for every non-empty symbol in the list.
Cost Basis Calculation:
In Auto-Calc Mode: The script calculates Raw Cost = Quantity * Input Price.
In Manual Mode: The script takes the Input Value directly as the Raw Cost.
"Round-Trip" Commission Modeling:
Entry Cost: Raw Cost * (1 + Commission%) (Fees increase your breakeven).
Exit Value: (Quantity * Current Price) * (1 - Commission%) (Fees reduce your payout).
Net PnL: Exit Value - Entry Cost.
Sanity Check Algorithm: Before displaying data, the script compares the Input Cost against the Gross Market Value (Qty * Price). If the Input Cost is less than a user-defined threshold (default 1%) of the Market Value, it triggers a warning, assuming the user forgot to update the field to a "Total Cost" figure.
Disclaimer
This script is for informational and educational purposes only. It is a tool to assist in tracking hypothetical or real positions based on manual user inputs and standard TradingView data feeds. It should not be relied upon as a primary accounting ledger or tax reporting tool. Past performance is not indicative of future results. Trading involves risk. Always verify your PnL against your actual exchange or broker statements.
The Portfolio Tracker is a utility dashboard designed for traders who need to monitor the performance of a multi-asset portfolio directly from a single chart layout. While TradingView provides excellent charting for individual symbols, tracking the combined Profit & Loss (PnL) of a basket of 20 different securities (stocks, crypto, forex, or indices) usually requires switching tabs, using external spreadsheets, or logging into multiple exchange accounts.
This script solves that problem by allowing users to manually input their position details into a customizable table. It fetches real-time price data for each symbol and calculates the individual and total portfolio performance, including commission costs.
Why This Tool is Useful
This indicator was built to address specific pain points for active traders:
Consolidated View: Instead of checking 20 different charts to see how your positions are doing, you get a single, real-time snapshot of your entire portfolio's health on one screen.
Risk Management: By seeing the "Total PnL" and "Total Investment" in one place, traders can better understand their overall market exposure, rather than focusing on single winning or losing trades.
Flexible Accounting: The ability to switch between "Unit Price" and "Total Cost" inputs accommodates different trading styles—whether you are a scalper entering a single price or an investor averaging down with a specific total capital allocation.
CRITICAL: Input Logic & Warnings
To ensure accurate PnL calculations, users must understand the relationship between Quantity and Cost, especially when using "Total Cost (Manual)" mode.
The Golden Rule: Your Input Cost must always match the Total Quantity entered.
Example Scenario:
Imagine you buy 2 BTC at a price of $90,000 each.
Correct Entry: You must enter Quantity: 2 and Cost: 180000 ($90k x 2).
Result: If BTC drops to $85k, your Portfolio Value is $170k. The script correctly shows a PnL of -$10,000.
Result: If BTC rises to $95k, your Portfolio Value is $190k. The script correctly shows a PnL of +$10,000.
Incorrect Entry: If you enter Quantity: 2 but leave Cost at 90000 (the unit price).
Result: The script thinks you bought 2 BTC for a total of only $90k. It will instantly show a massive, incorrect profit because the math implies you bought 2 coins for the price of 1.
Please double-check your inputs. The script includes a "Sanity Check" feature to help catch these errors, but accurate data entry is the user's responsibility.
Key Features & Benefits
Multi-Asset Tracking (20 Slots): Monitor up to 20 different tickers simultaneously.
Real-Time Valuation: Uses request.security() to fetch the current market price for every symbol in the list. Your PnL updates with every tick of the market.
Flexible Cost Basis Modes:
Auto-Calc Mode: Enter Entry Price and Quantity. (Best for simple, single-entry trades).
Manual Cost Mode: Enter Total Invested Amount. (Best for averaged-down positions).
Advanced Commission Handling: Supports both Global and Individual commission rates. This provides a realistic "Net PnL" by factoring in fees on both the entry (cost basis) and the theoretical exit (current value).
Input Safety ("Sanity Check"): A logic check that compares the user's input against the current market value. If a user switches to "Total Cost" mode but leaves a small "Unit Price" value in the input field, the script flags the row to prevent irrational PnL percentages (e.g., >100,000%).
Clean & Customizable UI: The table can be positioned in 9 different locations, and inputs are hidden from the chart status line to keep the visual workspace clean.
How It Works
The script operates using a systematic loop that processes user inputs through a series of mathematical validations:
Data Acquisition: The script collects all 20 user inputs and utilizes request.security() to fetch the real-time close price for every non-empty symbol in the list.
Cost Basis Calculation:
In Auto-Calc Mode: The script calculates Raw Cost = Quantity * Input Price.
In Manual Mode: The script takes the Input Value directly as the Raw Cost.
"Round-Trip" Commission Modeling:
Entry Cost: Raw Cost * (1 + Commission%) (Fees increase your breakeven).
Exit Value: (Quantity * Current Price) * (1 - Commission%) (Fees reduce your payout).
Net PnL: Exit Value - Entry Cost.
Sanity Check Algorithm: Before displaying data, the script compares the Input Cost against the Gross Market Value (Qty * Price). If the Input Cost is less than a user-defined threshold (default 1%) of the Market Value, it triggers a warning, assuming the user forgot to update the field to a "Total Cost" figure.
Disclaimer
This script is for informational and educational purposes only. It is a tool to assist in tracking hypothetical or real positions based on manual user inputs and standard TradingView data feeds. It should not be relied upon as a primary accounting ledger or tax reporting tool. Past performance is not indicative of future results. Trading involves risk. Always verify your PnL against your actual exchange or broker statements.
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน