Polarized_Fractal_Efficiency
Download scriptThe Polarized Fractal Efficiency indicator is designed to measure the "directness" of price movement on a trading chart. Instead of simply looking at whether the price went up or down, this tool evaluates how efficiently the market reached its current destination by comparing the straight-line distance against the actual path taken by the price action.
How the Logic Works
1. Measuring the "Direct Path" (The Shortcut) The script looks back at a specific number of candles (defined by the period setting). It calculates the straight-line distance between the current price and the price from that past point. Think of this as a "as-the-crow-flies" measurement—it ignores all the zig-zags, fluctuations, and noise in between to see the ultimate displacement of the market.
2. Measuring the "Actual Path" (The Journey) Simultaneously, the script tracks every individual movement the price made during that same timeframe. It treats each small move as a segment of a journey. By adding up all these segments, it calculates the total distance traveled by the price, including every minor fluctuation and retracement.
3. Calculating Efficiency The core logic compares these two values:
- Efficiency: If the price moved in a nearly straight line from Point A to Point B, the "Actual Path" will be very close to the "Direct Path," resulting in a high efficiency percentage.
- Inefficiency: If the price moved wildly up and down (choppy market) but ended up only a short distance from where it started, the "Actual Path" will be much longer than the "Direct Path," resulting in a lower efficiency percentage.
4. Polarization and Smoothing The indicator distinguishes between upward and downward trends by assigning a positive or negative value based on the direction of the move. Finally, it applies a moving average to these results. This smoothing process removes "jitter" from the data, providing a cleaner, more readable line that shows the prevailing trend's strength and quality.
Summary for Traders
Essentially, this tool tells you how "honest" a price move is. A high value suggests a strong, trending market where price is moving purposefully in one direction. A low or fluctuating value suggests a "noisy" market where price is struggling to find direction, moving a lot of distance without making significant progress toward a new level.
//+------------------------------------------------------------------+
//| Polarized_Fractal_Efficiency.mq4 |
//| Yuriy Tokman |
//| yuriytokman@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Yuriy Tokman"
#property link "yuriytokman@gmail.com"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Lime
#property indicator_color2 Teal
#property indicator_level1 100
#property indicator_level2 75
#property indicator_level3 50
#property indicator_level4 25
#property indicator_level5 -25
#property indicator_level6 -50
#property indicator_level7 -75
#property indicator_level8 -100
extern string __íàñòðîéêè_íèäèêàòîðà__ = "Çäåñü èçìåíÿåì";
extern int Perriod = 9;
extern int period_MA = 5;//0-3
double FractalEfficiency[];
double Line_Zero[];
double FractalEfficiencyTmp[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE,EMPTY,3);
SetIndexBuffer(0,FractalEfficiency);
SetIndexStyle(1,DRAW_LINE,1,1);
SetIndexBuffer(1,Line_Zero);
SetIndexStyle(2,DRAW_NONE);
SetIndexBuffer(2,FractalEfficiencyTmp);
IndicatorShortName("Polarized_Fractal_Efficiency ("+Perriod+")");
SetIndexLabel(0," ISQ#481971287 ");
SetIndexLabel(1," yuriytokman@gmail.com ");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(int i=limit; i>=0; i--)
{
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//Path1 = Sqrt( (Close Close[Period])^2 + Period^2 )
//Path2 = Sum(from i=0 to Period-1)Sqrt( (Close[i] Close[i-1])^2 + 1 )
//FractalEfficiencyTmp = Sign(Close Close[Period]) * Path1 / Path2 * 100.0
//FractalEfficiency = ExpMovAvg(FractalEfficiencyTmp, Smoothing Period),
//where:
//Close[Period] (or Close[i]) is Close Period (or i) bars back,
//Sign(a) is +1 if a>0 and 1 if a<0,
//Sqrt(a) is square root of a,
//Sum is a summation operation,
//ExpMovAvg is Exponential Moving Average over Smoothing Period bars.
//Path1 is simply the hypotenuse of the big triangle formed by the current
//Close and Period bars ago Close. Path2 is the sum of hypotenuses of small
//triangles formed by each Close point.
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
double Path1, Path2 = 0, a;
Path1 = MathSqrt(MathPow(Close[i] - Close[i+Perriod],2)+MathPow(Perriod,2));
for (int k=1; k<=Perriod; k++)
Path2 += MathSqrt(MathPow(Close[i+k-1]-Close[i+k],2)+1);
a = Close[i] - Close[i+Perriod];
if (a>0) FractalEfficiencyTmp[i] = +1*Path1 / Path2 * 100.0;
else FractalEfficiencyTmp[i] = -1*Path1 / Path2 * 100.0;
}
for(i=limit; i>=0; i--)
{
FractalEfficiency[i] = iMAOnArray(FractalEfficiencyTmp,0,period_MA,0,2,i);
Line_Zero[i]=0;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments