DiNapoli Detrend Oscillator

Download script
DiNapoli Detrend Oscillator

This script creates a specialized visual tool designed to help traders identify price trends by removing the "noise" or general direction of the market. It functions as an oscillator, meaning it appears in a separate window below your main price chart rather than directly on the candles.

Core Logic and Functionality

The primary goal of this tool is to isolate the momentum of the price by comparing current values against a moving average. Here is how the logic flows:

1. Trend Filtering The script calculates a "Moving Average"—which is essentially the average price over a specific period—to establish a baseline for what the market is doing normally. By subtracting this average from the current closing price, the tool strips away the long-term trend to reveal the short-term fluctuations.

2. Visual Representation The resulting data is plotted as a blue line. This line represents the "distance" between the current price and its recent average.

  • When the line is above zero, it suggests that the current price is trading higher than the recent average.
  • When the line drops below zero, it indicates that the price is trading lower than the average.

3. Customization Settings The script allows for two primary adjustments:

  • Period (x_prd): This determines how many previous bars are analyzed to calculate the data points. Adjusting this changes the sensitivity of the oscillator.
  • Bar Count: This manages how much historical data is displayed on your screen, ensuring the chart remains clean and relevant to your current viewing area.

Summary for Traders

In practical terms, this tool acts like a magnifying glass for price action. Instead of looking at whether the market is going "up" or "down" overall, it helps you see how much the price is deviating from its recent norm. It provides a smoother, more readable way to observe price momentum, making it easier to spot potential shifts in strength or weakness without being distracted by the general direction of the market.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
DiNapoli Detrend Oscillator
//+------------------------------------------------------------------+
//| DiNapoli Detrend Oscillator.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,7,MODE_SMA,0,PRICE_CLOSE,i);


      i--;
     }
   return(0);
  }
//+------------------------------------------------------------------+

Comments