OPEN-SOURCE SCRIPT
Position Sizer and Calculator

Here is your properly formatted TradingView-ready description using correct BBCode structure for clean public library display:
---
Position Sizer and Calculator (PSC)
A professional-grade position sizing and risk evaluation tool designed to quantify trade exposure directly from chart-defined levels.
This script calculates trade size, risk, reward, and performance metrics dynamically based on your selected Entry, Take Profit, and Stop Loss levels.
It is designed for disciplined traders who manage capital allocation through structured risk control.
---
Overview
The Position Sizer and Calculator operates on a capital-allocation model.
The trader defines the total dollar amount intended for the position. Risk is then derived automatically from the selected Stop Loss level. All outputs update in real time as Entry, TP, or SL levels are adjusted on the chart.
This ensures immediate visibility into:
---
User Inputs
Manual Inputs
Chart-Selected Inputs
Levels are selected directly on the chart using TradingView’s confirmation-click system. Adjusting these levels automatically recalculates all metrics.
---
Calculation Methodology
The script uses the following formulas:
All risk and reward calculations use absolute price distances to ensure correct handling of both long and short configurations.
---
Table Output
The summary table displays the following metrics in structured order:
Values update immediately when price levels or trade value are adjusted.
---
Structural Controls
The script enforces logical trade structure:
---
Position Sizer and Calculator (PSC)
A professional-grade position sizing and risk evaluation tool designed to quantify trade exposure directly from chart-defined levels.
This script calculates trade size, risk, reward, and performance metrics dynamically based on your selected Entry, Take Profit, and Stop Loss levels.
It is designed for disciplined traders who manage capital allocation through structured risk control.
---
Overview
The Position Sizer and Calculator operates on a capital-allocation model.
The trader defines the total dollar amount intended for the position. Risk is then derived automatically from the selected Stop Loss level. All outputs update in real time as Entry, TP, or SL levels are adjusted on the chart.
This ensures immediate visibility into:
- Position size
- Dollar risk
- Risk percentage
- Profit potential
- Risk/Reward ratio
---
User Inputs
Manual Inputs
- Trade Value ($)
The total capital allocated to the position. - Quantity Decimals
Controls the number of decimals displayed for share quantity. Fractional shares are supported.
Chart-Selected Inputs
- Entry
- Take Profit (TP)
- Stop Loss (SL)
- Anchor bar (time reference)
Levels are selected directly on the chart using TradingView’s confirmation-click system. Adjusting these levels automatically recalculates all metrics.
---
Calculation Methodology
The script uses the following formulas:
- Shares Quantity
Qty = Trade Value ÷ Entry Price - Risk per Share
Risk per Share = |Entry − SL| - Total Risk (Dollar Risk)
Risk = Risk per Share × Qty - Risk Percentage of Trade Value
Risk % = (Risk ÷ Trade Value) × 100 - Reward per Share
Reward per Share = |TP − Entry| - Profit at Target
Profit = Reward per Share × Qty - Risk/Reward Ratio
R:R = Reward per Share ÷ Risk per Share
All risk and reward calculations use absolute price distances to ensure correct handling of both long and short configurations.
---
Table Output
The summary table displays the following metrics in structured order:
- Trade Value
- Shares Quantity
- Entry
- Take Profit
- Stop Loss
- Profit at Target
- Risk (Dollar Risk)
- Risk % (of Trade Value)
- Risk/Reward Ratio
Values update immediately when price levels or trade value are adjusted.
---
Structural Controls
The script enforces logical trade structure:
- TP and SL cannot both be above Entry.
- TP and SL cannot both be below Entry.
- Risk is always derived from the Stop Loss.
- Long and short configurations are automatically detected.
開源腳本
秉持TradingView一貫精神,這個腳本的創作者將其設為開源,以便交易者檢視並驗證其功能。向作者致敬!您可以免費使用此腳本,但請注意,重新發佈代碼需遵守我們的社群規範。
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。
開源腳本
秉持TradingView一貫精神,這個腳本的創作者將其設為開源,以便交易者檢視並驗證其功能。向作者致敬!您可以免費使用此腳本,但請注意,重新發佈代碼需遵守我們的社群規範。
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。