This technical tool is designed to analyze price movements by calculating the rate of change in market momentum. Instead of simply looking at where the price is currently sitting, this script identifies the "velocity" or the speed at which price trends are shifting, helping traders distinguish between active movements and stagnant periods.
How the Logic Works
The indicator operates through a three-step mathematical process to transform raw price data into a readable trend line:
1. Establishing a Baseline (Price Center) The tool begins by calculating a "Center Price" for every individual candle. It does this by taking the average of four key data points: the High, Low, Open, and Close prices. This creates a smoothed baseline that represents the "middle ground" of price action for each specific moment in time.
2. Comparative Analysis (Mean vs. Geometric Mean) The logic then performs two different types of averages over a user-defined period (defaulting to 13 candles):
- Arithmetic Average: This calculates the standard average of the center prices, representing the typical price level.
- Geometric Average: This is a more complex calculation that accounts for the relative proportions between price changes. It is often used to smooth out extreme outliers and provide a more nuanced view of steady growth or decay.
3. Calculating the Derivative (The Velocity) The final step—and the core purpose of the script—is to find the difference between these two averages. The "derivative" represents how much the gap between the standard average and the geometric average has changed from one candle to the next.
What This Means for the User
By focusing on this "derivative," the indicator highlights momentum. When the resulting line moves sharply, it suggests that the relationship between the price averages is accelerating. Conversely, when the line flattens, it indicates that the price movement is stabilizing or losing its previous speed. This allows you to visualize the underlying "pulse" of the market rather than just following the raw price fluctuations.
//+------------------------------------------------------------------+
//| Cauchy derivative.mq4 |
//| Yuriy Tokman (YTG) |
//| http://ytg.com.ua/ |
//+------------------------------------------------------------------+
#property copyright "Yuriy Tokman (YTG)"
#property link "http://ytg.com.ua/"
#property version "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 clrDarkViolet
#property indicator_width1 2
input int period=13;
//---- buffers
double ExtMapBuffer1[];
string name="";
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
name="Cauchy derivative("+DoubleToStr(period,0)+")";
IndicatorShortName(name);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexLabel(0,name);
SetIndexDrawBegin(0,period);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---
int limit=rates_total-prev_calculated;
if(prev_calculated==0)limit--;
else limit++;
if(limit==rates_total-1)limit=rates_total-period-1;
for(int i=0; i<limit && !IsStopped(); i++)
ExtMapBuffer1[i]=(MA(i)-MG(i)) -(MA(i+1)-MG(i+1));
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
double PC(int _i=0)
{
double pc=0;
pc=((High[_i]+Open[_i]+Close[_i]+Low[_i])/4)/Point;
return(pc);
}
//----
double MA(int _i=0)
{
double ar= 0;
for(int i=_i; i<_i+period; i++)
{
ar+=PC(i);
}
return(ar/period);
}
//----
double MG(int _i=0)
{
double ge= 1;
for(int i=_i; i<_i+period; i++)
{
ge*=PC(i);
}
return(MathPow(ge,1.0/period));
}
//+------------------------------------------------------------------+
Comments