OPEN-SOURCE SCRIPT

WIG20 Total Value-Weighted Volume

88
This Pine Script creates a custom indicator for TradingView that calculates and visualizes the total "value-weighted volume" of the 20 stocks in the WIG20 index (a major Polish stock market index). Here's a breakdown of what it does:
Functionality:
Stock Selection:
The script allows you to input the ticker symbols for the 20 stocks that make up the WIG20 index (e.g., "PKO" for PKO Bank Polski, "PKN" for PKN Orlen, etc.). These are customizable via input fields, so you can adjust them to match the current WIG20 constituents.
Data Retrieval:
For each of the 20 stocks, it fetches two pieces of data from the current chart timeframe (e.g., daily, hourly):
Volume: The number of shares traded (e.g., v01 for the first stock).
Average Price: The midpoint price of the candle, calculated as (open + close) / 2 (e.g., p01 for the first stock). This represents a typical price for that period.
Value-Weighted Volume Calculation:
For each stock, it multiplies the volume by its average price (e.g., vw01 = v01 * p01). This converts the raw volume (in shares) into a monetary value (e.g., in Polish złoty, PLN, assuming the prices are in PLN).
The result, called "value-weighted volume," reflects the total monetary amount traded for each stock rather than just the number of shares.
Total Value-Weighted Volume:
It sums the value-weighted volumes of all 20 stocks into a single value, totalValueVolume. This represents the combined monetary trading activity across the WIG20 index for each time period (e.g., each candle on the chart).
Statistical Analysis:
The script calculates a rolling mean and standard deviation of the totalValueVolume over a user-defined lookback period (default is 20 bars, adjustable via input).
It then computes a "3-sigma" threshold, which is the mean plus three times the standard deviation. This threshold identifies unusually high trading activity (statistically significant outliers).
Candle Direction:
It checks whether the current candle on the chart (e.g., the WIG20 index itself) is bullish or bearish:
Bullish: If the close price is higher than the open price (close > open).
Bearish: If the close price is lower than the open price (close < open).
Color-Coded Visualization:
The totalValueVolume is plotted as a histogram on the chart with dynamic colors:
Blue: If the value-weighted volume is below the 3-sigma threshold (normal trading activity).
Green: If the value-weighted volume exceeds the 3-sigma threshold and the candle is bullish (indicating unusually high buying activity).
Red: If the value-weighted volume exceeds the 3-sigma threshold and the candle is bearish (indicating unusually high selling activity).
Purpose:
What It Shows: The indicator highlights the total monetary trading volume across the WIG20 stocks, adjusted for each stock’s price, and flags periods of exceptional activity (above 3 sigma) with colors that indicate market direction (bullish or bearish).
Use Case: Traders or analysts might use this to:
Identify significant market events where trading volume spikes (e.g., news-driven moves).
Assess whether those spikes align with bullish (green) or bearish (red) sentiment, based on the WIG20 index’s price movement.
Compare monetary trading activity across different periods, rather than just share volume, which gives more weight to higher-priced stocks.
Key Features:
Customizable: You can tweak the stock symbols and lookback period to fit your needs.
Statistical Insight: The 3-sigma rule helps spot outliers in trading activity.
Visual Clarity: The histogram’s color changes make it easy to see when volume spikes occur and whether they’re tied to upward or downward price moves.
Example Output:
On a daily WIG20 chart, if one day’s total value-weighted volume is exceptionally high (above 3 sigma) and the WIG20 closes higher than it opened, the histogram bar for that day turns green. If it closes lower, it turns red. Otherwise, it stays blue.
In essence, this script transforms raw volume data into a price-adjusted, statistically informed indicator that visually emphasizes significant trading events with directional context!

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.