_!DivStochv5onchart

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

This script is a specialized technical analysis tool designed for the MetaTrader platform. Its primary purpose is to identify specific momentum shifts and potential price reversals by combining multiple "Stochastic" indicators into a single, comprehensive visual signal.

Core Logic and Methodology

1. Multi-Layered Data Synthesis Instead of relying on a single standard indicator, the script calculates four different versions of the Stochastic Oscillator simultaneously. It uses varying periods (ranging from standard to significantly extended) and applies a weighting system to them. By averaging these different timeframes together, the tool creates a "Smoothed Stochastic" value. This approach helps filter out "noise"—the minor, insignificant price fluctuations that often trigger false signals in simpler indicators.

2. Trend Smoothing and Thresholds Once the primary composite data is established, the script applies two additional layers of refinement:

  • Smoothing: It uses a Linear Weighted Moving Average (LWMA) to further stabilize the data, ensuring the movement appears fluid rather than jagged.
  • Inversion: It calculates an "inverse" version of this data. This allows the script to monitor price momentum from both directions (upward and downward) simultaneously.

3. Signal Detection (The Entry Logic) The script looks for specific "exhaustion" patterns. It monitors when the smoothed data exceeds a pre-defined "Overbought" or "Oversold" threshold. A signal is generated specifically when the price momentum reaches these extremes but then shows signs of pulling back or crossing over its own moving average.

  • Short Signals: Identified when the upward momentum hits an extreme peak and begins to retreat.
  • Long Signals: Identified when the downward momentum hits an extreme floor and begins to recover.

4. Visual Output To make this data actionable for a trader, the script translates these mathematical calculations into clear visual markers on the price chart:

  • Text Labels: It places specific text markers at the exact moment a signal is detected.
  • Color Coding: It uses distinct colors (such as Aqua and Pink) to differentiate between potential "Buy" opportunities and "Sell" opportunities.
  • Positioning: The labels are automatically placed above or below the price candles based on the direction of the signal, providing an immediate at-a-glance reference for market sentiment.

Summary for the User

In essence, this script acts as a sophisticated filter. It takes complex momentum data from multiple timeframes, smooths it out to remove distractions, and alerts you with visual labels whenever the market shows signs of being "overextended" and potentially ready to reverse direction.

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

#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1
#property indicator_width5 1
#property indicator_width6 1
#property indicator_width7 2
 
extern int StochPeriod=20;
extern int Sensitive=5;
extern double overbought_value=99.9;
extern double oversold_value=99.9;
double buf[];
double bufinv[];
double mabuf[];
double mabufinv[];
double buf2[];
double overbought[];
double oversold[];
double shortentry[];
double longentry[];
double zigzag[];
string TOP_BOTText[5000];
int shift=0;
int deinit()
{

ObjectsDeleteAll();
   return(0);
}
int init()
  {
   SetIndexBuffer(0,buf);
   SetIndexStyle(0,DRAW_NONE);
   
   SetIndexBuffer(1,bufinv);
   SetIndexStyle(1,DRAW_NONE);
   
   SetIndexBuffer(2,mabuf);
   SetIndexStyle(2,DRAW_NONE);
   
   SetIndexBuffer(3,mabufinv);
   SetIndexStyle(3,DRAW_NONE);
   
   SetIndexBuffer(4,shortentry);
   SetIndexStyle(4,DRAW_SECTION);
   
   SetIndexBuffer(5,longentry);
   SetIndexStyle(5,DRAW_SECTION);
   
   SetIndexBuffer(6,zigzag);
   SetIndexStyle(6,DRAW_SECTION);

   IndicatorShortName("Div-Stochv3 - rockyhoangdn@gmail.com");
   return(0);
  }
 
int start()
  {
   int limit=Bars;
   for (int z = Bars; z >=0 ; z--) 
      { 
      ObjectDelete("pattern-" + z);
      }
   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] = Open[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] = Open[iii];
         }
            else longentry[iii] =0;
      }
   for(iii=0; iii<limit; iii++) 
      {
         if(shortentry[iii]!=0) zigzag[iii] = Open[iii];
         if(longentry[iii] !=0) zigzag[iii] = Open[iii];
      }
   for (int j = Bars; j >=0 ; j--) 
      { 
      TOP_BOTText[j] = "pattern-" + j;
      }
   for (shift=limit;shift>=0;shift--)
     {
     if(longentry[shift+1]!=0)
      {
      ObjectCreate(TOP_BOTText[shift+1], OBJ_TEXT, 0, Time[shift+1], Low[shift+1] - (High[shift+1] - Low[shift+1])/4 );
      ObjectSetText(TOP_BOTText[shift+1], DoubleToStr(longentry[shift+1],Digits)  , 7, "Times New Roman", Aqua);
      }
      
     if(shortentry[shift+1]!=0)
      {
      ObjectCreate(TOP_BOTText[shift+1], OBJ_TEXT, 0, Time[shift+1], High[shift+1] + (High[shift+1] - Low[shift+1])/4 );
      ObjectSetText(TOP_BOTText[shift+1],DoubleToStr(shortentry[shift+1],Digits)  , 7, "Times New Roman", Pink);
      }
     }
   return(0);
  }

Comments