DPO_v1
Download scriptThis script is designed as a custom technical analysis tool for the MetaTrader platform. Its primary purpose is to visualize the relationship between the current market price and its historical average over a specific period, allowing traders to identify momentum and trend direction.
Core Functionality
The logic behind this tool centers on calculating a specific type of "distance" value. Rather than just showing you the price or a simple moving average, it measures how far the current closing price sits above or below that average.
Here is the step-by-step breakdown of how the script processes information:
- Input Configuration: The tool relies on two main user-defined settings. First, a "period" (defaulting to 14), which determines how far back into the past the script looks to calculate the average. Second, a "bar count," which dictates how much historical data is displayed on your screen at one time to keep the chart clean.
- Data Processing: The script scans through the price history starting from the specified period. For every point on the chart, it calculates a Simple Moving Average (SMA). This average represents the "baseline" of the market's behavior over that timeframe.
- The Conversion Logic: Once the baseline is established, the script subtracts that average from the actual closing price of the asset.
- If the result is positive, it indicates that the price is currently trading higher than its recent average (bullish momentum).
- If the result is negative, it indicates the price is trading lower than its recent average (bearish momentum).
- Visual Output: The final result is plotted as a continuous line in a separate window below your main price chart. Instead of fluctuating wildly with every minor tick, this line provides a smoothed representation of the price's deviation from its mean.
How to Interpret the Result
By viewing this indicator, you can quickly see whether the market is overextending itself or staying closely aligned with its average. Because it isolates only the "conversion" (the difference between price and average), it serves as a dedicated momentum oscillator. When the line moves away from the zero mark, it signals a trend; when it returns toward the zero mark, it suggests the price is returning to its historical mean.
//+------------------------------------------------------------------+
//| DPO.mq4
//| Ramdass - Conversion only
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Blue
extern int x_prd=14;
extern int CountBars=300;
//---- buffers
double dpo[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
IndicatorBuffers(1);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,dpo);
//----
return(0);
}
//+------------------------------------------------------------------+
//| DPO |
//+------------------------------------------------------------------+
int start()
{
if (CountBars>=Bars) CountBars=Bars;
SetIndexDrawBegin(0,Bars-CountBars+x_prd+1);
int i,counted_bars=IndicatorCounted();
double t_prd;
//----
if(Bars<=x_prd) return(0);
//---- initial zero
if(counted_bars<x_prd)
{
for(i=1;i<=x_prd;i++) dpo[CountBars-i]=0.0;
}
//----
i=CountBars-x_prd-1;
t_prd=x_prd/2+1;
while(i>=0)
{
dpo[i]=Close[i]-iMA(NULL,0,x_prd,t_prd,MODE_SMA,PRICE_CLOSE,i);
i--;
}
return(0);
}
//+------------------------------------------------------------------+
Comments