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提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。