This technical indicator is designed to analyze market price action by calculating a momentum-based efficiency metric. It focuses on identifying the strength and direction of price movements over a specific timeframe, smoothing out short-term "noise" to provide a clearer visual trend.
Core Methodology
The logic operates through three primary stages:
1. Price Smoothing Rather than looking at every individual price tick—which can be erratic—the script first calculates an average price for each period. It takes the closing prices of the most recent bars (based on a user-defined smoothing length) and averages them. This establishes a stable baseline for measuring movement.
2. Movement Analysis (The Efficiency Calculation) The indicator then compares current price trends against past movements using two specific measurements:
- Total Displacement: It measures the difference between the current smoothed price and the price from nine periods ago.
- Cumulative Volatility: It calculates the sum of all individual price changes occurring within those same nine periods.
By comparing the "Total Displacement" against the "Cumulative Volatility," the script determines how efficiently the market is moving. In simpler terms, it looks at whether the price is moving directly toward a target in a straight line or if it is wandering back and forth while making slow progress.
3. Trend Direction and Smoothing Once the efficiency of the movement is calculated, the script assigns it a positive or negative value based on whether the price has moved up or down over that period.
To ensure the final output is readable and not jumpy, the indicator applies a "weighted smoothing" technique. Instead of showing raw, jagged data, it blends each new calculation with the previous result (using a fixed ratio). This creates a fluid line that highlights the underlying momentum of the market, making it easier to identify the strength of a trend at a glance.
//+------------------------------------------------------------------+
//| pfe2.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Yellow
//---- input parameters
extern int smoothingLen = 15;
//extern int buySellLevel = 60;
//---- buffers
double pfe[];
double calcPrice(int bar)
{
int k;
double sum = 0;
for (k=bar;k>=bar-smoothingLen;k--)
sum += iClose(NULL, 0, k);
//Print(sum/smoothingLen);
return (sum/smoothingLen);
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicator line
IndicatorBuffers(1);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
SetIndexBuffer(0,pfe);
return(0);
}
//+------------------------------------------------------------------+
//| pfe |
//+------------------------------------------------------------------+
int start()
{
int CountBars = 300, i =0, j = 0;
double calcPrice = 0, PFE = 0, c2c = 0, fraceff = 0;
SetIndexDrawBegin(0,Bars-CountBars+smoothingLen);
//---- initial zero
//for(i=Bars-CountBars+smoothingLen;i<=Bars;i++) pfe[i]=0;
for(i=0;i<=CountBars;i++) pfe[i]=0;
//----
for(i=0;i<=CountBars;i++)
{
calcPrice = 0;
PFE = 0;
c2c = 0;
fraceff = 0;
PFE = MathSqrt(MathPow(calcPrice(i) - calcPrice(i-9), 2) + 100);
//Print("PFE = " + PFE);
for (j=1;j<=9;j++)
c2c += MathSqrt(MathPow(calcPrice(i-j-1) - calcPrice(i-j), 2) + 1);
//Print("c2c = " + c2c);
if (calcPrice(i) - calcPrice(i-9) > 0)
fraceff = MathRound((PFE / c2c) * 100);
else
fraceff = MathRound(-(PFE / c2c) * 100);
//a = iMomentum(NULL,0,len-1,PRICE_MEDIAN,0);
//b = iMomentum(NULL,0,len-1,PRICE_MEDIAN,0);
//a = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
//b = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
//Print("fraceff = " +fraceff);
if (i == Bars-CountBars+smoothingLen)
pfe[i] = fraceff;
else
pfe[i] = MathRound((fraceff * 0.333) + (pfe[i-1] * (1 - 0.333)));
}
return(0);
}
//+------------------------------------------------------------------+
Comments