pfe2_v1

This script is designed as a visual tool for traders to analyze price momentum and trend strength. Rather than showing the raw price of an asset, it processes market data to create a smoothed, weighted indicator that helps identify the "strength" or "velocity" of a move.

Here is a breakdown of how the logic works in plain English:

1. Data Smoothing

The first step the script takes is to stabilize the market noise. Instead of looking at every tiny price tick—which can be erratic—it calculates an average price over a specific period (determined by the "smoothing" setting). This ensures that the resulting indicator reflects broader trends rather than momentary fluctuations.

2. Measuring Movement Velocity

The logic then compares the current smoothed price against the price from several bars back. By calculating the difference between these two points, the script determines the "distance" traveled over a specific timeframe. It specifically looks at the significant change over a 9-bar window to establish a baseline for movement.

3. Relative Strength Calculation

To provide context to that movement, the script performs a unique calculation:

  • The Current Move: It measures the magnitude of the recent price change.
  • The Historical Context: It looks at the sum of all individual movements over the preceding 9 bars.
  • The Ratio: It compares the current move against that historical sum to create a "force" percentage. This tells the user whether the current price action is significantly stronger or weaker than what has occurred recently.

4. Directional Alignment

The indicator recognizes the difference between upward and downward trends. If the price is moving up, the value remains positive; if the price is moving down, the value becomes negative. This allows a trader to see at a glance not just how fast the price is moving, but in which direction the "force" is headed.

5. Final Smoothing and Visualization

To prevent the indicator from jumping too wildly on the chart (which can lead to false signals), the script applies a final "weighted average." It takes 33% of the new calculation and blends it with 67% of the previous value. This creates a fluid, continuous line that is easier for the human eye to follow while still reacting quickly to significant changes in market momentum.

Price Data Components
Series array that contains close prices for each bar
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
pfe2_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                          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