VolPerPip v4
Download scriptThis technical script is designed to function as a specialized trading indicator that analyzes the relationship between market volume and price movement. Rather than simply showing price history, it seeks to quantify how much "effort" or volume is being expended to move the market in specific directions.
Core Logic and Functionality
The tool operates by scanning a specific window of recent historical data (defined by a user-set period) to differentiate between upward and downward market activity. Here is the step-by-step breakdown of how it processes this information:
1. Data Categorization The script looks at each individual price candle and identifies whether the price moved up or down during that timeframe. It then separates the data into two categories:
- Upward Movement: Captures the total "pips" gained when the price rises, along with the volume traded during those specific moments.
- Downward Movement: Captures the total "pips" lost when the price falls, along with the volume traded during those specific moments.
2. Efficiency Calculations (The Ratios) The primary logic of the script is to calculate a ratio for both upward and downward movements. It divides the total accumulated volume by the total price change (pips). This effectively measures the "volume per pip."
- If it takes a massive amount of volume to move the price only a small distance, the ratio will be high.
- If a small amount of volume moves the price a large distance, the ratio will be low.
3. Visual Representation The script outputs these results into two distinct visual lines on a separate window below your main chart:
- Upward Ratio: Represents the volume intensity of bullish movements.
- Downward Ratio: Represents the volume intensity of bearish movements (mirrored visually so they can be compared easily).
How to Interpret the Results
By looking at these lines, a trader can observe the "intensity" of the market. When the ratios shift, it provides insight into whether the current price trend is being supported by heavy trading activity or if the move is happening on relatively thin volume. This helps in identifying where the market might be showing exhaustion or where significant pressure is being applied by large participants.
//+------------------------------------------------------------------+
//| Moving Averages Advance.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. 2007, MQL Service |
//| http://www.mqlservice.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp. 2007, MQL Service"
#property link "http://www.mqlservice.com/"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
//---- indicator parameters
extern int VolP_Period=14;
//---- indicator buffers
double ExtMapBufferVolP_up[];
double ExtMapBufferVolP_dwn[];
//----
int ExtCountedBars=0;
int i, periodbar, objckeckback, objckeckfrwd, frwdbar,backbar;
double open, close, barpips, gainpos, volpos, pips, gainneg, volneg, gainratio,barvol;
double volratio,gainnet,avpipsperbar,volfactor, volnumberfactor,volpipsfactor, adjustment, adjustmentnorm;
double plot1,plot2, totaladjustment, upratio,dwnratio, netratio, net;
datetime ObjName;//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
int draw_begin;
string short_name;
//---- drawing settings
SetIndexStyle(0,DRAW_LINE);
//IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
if(VolP_Period<2) VolP_Period=14;
draw_begin=VolP_Period-1;
//---- indicator short name
short_name="VolP(";
IndicatorShortName(short_name+VolP_Period+")");
SetIndexDrawBegin(0,draw_begin);
//---- indicator buffers mapping
SetIndexBuffer(0,ExtMapBufferVolP_up);
//========================================second buff
//---- drawing settings
SetIndexStyle(1,DRAW_LINE);
SetIndexDrawBegin(1,draw_begin);
//---- indicator buffers mapping
SetIndexBuffer(1,ExtMapBufferVolP_dwn);
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
if(Bars<=VolP_Period) return(0);
ExtCountedBars=IndicatorCounted();
//---- check for possible errors
if (ExtCountedBars<0) return(-1);
//---- last counted bar will be recounted
if (ExtCountedBars>0) ExtCountedBars--;
//---- done MA's
//double sum=0;
double gainpos=0;
double volpos=0;
double gainneg=0;
double volneg=0;
int i,pos=Bars-ExtCountedBars-1;
//---- initial accumulation
if(pos<VolP_Period) pos=VolP_Period;
for(i=1;i<VolP_Period;i++,pos--)
{
//sum+=Close[pos];
barvol=Volume[pos];
open=Open[pos];
close=Close[pos];
barpips=close-open;
if(barpips>0) {gainpos+=barpips;
volpos+=barvol; }
if(barpips<0) {gainneg+=barpips;
volneg+=barvol; }
}//for(i=1;i<VolP_Period;i++,pos--)
//---- main calculation loop
// while(pos>=0)
// {
// sum+=Close[pos];
while(pos>=0)
{
barvol=Volume[pos];
open=Open[pos];
close=Close[pos];
barpips=close-open;
if(barpips>0) { gainpos+=barpips;
volpos+=barvol; }
if(barpips<0) {gainneg+=barpips;
volneg+=barvol; }
// ExtMapBuffer[pos]=sum/MA_Period;
upratio=volpos/gainpos; //up vol per pip
dwnratio=volneg/gainneg; //dwn vol per pip
double uprationorm=NormalizeDouble(upratio,0);
double dwnrationorm=NormalizeDouble(dwnratio,0);
ExtMapBufferVolP_up[pos]=(uprationorm);
ExtMapBufferVolP_dwn[pos]=(dwnrationorm*(-1));
// sum-=Close[pos+MA_Period-1];
barvol=Volume[pos+VolP_Period-1];
open=Open[pos+VolP_Period-1];
close=Close[pos+VolP_Period-1];
barpips=close-open;
if(barpips>0) {gainpos-=barpips;
volpos-=barvol; }
if(barpips<0) {gainneg-=barpips;
volneg-=barvol; }
// pos--;
// }
pos--;
}//while
//---- zero initial bars
//if(ExtCountedBars<1)
//for(i=1;i<MA_Period;i++) ExtMapBuffer[Bars-i]=0;
if(ExtCountedBars<1)
for(i=1;i<VolP_Period;i++) ExtMapBufferVolP_up[Bars-i]=0;
for(i=1;i<VolP_Period;i++) ExtMapBufferVolP_dwn[Bars-i]=0;
return(0);
}//start
//+------------------------------------------------------------------+
Comments