_i_EF_distance
Download scriptOverview
The i_EF_distance tool is a specialized technical indicator designed to analyze price movements by measuring the relative "distance" or displacement between current prices and historical data over a specific period. Unlike standard moving averages that simply calculate the mean of past prices, this script utilizes a mathematical weighting system to identify more significant price trends.
Core Logic & Methodology
The indicator operates through a three-step calculation process to generate its visual output:
1. Distance Measurement (Power Calculation) The script first examines a set window of recent price bars (defined by the "Length" parameter). For every point in this window, it calculates the numerical difference between the current price and the prices preceding it. By applying a "Power" factor to these differences, the script amplifies larger price gaps. This means that significant jumps or sharp movements in price are given more weight than minor fluctuations.
2. Cumulative Weighting Once the distances are calculated, the tool aggregates these values. It essentially creates a running total of the "intensity" of price movement across the selected timeframe. By summing these weighted differences, the indicator builds a profile of how volatile or active the recent price action has been.
3. Weighted Average Smoothing In the final stage, the script produces its primary visual line. It calculates a weighted average where each historical price is multiplied by its corresponding intensity value (the result from the previous steps). This ensures that periods of high price activity have a greater influence on the resulting line than periods of stagnation. The tool then normalizes this data to ensure the final output remains consistent with the current price scale on your chart.
Key Objectives
- Trend Filtering: By focusing on the magnitude of price movement, the indicator attempts to filter out "noise" and highlight significant directional shifts.
- Dynamic Responsiveness: The use of the "Power" variable allows for a customized sensitivity; higher values emphasize large price swings more aggressively, while lower values provide a smoother, more conservative view of the trend.
- Visual Representation: The final result is plotted as a continuous line on the chart, providing traders with a smoothed representation of price momentum based on historical displacement rather than simple averages.
//+------------------------------------------------------------------+
//| _i_EF_distance.mq4 |
//| Copyright © 2006, Doji Starr |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Doji Starr"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Aqua
// input params
extern int Length = 10;
extern double Power = 2;
// vars
int i, c, startBar;
double coef, norm;
// buffers
double buf_el[], buf_co[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(2);
SetIndexBuffer(0,buf_el);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(1,buf_co);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
if (Bars <= Length)
return(0);
int bar;
int counted_bars = IndicatorCounted();
if (counted_bars < 1)
{
// filling initial values in buffers
for (bar=Bars-1; bar>=Bars-Length*2; bar--)
{
buf_el[bar] = Close[bar];
buf_co[bar] = 0.0;
}
startBar = Bars-Length*2-1;
}
else
startBar = Bars-counted_bars-1;
for (bar=startBar; bar>=0; bar--)
{
buf_co[bar] = 0.0;
for (i=Length-1; i>=0; i--)
buf_co[bar] += MathAbs(MathPow(Close[bar]-Close[bar+i], Power));
norm = 0.0;
buf_el[bar] = 0.0;
for (i=Length-1; i>=0; i--)
{
norm += buf_co[bar+i];
buf_el[bar] += buf_co[bar+i] * Close[bar+i];
}
if (norm != 0)
buf_el[bar] /= norm;
else
buf_el[bar] = 0.0;
//Print(norm);
}
return(0);
}
Comments