Skewness_v1
Download scriptThis technical tool, titled Skewness_v1, is designed to provide traders with a deeper understanding of price action by analyzing the relationship between volume and price distribution. Instead of looking at simple price movements, this script calculates how "unbalanced" the trading activity is within a specific historical timeframe.
Core Logic Overview
The script operates by reconstructing the behavior of the market based on three primary metrics: PVP (Point of Volume), VWAP (Volume Weighted Average Price), and Skewness.
1. Data Collection and Volume Distribution
The tool starts by looking at a specific date range provided by the user. It scans every price bar within that period to determine the highest and lowest prices reached. It then creates a "histogram" of price levels. For every individual transaction, the script attempts to distribute the volume across these price levels to see where the majority of the actual trading activity is occurring.
2. Key Indicators Explained
To provide a complete picture, the script calculates three distinct values:
- PVP (Point of Volume): This identifies the price level where the highest concentration of trading volume has actually occurred. Think of this as the "center of gravity" for all trading activity.
- VWAP (Volume Weighted Average Price): This is a standard financial metric that calculates the average price weighted by the volume traded at each price. It tells you what the "fair value" was over a period, taking into account how much volume was traded at different levels.
- Skewness: This is the primary output of the script (displayed as a line on your chart). It measures the mathematical distance between the PVP and the VWAP, adjusted by the Standard Deviation (volatility).
How to Interpret the Results
The goal of this logic is to identify market imbalances:
- Balance: When the Skewness value is near zero, it suggests that the Point of Volume (where most trading is happening) is very close to the Volume Weighted Average Price. This indicates a relatively balanced market with no extreme pressure from one side.
- Imbalance (Skew): A significant deviation in the Skewness line indicates that the "center of gravity" for volume is moving away from the average price. If the Skewness moves significantly in one direction, it suggests that heavy trading activity is concentrating at prices different from the mathematical average, potentially signaling a trend shift or a zone of high resistance/support.
By using this tool, users can visualize whether the current market sentiment is concentrated in a way that suggests an underlying imbalance between buyers and sellers.
//+------------------------------------------------------------------+
//| Skewness_v1.mq4 |
//| Copyright © 2009, Akif TOKUZ |
//| akifusenet@gmail.com |
//| 11.08.2009: v1=>Initial release |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Akif TOKUZ"
#property link "akifusenet@gmail.com"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red //Skew
#property indicator_width1 1
//---- input parameters
extern datetime StartDate=D'2009.08.06 00:00';
extern datetime EndDate=D'2009.08.07 00:00';
//---- buffers
double Skew[];
double PVP[];
double VWAP[];
double Hist[];
datetime OpenTime = 0; // To check if we have a new bar
int items; // numbers of items inside volume histogram
int Bars_Back = 0; // Shows the starting bar for given date
double SD; // standart deviation
// Finds the bar number for the given date
int FindStartIndex(datetime startDate)
{
for (int i=Bars-1; i>=0; i--)
{
if (Time[i]>=StartDate) return (i);
}
return( 0);
}
int init()
{
//---- indicators
IndicatorBuffers(3);
SetIndexStyle(0,DRAW_LINE);
SetIndexLabel(0,"Skew");
SetIndexBuffer(0,Skew);
SetIndexStyle(1,DRAW_NONE);
SetIndexLabel(1,"PVP");
SetIndexBuffer(1,PVP);
SetIndexStyle(2,DRAW_NONE);
SetIndexLabel(2,"VWAP");
SetIndexBuffer(2,VWAP);
string short_name="Skewness";
IndicatorShortName(short_name);
return(0);
}
int start()
{
double TotalVolume=0;
double TotalPV=0;
int n;
if (OpenTime != Open[0])
{
Bars_Back=FindStartIndex(StartDate);
OpenTime = Open[0];
double max = High[iHighest( NULL , 0, MODE_HIGH, Bars_Back, 0)];
double min = Low[ iLowest( NULL , 0, MODE_LOW, Bars_Back, 0)];
items = MathRound((max - min) / Point);
ArrayResize(Hist, items);
ArrayInitialize(Hist, 0);
TotalVolume=0;
TotalPV=0;
for (int i = Bars_Back; i >= 1; i--)
{
if (Time[i]<EndDate) // Only calculate if we didnt reach the end date
{
double t1 = Low[i], t2 = Open[i], t3 = Close[i], t4 = High[i];
if (t2 > t3) {t3 = Open[i]; t2 = Close[i];}
double totalRange = 2*(t4 - t1) - t3 + t2;
if (totalRange != 0.0)
{
for (double Price_i = t1; Price_i <= t4; Price_i += Point)
{
n = MathRound((Price_i - min) / Point);
if (t1 <= Price_i && Price_i < t2)
{
Hist[n] += MathRound(Volume[i]*2*(t2-t1)/totalRange);
}
if (t2 <= Price_i && Price_i <= t3)
{
Hist[n] += MathRound(Volume[i]*(t3-t2)/totalRange);
}
if (t3 < Price_i && Price_i <= t4)
{
Hist[n] += MathRound(Volume[i]*2*(t4-t3)/totalRange);
}
}//for
}else
{
// Check if all values are equal to each other
n = MathRound((t3 - min) / Point);
Hist[n] += Volume[i];
}//if
// use H+L+C/3 as average price
TotalPV+=Volume[i]*((Low[i]+High[i]+Close[i])/3);
TotalVolume+=Volume[i];
if (i==Bars_Back) PVP[i]=Close[i];
else PVP[i]=min+ArrayMaximum(Hist)*Point;
if (i==Bars_Back) VWAP[i]=Close[i];
else VWAP[i]=TotalPV/TotalVolume;
SD=0;
for (int k = Bars_Back; k >= i; k--)
{
double avg=(High[k]+Close[k]+Low[k])/3;
double diff=avg-VWAP[i];
SD+=(Volume[k]/TotalVolume)*(diff*diff);
}
SD=MathSqrt(SD);
Skew[i]=(VWAP[i]-PVP[i])/SD;
}//if for checking end date
}//for BARS BACK
}//MAIN IF BAR START
return(0);
}
int deinit()
{
return(0);
}
Comments