DiNapoli Detrend Oscillator_v1

Download script
DiNapoli Detrend Oscillator_v1

This tool is designed to help traders identify the underlying momentum of a financial market by isolating specific price movements from the general long-term trend. Rather than showing you the raw price of an asset, it filters out "noise" to reveal whether the current price is behaving aggressively or conservatively relative to its historical average.

Core Logic Overview

The script functions by performing a continuous comparison between two different data points: the most recent closing price and a smoothed moving average.

  1. Establishing a Baseline: The tool calculates a Moving Average (based on a user-defined period). This represents the "normal" or "average" path the price has taken over a specific window of time.
  2. Measuring the Deviation: It then looks at the current closing price and measures the gap between that price and the calculated average.
  3. Visualizing Momentum: The result of this calculation is plotted as a line on a separate window in your trading platform.

How to Interpret the Movement

By looking at the resulting line, you can gain insights into the market's behavior:

  • Above the Baseline: When the line moves upward or stays high, it indicates that the current price is trading significantly above its recent average. This suggests bullish momentum—the asset is moving faster or stronger than its usual trend.
  • Below the Baseline: When the line drops below zero or moves downward, it signifies that the price is currently lower than its recent average. This indicates bearish sentiment or a cooling off of previous gains.
  • Trend Detection: Because it "detrends" the data, the tool helps you see if a move is gaining strength (the gap is widening) or losing steam (the gap is narrowing), even if the overall market trend remains the same.

Key Customizable Parameters

To tailor the tool to different trading styles, the script includes three main adjustable settings:

  • Period Length: This determines how many previous bars are used to calculate the initial deviation. A shorter period makes the indicator more sensitive to sudden price jumps, while a longer period smooths the line out for a broader view.
  • Moving Average Period: This controls the "baseline." It dictates how much historical data is considered when determining what the "average" price should be.
  • Calculation Range: You can define how many historical bars are displayed on your screen at one time, allowing you to focus on recent history without cluttering your workspace.
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
16 Views
0 Downloads
0 Favorites
DiNapoli Detrend Oscillator_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//| DiNapoli Detrend Oscillator.mq4 
//| Treberk, www.forex-tsd.com - 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[];
extern int MAPeriod=7;


//+------------------------------------------------------------------+
//| 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();
  
//----
   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;
   

   while(i>=0)
     {
     dpo[i]=Close[i]-iMA(NULL,0,MAPeriod,MODE_SMA,0,PRICE_CLOSE,i);


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

Comments