DPO_alert

This tool is a specialized technical analysis indicator designed to help traders identify price momentum by filtering out long-term market trends. Instead of looking at the raw price movements, it focuses on "detrending" the data—essentially stripping away the background noise of a persistent uptrend or downtrend to reveal whether the current price action is strengthening or weakening relative to its recent history.

How the Logic Works

1. Trend Filtering (The "Detrending" Process) The core logic operates by comparing two different types of moving averages simultaneously:

  • A very short-term average (representing immediate price movement).
  • A longer-term average (representing the broader trend).

By subtracting the longer-term average from the short-term average, the indicator produces an oscillator. This tells you how far the current price has deviated from its established path. When the resulting line is above zero, it suggests that the immediate price momentum is higher than the long-term average; when below zero, it suggests lower momentum.

2. Visual Representation The indicator appears in a separate window at the bottom of your trading chart as a continuous line (colored DodgerBlue). This allows you to see fluctuations independent of the main price candles, making it easier to spot "overbought" or "oversold" conditions without being distracted by major price swings.

3. Smart Alert System The script includes a built-in notification system designed to capture specific turning points automatically. It watches for "Zero Crosses," which occur when the oscillator line moves from negative territory to positive (a potential bullish shift) or from positive to negative (a potential bearish shift).

You can customize how these alerts behave:

  • Volume Check: The script is configured to only trigger alerts if there is actual trading activity (volume) occurring.
  • Timing Options: You can choose to receive an alert the moment a cross happens in real-time or wait until the current candle closes to confirm the move, which helps filter out "fake" signals caused by rapid price flickering during a live minute.
  • Audio Feedback: If configured, the tool will play a specific sound file to notify you of these shifts immediately.

Summary for the Trader

Essentially, this tool simplifies complex market data into a single line. It tells you when the immediate "pulse" of the market is shifting direction compared to its historical average, providing a clearer picture of momentum and alerting you the moment that momentum flips.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screenIt plays sound alerts
12 Views
0 Downloads
0 Favorites
DPO_alert
//+------------------------------------------------------------------+
//|                                  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;
extern bool AlertsEnabled  = true;
extern bool AlertAfterBarClose = true;
extern string AlertsSound = "alert.wav";
//---- buffers
double dpo[];
datetime AlertTime;
//+------------------------------------------------------------------+
//| 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] = iMA(NULL, 0, 1, 0, MODE_SMA, PRICE_CLOSE, i) - iMA(NULL, 0, x_prd, t_prd, MODE_SMA, PRICE_CLOSE, i);
       i--;
     }
     
if (AlertsEnabled  && AlertTime != Time[0]&& Volume[0]>1) 
		{
	
			if ((AlertAfterBarClose  && (dpo[i+1] > 0 && dpo[i+2] <= 0) || (dpo[i+1] < 0 && dpo[i+2] >= 0)) ||
		      (!AlertAfterBarClose  && (dpo[i] > 0 && dpo[i+1] <= 0) || (dpo[i] < 0 && dpo[i+1] >= 0))  )
			{

				AlertTime = Time[0];
				Alert("DPO Cross 0 ", Symbol(), " M", Period());

		    if (StringLen(AlertsSound) > 0)
					PlaySound(AlertsSound);
			}
		}
	
	 
 		         
   return(0);
  }
//+------------------------------------------------------------------+

Comments