Detrended Price Oscillator
Download scriptThis tool is designed to provide traders with a visual representation of market momentum by measuring the distance between the current market price and its recent average. It functions as a "momentum oscillator," meaning it helps identify whether the price is currently trading significantly above or below its historical norms.
Core Logic and Functionality
The script operates based on the relationship between two primary data points:
- Current Price Action: The tool looks at the most recent closing price of the asset (such as a currency pair or stock).
- Moving Average Baseline: It calculates a "smoothed" average of those prices over a specific period, which you can define in the settings.
By subtracting this moving average from the current price, the script produces a single line on a separate window below your main chart.
How to Interpret the Visuals
- Above the Zero Line: When the indicator line is above zero, it signifies that the current market price is trading higher than its recent average. This typically suggests bullish momentum or an upward trend.
- Below the Zero Line: When the line drops below zero, it indicates that the price is currently lower than its recent average, which may suggest bearish momentum or a downward trend.
- Convergence and Divergence: The distance of the line from the zero mark shows the "strength" of the move. A wide gap suggests a strong trend, while the line returning toward the zero level can indicate that the current price movement is stabilizing or losing steam.
Key Customizable Settings
The tool allows for two main adjustments to tailor the logic to different trading styles:
- Period (x_prd): This determines how much historical data is considered when calculating the average. A smaller number makes the indicator react more quickly to sudden price changes, while a larger number smooths out the data to identify long-term trends.
- Count Bars: This sets the visual limit of how far back on your chart the indicator will be drawn, helping to keep your workspace clean and focused on the most relevant recent data.
In summary, this script simplifies complex price movements into a clear, readable line that highlights whether the market is currently "overstretched" in one direction or if it is reverting toward its mean.
//+------------------------------------------------------------------+
//| DPO.mq4
//| Ramdass - Conversion only
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_level1 0
extern int x_prd=7;
extern int CountBars=500;
//---- 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;
// saya tidak menggunakan variable ini dan men-set ma_shift=0
// saya blm terlalu mengerti fungsi ma_shift
// tp setingan ini memberi hasil yg sama dgn DOsc dr MT3 Indicator
// t_prd=x_prd/2+1;
// tp beda dgn DPO di TS 8.1, jd saya kembali ke asal lagi
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