Cauchy_derivative_YTG
Download scriptThis indicator, titled the Cauchy Derivative, is designed to provide traders with a visual representation of momentum and price movement dynamics by measuring the rate of change between two distinct types of moving averages. Instead of looking at just one price trend, it analyzes the relationship between "Simple" and "Geometric" mathematical trends to highlight shifts in market behavior.
How the Logic Works
The tool operates by performing three primary steps:
1. Calculating Two Distinct Averages The script constantly monitors four key data points for every candle: the Open, High, Low, and Close prices. It uses these to create two different types of averages:
- Simple Average (YMA): This calculates the standard arithmetic mean over a short period. it treats all price movements equally, providing a straightforward view of recent price action.
- Geometric Average (GMA): This calculates a geometric progression over a longer period. Unlike a simple average, a geometric average is more sensitive to proportional changes and compounding, which can offer a different perspective on the underlying trend.
2. Measuring the Difference (The Spread) Once these two averages are established, the script identifies the "gap" between them. By subtracting the Geometric Average from the Simple Average, the tool isolates how much the short-term price action is deviating from the longer-term geometric structure.
3. Determining the Derivative (The Change) This is the core of the "Cauchy Derivative" logic. The indicator does not just show you the gap between these averages; it shows you how fast that gap is growing or shrinking.
- It compares the current gap to the gap from the previous price candle.
- If the difference between the two averages is widening quickly, the histogram will reflect a surge in momentum.
- If the gap is narrowing or staying constant, the movement is stabilizing.
Visual Representation
The result is displayed as a Histogram in a separate window below your main price chart. Because it tracks the change in the relationship between these two averages, the bars help you visualize the acceleration of the market. It acts as a momentum signal, highlighting where the "speed" of the trend is picking up or slowing down, allowing you to see the transition from one market state to another more clearly than by looking at price alone.
//+------------------------------------------------------------------+
//| Cauchy derivative.mq5 |
//| Yuriy Tokman |
//| http://ytg.com.ua |
//+------------------------------------------------------------------+
#property copyright "Yuriy Tokman"
#property link "http://ytg.com.ua"
#property version "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_width1 2
#property indicator_type1 DRAW_HISTOGRAM
#property indicator_color1 clrDarkViolet
//--- input parameters
input int YMA_Period=5;
input int GMA_Period=12;
//--- indicator buffers
double Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
SetIndexBuffer(0,Buffer);
//IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,MathMax(YMA_Period,GMA_Period));
string short_name="Cauchy derivative YTG";
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
//---
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 i,limit;
//--- check for rates
if(rates_total<MathMax(YMA_Period,GMA_Period)) return(0);
//--- preliminary calculations
if(prev_calculated==0)limit=MathMax(YMA_Period,GMA_Period);
else limit=prev_calculated-1;
//--- the main loop of calculations
for(i=limit;i<rates_total && !IsStopped();i++)
{
double MA = ma (open,high,low,close,i);
double MG = mg (open,high,low,close,i);
double MA1 = ma (open,high,low,close,i-1);
double MG1 = mg (open,high,low,close,i-1);
Buffer[i] = (MA - MG) - (MA1 - MG1);
}
//----
return(rates_total);
}
//+------------------------------------------------------------------+
double mg (const double &o[],const double &h[],const double &l[],const double &c[],int _i)
{
double res =1;
for(int j=_i;j>_i-GMA_Period && j>0;j--)
res *= (c[j]+o[j]+h[j]+l[j])/4.0;
return(MathPow(res,1.0/GMA_Period));
}
double ma (const double &o[],const double &h[],const double &l[],const double &c[],int _i)
{
double res =1;
for(int j=_i;j>_i-YMA_Period && j>0;j--)
res += (c[j]+o[j]+h[j]+l[j])/4.0;
return(res/YMA_Period);
}
Comments