_!DivStochv5

Download script
Author: Copyright @2011, Rockyhoangdn
_!DivStochv5

This tool is a specialized technical indicator designed for the MetaTrader platform to help traders identify potential market reversals based on momentum and price extremes. It functions by combining multiple versions of the Stochastic Oscillator into a single, smoothed visual data set.

Core Logic Overview

1. Multi-Layered Data Aggregation Instead of relying on a single standard Stochastic reading, the script calculates four different versions of the indicator simultaneously. These versions use varying timeframes (scaled by factors of 2.5, 5, and 10). By blending these four layers together, the tool creates a more comprehensive view of market momentum, filtering out "noise" that might appear in a single, shorter-term calculation.

2. Smoothing and Normalization Once the multi-layered data is combined, the script performs two main processing steps:

  • Moving Averages: It applies an Exponential Moving Average (EMA) to smooth out the fluctuations of the combined data, making the overall trend easier to read visually.
  • Inversion Logic: The script calculates both a primary value and an "inverted" value. While the primary value tracks upward momentum, the inverted value mirrors this behavior, allowing the tool to monitor both buying pressure and selling pressure simultaneously.

3. Identifying Market Extremes The indicator monitors for specific "Overbought" and "Oversold" conditions. It looks for moments where the price momentum reaches an extreme ceiling or floor. However, simply reaching these levels is not enough for a signal; the script waits for a specific shift in behavior.

4. Entry Signal Mechanics The tool generates visual signals (arrows) based on a "pullback" logic:

  • Short Entry Signals: These appear when the momentum was recently at an extreme high (Overbought) but has since dropped back down to cross below its own moving average line. This suggests that the upward move has exhausted and the price is beginning to retreat.
  • Long Entry Signals: These appear when the inverted momentum was recently at an extreme low (Oversold) but has subsequently risen to cross above its moving average line. This suggests that the downward pressure has faded and a recovery may be underway.

Summary for the User

Think of this script as a sophisticated "momentum filter." Rather than just telling you when a price is high or low, it waits for the price to hit an extreme and then confirms that the momentum is actually starting to turn around. It uses weighted averages of multiple timeframes to ensure that the signals provided are based on broader market trends rather than temporary, erratic price spikes.

Indicators Used
Stochastic oscillatorMoving average indicator
Miscellaneous
Implements a curve of type %1
7 Views
0 Downloads
0 Favorites
_!DivStochv5
//+------------------------------------------------------------------+
//|                                                 #!DivStochv5.mq4 |
//|                                    Copyright @2011, Rockyhoangdn |
//|                                           rockyhoangdn@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright @2011, Rockyhoangdn"
#property link      "rockyhoangdn@gmail.com"
#property indicator_separate_window
#property indicator_buffers 8
#property indicator_color1  DarkGreen
#property indicator_color2  Red
#property indicator_color3  Blue
#property indicator_color4  DeepPink
#property indicator_color5  Yellow
#property indicator_color6  Blue
#property indicator_color7  Red
#property indicator_color8  Lime

#property indicator_width1 3
#property indicator_width2 3
#property indicator_width3 3
#property indicator_width4 3
#property indicator_width5 2
#property indicator_width6 2
#property indicator_width7 3
#property indicator_width8 3
#property indicator_level4 60
#property indicator_level1 70
#property indicator_level2 80
#property indicator_level3 90
#property indicator_levelcolor Gray
 
#property indicator_minimum 50
#property indicator_maximum 100
extern int StochPeriod=20;
extern int Sensitive=5;
double overbought_value=99.9;
double oversold_value=99.9;
double buf[];
double bufinv[];
double mabuf[];
double mabufinv[];
double buf2[];
double overbought[];
double oversold[];
double shortentry[];
double longentry[];
int init()
  {
   SetIndexBuffer(0,buf);
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexLabel(0,"buf");

   SetIndexBuffer(1,bufinv);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexLabel(1,"bufinv");
   
   SetIndexBuffer(2,overbought);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexLabel(2,"Overbought");
   
   SetIndexBuffer(3,oversold);
   SetIndexStyle(3,DRAW_HISTOGRAM);
   SetIndexLabel(3,"Oversold");

   SetIndexBuffer(4,mabuf);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexLabel(4,"Mabuf");

   SetIndexBuffer(5,mabufinv);
   SetIndexStyle(5,DRAW_LINE);
   SetIndexLabel(5,"Mabufinv");
   
   SetIndexBuffer(6,shortentry);
   SetIndexStyle(6,DRAW_ARROW);
   SetIndexArrow(6,252);
   SetIndexLabel(6,"Shortentry");

   SetIndexBuffer(7,longentry);
   SetIndexStyle(7,DRAW_ARROW);
   SetIndexArrow(7,252);
   SetIndexLabel(7,"Longentry");

   IndicatorShortName("Div-Stochv5 - rockyhoangdn@gmail.com");
   return(0);
  }
 
int start()
  {
   int limit=Bars;
 
   ArrayResize(buf2,limit); 
   ArraySetAsSeries(buf2,true);
   for(int i=0; i<limit; i++)
    {
       buf2[i]=(iStochastic(NULL,0,StochPeriod,3,3,MODE_EMA,1,MODE_MAIN,i)+
                iStochastic(NULL,0,StochPeriod*2.5,3,3,MODE_EMA,1,MODE_MAIN,i)*2.5+
                iStochastic(NULL,0,StochPeriod*5,3,3,MODE_EMA,1,MODE_MAIN,i)*5+
                iStochastic(NULL,0,StochPeriod*10,3,3,MODE_EMA,1,MODE_MAIN,i)*10
       )/18.5;
    }
   for(i=0; i<limit; i++) 
      {
      buf[i]=iMAOnArray(buf2,limit,1,0,MODE_EMA,i);  
      bufinv[i]=100-buf[i];
      if(buf[i] >= overbought_value) overbought[i]=buf[i];
      if(bufinv[i] >= oversold_value) oversold[i]=bufinv[i];
     }

   for(int ii=0; ii<limit; ii++) 
      {
      mabuf[ii]=iMAOnArray(buf,limit,Sensitive,0,MODE_LWMA,ii);  
      mabufinv[ii]=iMAOnArray(bufinv,limit,Sensitive,0,MODE_LWMA,ii);
      }
   for(int iii=0; iii<limit; iii++) 
      {
      if((buf[iii+1] >= overbought_value && buf[iii] <=  mabuf[iii])
          ||(buf[iii+2] >= overbought_value && buf[iii] <=  mabuf[iii])
          ||(buf[iii+3] >= overbought_value && buf[iii] <=  mabuf[iii])
            )   
         {
         shortentry[iii] = buf[iii];
         }
            else shortentry[iii] =0;
            
      if((bufinv[iii+1] >= overbought_value && bufinv[iii] <=  mabufinv[iii])
         ||(bufinv[iii+2] >= overbought_value && bufinv[iii] <=  mabufinv[iii])
         ||(bufinv[iii+3] >= overbought_value && bufinv[iii] <=  mabufinv[iii])
      
      )   
         {
         longentry[iii] = bufinv[iii];
         }
            else longentry[iii] =0;
      }

   return(0);
  }

Comments