Detrended Price Oscillator - DPO

Forex Market Indicator


Metatrader Technical indicator
DPO
Metatrader Technical indicator
DPO
Metatrader Technical indicator
DPO
Metatrader Technical indicator
DPO
Metatrader Technical indicator
DPO
Metatrader Technical indicator
DPO
Metatrader Technical indicator
DPO
Metatrader Technical indicator
DPO









The Detrended Price Oscillator - DPO, described in book Technical Analysis from A-Z by author Steven Achelis. Indicator Detrended Price Oscillator - DPO is an indicator in technical analysis that attempts to eliminate the long-term trends in prices by using a displaced moving average so it does not react to the most current price action. This allows the indicator to show intermediate overbought and oversold levels effectively. Indicator DPO helps to remove the trend effect and the long-term cycles in price behavior.  It helps to discover the overbought and oversold levels.  It accomplishes this by comparing the current price to a moving of price (n/2)+1 periods ago. By detrending prices, shorter-term cycles are more easily identified allowing for a quicker determination of potential overbought and oversold levels.
The Detrended Price Oscillator can be used in a variety of ways, identifying overbought and oversold conditions, divergence and  to signal long trades when the Detrended Price Oscillator - DPO crosses above the zero line and short trades when it crosses below the zero line.
Mathematical formula
The DPO is calculated by subtracting the simple moving average over an "n" day period and shifted n/2+1 days back from the price.

Detrended Price Oscillator - DPO = Close - SMA [from (n / 2 + 1) days ago



Detrended Price Oscillator - DPO MQ4 Code Base (Copy Code)
//+------------------------------------------------------------------+
//|                                  Detrended Price Oscillator.mq4  |
//|                                       Ramdass - Conversion only  |
//+------------------------------------------------------------------+
 
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
//----
extern int x_prd = 14;
extern int CountBars = 300;
//---- buffers
double dpo[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, dpo);
//---- name for DataWindow and indicator subwindow label
   short_name = "DPO(" + x_prd + ")";
   IndicatorShortName(short_name);
   SetIndexLabel(0, short_name);
//----
   if(CountBars >= Bars) 
   CountBars = Bars;
   SetIndexDrawBegin(0, Bars - CountBars + x_prd + 1);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| DPO                                                              |
//+------------------------------------------------------------------+
int start()
  {
   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);
  }
//+------------------------------------------------------------------+


Detrended Price Oscillator - DPO MQ5 Code Base (Copy Code)
//+------------------------------------------------------------------+
//|                                                          DPO.mq5 |
//|                        Copyright 2009, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright   "2009, MetaQuotes Software Corp."
#property link        "http://www.mql5.com"
#property description "Detrended Price Oscillator"
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots   1
#property indicator_type1   DRAW_LINE
#property indicator_color1  DodgerBlue
//--- input parameters
input int InpDetrendPeriod=12; // Period
//--- indicator buffers
double    ExtDPOBuffer[];
double    ExtMABuffer[];
//--- global variable
int       ExtMAPeriod;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- get length of cycle for smoothing
   ExtMAPeriod=InpDetrendPeriod/2+1;
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtDPOBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtMABuffer,INDICATOR_CALCULATIONS);
//--- set accuracy
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//--- set first bar from what index will be drawn
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtMAPeriod-1);
//--- name for DataWindow and indicator subwindow label
   IndicatorSetString(INDICATOR_SHORTNAME,"DPO("+string(InpDetrendPeriod)+")");
//--- initialization done
  }
//+------------------------------------------------------------------+
//| Detrended Price Oscillator                                       |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
   int limit;
   int firstInd=begin+ExtMAPeriod-1;
//--- correct draw begin
   if(begin>0) PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,firstInd);
//--- preliminary calculations
   if(prev_calculated<firstInd)
     {
      //--- filling  
      ArrayInitialize(ExtDPOBuffer,0.0);
      limit=firstInd;
     }
   else limit=prev_calculated-1;
//--- calculate simple moving average
   SimpleMAOnBuffer(rates_total,prev_calculated,begin,ExtMAPeriod,price,ExtMABuffer);
//--- the main loop of calculations
   for(int i=limit;i<rates_total && !IsStopped();i++)
      ExtDPOBuffer[i]=price[i]-ExtMABuffer[i];
//--- done
   return(rates_total);
  }
//+------------------------------------------------------------------+