OPEN-SOURCE SCRIPT
Zaktualizowano Position Size + Liquidity Check

=============================================================================
Position Size Calculator + Liquidity Check
=============================================================================
Position sizing math derived from:
"Position Size Calculator" by Kousik_View (MPL 2.0)
mozilla.org/MPL/2.0/
WHAT IT DOES
Combines two essential pre-trade checks into one indicator:
1. Position sizing - computes quantity, stop loss price, and risk
amount from your account capital, risk-per-trade %, and
stop-loss %.
2. Liquidity verdict - checks whether the stock can actually
absorb that computed position size, by sampling 1m/3m/5m
turnover across the chart bar.
You enter your risk parameters ONCE. The indicator tells you
exactly how many shares to buy AND whether the stock is liquid
enough for that size. No need to type position size manually.
POSITION SIZING FORMULA (Kousik_View)
Risk Amount = Account Capital * RPT% / 100
SL per share = current close * StopLoss% / 100
Stop Loss price = current close - SL per share
Quantity = Risk Amount / SL per share
Position Size = Quantity * current close
Equivalent simplification:
Position Size = Account Capital * (RPT% / StopLoss%)
For Acct=5L, RPT=0.5, SL=2.5 -> Position = Rs.1L regardless of price.
LIQUIDITY CHECK
For each lower-TF bar (1, 3, or 5 min):
turnover = close * volume
Count how many inner bars have turnover < computed position size.
If the count exceeds your threshold, the stock can't absorb your
order without market impact - flagged red.
INPUTS
Risk:
- Account Capital (Rs.)
- Risk per trade %
- Stop Loss %
Liquidity:
- Inner timeframe (1, 3, 5 min)
- Bars below position size to flag illiquid
Display:
- Show table / status line toggles
- Table position (9-way) and text size
DISPLAY
Two-column table with rows:
Qty <shares>
SL price Rs.<price>
Risk Rs.<amount>
Pos size Rs.<amount>
Liquidity <pct>% bars below <- red row when illiquid
Avg turn Rs.<amount>
Status line shows: Qty, SL price, Risk, % illiquid, Avg turnover.
=============================================================================
Position Size Calculator + Liquidity Check
=============================================================================
Position sizing math derived from:
"Position Size Calculator" by Kousik_View (MPL 2.0)
mozilla.org/MPL/2.0/
WHAT IT DOES
Combines two essential pre-trade checks into one indicator:
1. Position sizing - computes quantity, stop loss price, and risk
amount from your account capital, risk-per-trade %, and
stop-loss %.
2. Liquidity verdict - checks whether the stock can actually
absorb that computed position size, by sampling 1m/3m/5m
turnover across the chart bar.
You enter your risk parameters ONCE. The indicator tells you
exactly how many shares to buy AND whether the stock is liquid
enough for that size. No need to type position size manually.
POSITION SIZING FORMULA (Kousik_View)
Risk Amount = Account Capital * RPT% / 100
SL per share = current close * StopLoss% / 100
Stop Loss price = current close - SL per share
Quantity = Risk Amount / SL per share
Position Size = Quantity * current close
Equivalent simplification:
Position Size = Account Capital * (RPT% / StopLoss%)
For Acct=5L, RPT=0.5, SL=2.5 -> Position = Rs.1L regardless of price.
LIQUIDITY CHECK
For each lower-TF bar (1, 3, or 5 min):
turnover = close * volume
Count how many inner bars have turnover < computed position size.
If the count exceeds your threshold, the stock can't absorb your
order without market impact - flagged red.
INPUTS
Risk:
- Account Capital (Rs.)
- Risk per trade %
- Stop Loss %
Liquidity:
- Inner timeframe (1, 3, 5 min)
- Bars below position size to flag illiquid
Display:
- Show table / status line toggles
- Table position (9-way) and text size
DISPLAY
Two-column table with rows:
Qty <shares>
SL price Rs.<price>
Risk Rs.<amount>
Pos size Rs.<amount>
Liquidity <pct>% bars below <- red row when illiquid
Avg turn Rs.<amount>
Status line shows: Qty, SL price, Risk, % illiquid, Avg turnover.
=============================================================================
Informacje o Wersji
v2 - Rolling lookback rewriteThe single-bar liquidity verdict was noisy: one half-day, earnings
spike, or holiday-thin session could flip a stock from "liquid" to
"illiquid" and back. This update aggregates liquidity stats across a
rolling window so the verdict reflects the stock's typical behaviour.
WHAT'S NEW
- Lookback (chart bars): rolling window size, default 10.
Recommended: 10 = ~2 weeks, 22 = ~1 month, 60 = ~3 months.
- Max % bars below size to allow trade: percentage threshold,
default 50. Replaces the old absolute count, so settings stay
valid regardless of chart timeframe.
- Table cells now show the window: "Liquidity 10d", "Avg turn 10d".
BUG FIX
- Under Pine v6 lazy evaluation, the position size used in the
comparison could drift to the inner timeframe. Rewritten to
use an explicit loop over the raw turnover array, comparing
against the chart-TF-resolved position size. Threshold is now
guaranteed fixed per chart bar.
MIGRATION
- The old "Bars below position size to flag illiquid" input is
replaced by two: "Lookback (chart bars)" (default 10) and
"Max % bars below size to allow trade" (default 50). New inputs
load at sensible defaults; tune to your screening horizon.
THRESHOLD GUIDE
- 30% bars below: conservative, low slippage
- 50% bars below: intraday-friendly (default)
- 70% bars below: swing-friendly
- Above 70%: skip the trade
Informacje o Wersji
Three pre-trade checks in one indicator — sizing, liquidity, and volatility.Enter your risk parameters once and the script tells you exactly how many shares to buy, whether the stock can actually absorb that
size, and how volatile it is — no manual position-size entry needed.
1. Position sizing (math derived from "Position Size Calculator" by Kousik_View, MPL 2.0)
From your account capital, risk-per-trade %, and stop-loss %, it computes:
• Quantity (shares) • Stop-loss price • Risk amount (Rs.) • Position size (Rs.)
2. Liquidity verdict
Samples 1/3/5-minute turnover (close × volume) across a rolling N-bar window and reports the % of inner bars whose turnover fell
below your computed position size. Cross your threshold and the row flags red — the stock is too thin to absorb your order without
market impact. Default lookback 10 bars (~2 weeks on a daily chart); adjustable to ~1 or ~3 months.
3. Average Daily Range (ADR %) — new
ADR% = 100 × (SMA(high/low, length) − 1), a fast volatility read. ~3–5% is a typical swing-trade sweet spot; very low = sluggish,
very high = whippy. Use on a daily chart for a true average daily range.
Display: a compact 7-row table (Qty, SL price, Risk, Pos size, ADR, Liquidity, Avg turnover) — positionable 9 ways with selectable
text size — plus all values mirrored in the status line. An alert fires when the stock can't absorb the computed position size.
Built for Indian equities but works on any symbol with intraday data. Best used on a daily chart.
Informacje o Wersji
Update: ADR volatility row + cleaner scale• New ADR (Average Daily Range %) row in the table and status line. ADR% = 100 × (SMA(high/low, length) − 1) — a quick volatility
read alongside your sizing and liquidity numbers. Use on a daily chart for a true average daily range.
• New input ADR length (default 20) — the averaging window. The table cell labels it, e.g. ADR 20d.
• New input ADR green/red threshold % (default 5) — the ADR cell and status-line plot turn green when ADR% ≥ threshold (enough
volatility to trade) and red below it.
• Removed the empty right-hand price scale. The indicator only draws a table and status-line values, so the blank axis it used to
reserve is gone.
Informacje o Wersji
1. Timeframe Mismatch Fix: The indicator now checks the chart's timeframe. If you put it on a chart equal to or lower than the innertimeframe (e.g. a 1m chart with a 1m inner timeframe), it bypasses request.security_lower_tf and processes the chart's native bar
directly instead of silently breaking and displaying 0% below .
2. NaN Value Propagation Check: Added safety checks ( if not na(t) ) to ensure missing volume data or chart gaps don't crash the
rolling turnover calculations to na / 0 .
3. Empty Minutes Correction (Illiquidity Bias): Dynamically calculates expected bars for Indian markets (375 bars per day for
NSE/BSE). Any missing minutes (where zero transactions occurred) are now correctly counted as having 0 turnover (which is below
your position size), eliminating the false "liquid" reading on dead stocks.
4. Exchange Tick Size Compliance: Replaced hardcoded .00 rounding with dynamic alignment to the instrument's tick size ( syminfo.
mintick ). For Indian stocks, this ensures stop-loss prices are rounded to valid multiples of 0.05 to avoid broker order rejection.
5. Position Size Risk Warning: If the computed position size exceeds your Account Capital (e.g., tight stop loss), the Pos size
cell will now glow in warning orange.
6. Double-Turnover Metrics: Renamed the label to "Avg 1m turn" (or 3m/5m) and added a new row for "Avg Daily turn" to display
actual daily turnover rather than confusing intrabar averages.
7. Premium Styling: Replaced harsh red/green colors with a premium slate-dark TradingView dashboard theme.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.