OPEN-SOURCE SCRIPT
Portfolio Open Risk and Position Heat Tracker - India [SMC]

WHAT THIS DOES
Position sizing tells you how much to buy on one trade. It says nothing about what happens when you are holding eight of them at once.
This tracks all your open positions together. Pick up to twenty symbols, give each one a quantity, an entry and a stop, and it prices what you are carrying: what you lose if every stop fills, which sectors that loss is concentrated in, and how much room is left before you reach the total loss you are willing to take.
TWO NUMBERS THAT ARE NOT THE SAME
Most risk calculators quietly conflate these. They answer different questions and both are worth knowing.
OPEN LOSS
what you give back from today's price down to your stops. Money currently on the table.
LOSS VS COST
what you lose measured from your entries. On a position whose stop has been trailed above cost this is zero, no matter how much open loss it still carries. A trader running trailed stops can be carrying a large open loss and no loss at all against cost. One number says exposed, the other says protected. Both are true, so the dashboard prints both.
The sample position in WIPRO shows it: stop at 172 against a 170 entry. Real open loss, zero loss against cost.
THE ARITHMETIC
Open loss = Qty x (Last - Stop)
Loss vs cost = Qty x max(0, Entry - Stop)
P&L = Qty x (Last - Entry)
Deployed = sum of Qty x Last
Room left = Max total open loss - Open loss
A position trading below its stop is counted as zero open loss and flagged "past stop", because that loss is already realised. Counting it again would flatter the total.
YOUR LIMIT, NOT MINE
You set the maximum total open loss in rupees. The default of thirty thousand is six percent of the default capital, being six trades at one percent each. That is a common starting point, not a rule from this script. Set it to what you actually run.
The bar fills toward your number. Room left translates whatever remains into a rough count of further trades at your standard risk per trade.
SECTOR CLUSTERING
Open loss is grouped by sector, taken automatically from exchange data. This exists because five positions in one sector is not five independent risks.
Total risk can look comfortable while sitting almost entirely in one group. In the sample portfolio three of five positions are Technology Services and carry half the open loss. The headline number never shows that. The sector block does.
THE POSITION TABLE
Rows sort by open loss, heaviest first, so the position you would feel most is not buried at the bottom. Note that this ordering is not P&L ordering. A stock up five percent with a trailed stop can sit last, because it has the least left on the table.
Entry, stop and last are reference prices and are shown muted. P&L and open loss are the numbers you act on and stay at full strength. A stop above cost is shown in the up colour, which is a fact about the position, not a view on the trade.
GETTING STARTED
The first five rows arrive filled with sample positions so the dashboard shows something useful before you type anything. Replace them with your own. A row counts once it has a symbol, a quantity and a stop. Entry is optional, though without it P&L and loss vs cost cannot be worked out.
Pine cannot add input rows on demand, so all twenty exist from the start and empty ones are ignored.
WHAT THIS DOES NOT DO
It does not know your real broker positions, so what you type is what it believes. It does not tell you whether any position is worth holding, whether your stops are sensible, or whether you are too concentrated. It measures. The judgement stays with you.
LIMITATIONS
Long positions only. Figures exclude brokerage, exchange and statutory charges, taxes, slippage, partial fills, and gap risk. Gap risk matters most here: if several positions gap below their stops at once, the total loss will exceed every figure shown, and no dashboard can prevent that. Open loss assumes each stop fills at its exact price. Treat it as a floor. Prices are daily closes for each symbol and update while the session is open. Positions whose symbol cannot be priced are excluded from every total and
flagged.
Educational and decision-support only. Not investment advice, and not a recommendation to buy or sell any security.
Position sizing tells you how much to buy on one trade. It says nothing about what happens when you are holding eight of them at once.
This tracks all your open positions together. Pick up to twenty symbols, give each one a quantity, an entry and a stop, and it prices what you are carrying: what you lose if every stop fills, which sectors that loss is concentrated in, and how much room is left before you reach the total loss you are willing to take.
TWO NUMBERS THAT ARE NOT THE SAME
Most risk calculators quietly conflate these. They answer different questions and both are worth knowing.
OPEN LOSS
what you give back from today's price down to your stops. Money currently on the table.
LOSS VS COST
what you lose measured from your entries. On a position whose stop has been trailed above cost this is zero, no matter how much open loss it still carries. A trader running trailed stops can be carrying a large open loss and no loss at all against cost. One number says exposed, the other says protected. Both are true, so the dashboard prints both.
The sample position in WIPRO shows it: stop at 172 against a 170 entry. Real open loss, zero loss against cost.
THE ARITHMETIC
Open loss = Qty x (Last - Stop)
Loss vs cost = Qty x max(0, Entry - Stop)
P&L = Qty x (Last - Entry)
Deployed = sum of Qty x Last
Room left = Max total open loss - Open loss
A position trading below its stop is counted as zero open loss and flagged "past stop", because that loss is already realised. Counting it again would flatter the total.
YOUR LIMIT, NOT MINE
You set the maximum total open loss in rupees. The default of thirty thousand is six percent of the default capital, being six trades at one percent each. That is a common starting point, not a rule from this script. Set it to what you actually run.
The bar fills toward your number. Room left translates whatever remains into a rough count of further trades at your standard risk per trade.
SECTOR CLUSTERING
Open loss is grouped by sector, taken automatically from exchange data. This exists because five positions in one sector is not five independent risks.
Total risk can look comfortable while sitting almost entirely in one group. In the sample portfolio three of five positions are Technology Services and carry half the open loss. The headline number never shows that. The sector block does.
THE POSITION TABLE
Rows sort by open loss, heaviest first, so the position you would feel most is not buried at the bottom. Note that this ordering is not P&L ordering. A stock up five percent with a trailed stop can sit last, because it has the least left on the table.
Entry, stop and last are reference prices and are shown muted. P&L and open loss are the numbers you act on and stay at full strength. A stop above cost is shown in the up colour, which is a fact about the position, not a view on the trade.
GETTING STARTED
The first five rows arrive filled with sample positions so the dashboard shows something useful before you type anything. Replace them with your own. A row counts once it has a symbol, a quantity and a stop. Entry is optional, though without it P&L and loss vs cost cannot be worked out.
Pine cannot add input rows on demand, so all twenty exist from the start and empty ones are ignored.
WHAT THIS DOES NOT DO
It does not know your real broker positions, so what you type is what it believes. It does not tell you whether any position is worth holding, whether your stops are sensible, or whether you are too concentrated. It measures. The judgement stays with you.
LIMITATIONS
Long positions only. Figures exclude brokerage, exchange and statutory charges, taxes, slippage, partial fills, and gap risk. Gap risk matters most here: if several positions gap below their stops at once, the total loss will exceed every figure shown, and no dashboard can prevent that. Open loss assumes each stop fills at its exact price. Treat it as a floor. Prices are daily closes for each symbol and update while the session is open. Positions whose symbol cannot be priced are excluded from every total and
flagged.
Educational and decision-support only. Not investment advice, and not a recommendation to buy or sell any security.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
pranjal
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
pranjal
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.