PROTECTED SOURCE SCRIPT

📊 The Final Masterpiece (Sorted Columns)

50
This script, written in Pine Script (version 5), is a TradingView indicator designed to create a portfolio dashboard directly on the chart. Its main purpose is to monitor the performance of up to four different stocks in real-time.
Here is a detailed description of its features:
Main Functionality
The script creates a floating table on the chart that summarizes the key information of a stock portfolio. This table is not anchored to a specific bar but remains in a fixed position chosen by the user.
Sections and Settings
1. Global Settings:
Available Cash: Allows you to enter an amount of available cash.
Capital Gain Tax (%): Lets you set a percentage for capital gains tax, which will be used to calculate the net profit/loss.
Table Position: Provides a drop-down menu to place the table in one of the nine available positions on the chart (e.g., top right, bottom center, etc.).
2. Color Settings:
This section offers extensive customization for the table's appearance.
You can change the background and text colors for the headers, data rows, and the totals row.
It also allows you to define specific colors to highlight profits (green) and losses (red) and to adjust their transparency.
3. Inputs for each Stock:
The script is pre-configured to handle up to four stocks.
For each stock, the user can:
Enable or disable its display in the table using a toggle (🟢 Enable Stock).
Enter the Ticker (e.g., "AAPL", "MSFT") to retrieve the real-time price.
Specify a descriptive name (e.g., "Apple").
Enter the quantity of shares owned and the buy price.
Define buy and sell commissions, both fixed and as a percentage.
Choose a background color for that specific stock's row.
How It Works
1. Price Retrieval:
It uses the request.security() function to get the daily ("D") closing price for each of the entered tickers. This function allows loading data from other symbols or timeframes different from the one currently displayed on the chart.
2. Financial Calculations:
The script performs a series of calculations for each enabled stock:
Position Cost: Calculates the total cost of the investment, including purchase commissions.
Current Value: Multiplies the number of shares by the current market price.
Gross Profit/Loss (P/L): The difference between the current value and the position cost, after deducting selling commissions.
Net Profit/Loss (Net P/L): Applies the capital gains tax (set in the global settings) only if there is a profit.
Return on Investment (ROI %): Calculates the net profit/loss as a percentage of the total position cost.
3. Table Creation and Management:
The table is created using table.new().
All calculations and table updates are performed only on the last bar of the chart (if barstate.islast). This optimizes the script's performance by preventing it from recalculating and redrawing the table on every historical bar.
The table is populated dynamically: only the rows for stocks that have been enabled by the user are displayed.
The cells for "Net P/L" and "ROI %" are colored green or red depending on whether the value is positive or negative.
Finally, a totals row is added, summarizing the total cost, total value, total net P/L, and total ROI of the portfolio. This row also displays the available cash entered by the user.
In summary, "The Final Masterpiece" is a customizable portfolio indicator that provides a clear and immediate overview of one's stock positions directly on TradingView, calculating costs, values, profits, and returns in real-time while accounting for commissions and taxes.

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.