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が提供または推奨する金融、投資、トレード、その他のアドバイスや推奨を意図するものではなく、それらを構成するものでもありません。詳細は利用規約をご覧ください。