pfe2_v2
Download scriptThis custom indicator is designed to analyze price trends by calculating a specific momentum value based on smoothed price averages. Instead of looking at raw, erratic market ticks, the script creates a stabilized view of price movement to identify the strength and direction of the current trend.
Core Logic Breakdown
1. Price Smoothing The foundation of the tool is a smoothing mechanism. It looks back at a specific number of previous candles (defined by the user) and calculates their average closing price. By using an average rather than a single price point, the indicator filters out "noise"—the minor, insignificant fluctuations that can often mislead traders—providing a cleaner picture of where the market is heading.
2. Momentum Calculation The script measures momentum by comparing the current smoothed price against the smoothed price from nine periods ago. It specifically calculates the difference between these two points to determine how far and how fast the price has moved over that duration.
3. Relative Strength Evaluation To provide a more nuanced reading, the indicator performs a secondary calculation. It compares the large-scale movement (the 9-period gap) against the sum of several smaller, immediate movements. This allows the tool to distinguish between a sustained, powerful trend and a series of small, erratic jumps. It essentially asks: "Is the current move significant compared to the recent minor wobbles?"
4. Directional Weighting The logic includes a directional check. If the price has moved upward over the 9-period span, it assigns a positive value; if it has moved downward, it applies a negative value. This ensures that the resulting indicator reflects both the speed of the move and its primary direction (bullish or bearish).
5. Trend Smoothing (The Final Line) Finally, to prevent the indicator line from jumping erratically on your chart, the script applies a "weighted smoothing" technique. Rather than showing the raw momentum value instantly, it blends the new calculation with the previous value using a 33% weight. This results in a much smoother, fluid line that is easier for a human trader to read visually, as it prevents sharp spikes while still reacting promptly to significant changes in market behavior.
//+------------------------------------------------------------------+
//| pfe2.mq4|
//| |
//| |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- 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