_i_EF_distance_v1

Download script
Author: Copyright � 2006, Doji Starr
_i_EF_distance_v1

This tool is designed to analyze price movements on a trading chart by calculating a specialized weighted average of the market's closing prices. Unlike standard moving averages that treat every previous price point with equal importance, this script applies a sophisticated mathematical logic to identify which prices are most significant based on their proximity and "distance" from the current price.

How the Logic Works

The script operates through a three-step process to determine the highlighted value:

1. Measuring Price Distance For every specific point in time, the tool looks back at a set number of previous candles (defined by the user). It calculates the "distance" between the current price and each of those past prices. By using a power variable, the script can be adjusted to prioritize how aggressively it penalizes larger price gaps.

2. Determining Relative Importance The core logic relies on the principle that prices closer to the current market value should carry more weight in the final calculation than older or much further-away prices. The tool calculates an importance factor for each past price based on the distances measured in the first step. If a price is very close to the current level, it is given a higher significance; if it is far away, its influence is reduced.

3. Calculating the Weighted Value Finally, the script combines all these pieces of information. It takes every past price, multiplies it by its calculated importance (its "weight"), and then averages them together. This results in a smoothed line on your chart that reacts dynamically to market volatility.

Key Characteristics

  • Dynamic Weighting: Because the weights change constantly as the market moves, the indicator provides a more nuanced view of price trends than a simple average.
  • Customizable Sensitivity: Users can adjust the look-back period and the "power" of the calculation to make the indicator smoother or more responsive to sudden price spikes.
  • Trend Smoothing: The primary goal of this logic is to filter out minor market noise while staying closely aligned with the most relevant recent price actions, helping traders see the underlying direction of the market more clearly.
Miscellaneous
Implements a curve of type %1
6 Views
0 Downloads
0 Favorites
_i_EF_distance_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

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