DoubleSmoothStochastic_2523

Download script
DoubleSmoothStochastic_2523

This script is a technical analysis tool designed for the MetaTrader trading platform. It generates a specialized visual indicator that provides traders with insights into price momentum and overbought/oversold conditions by applying multiple layers of mathematical smoothing to the standard Stochastic Oscillator.

Core Logic Overview

The logic operates through a three-stage processing sequence. Instead of simply showing raw price movements, the script filters out "market noise" to produce smoother, more reliable trend lines.

1. Primary Momentum Calculation

The first stage identifies the price range (the highest high and lowest low) over a specific period. It then calculates where the current closing price sits within that range as a percentage. This establishes the basic foundation of the momentum. To ensure stability, the script immediately applies a smoothing constant; this prevents the data from jumping erratically and helps highlight the underlying trend.

2. Secondary Smoothing Layer

Once the primary data is established, the script performs a more intensive secondary calculation. It looks back at the previous results and identifies the highest and lowest values reached within that specific set of data points. By calculating the position relative to these "peaks and valleys," it creates a second, even smoother line. This dual-layer approach is intended to filter out temporary price spikes that might otherwise trigger false signals in a standard indicator.

3. Signal Line Generation

The final stage of the logic calculates a "Signal Line." It takes the primary smoothed data and applies an additional layer of smoothing. In technical analysis, this creates a "moving average" of the momentum itself.

Summary of Visual Output

By processing the price through these three distinct mathematical layers, the script produces two primary lines on the chart:

  • The Main Line: A result of double-smoothing that represents the current trend's strength and position.
  • The Signal Line: A lagging average of the main line used to identify potential turning points or crossovers.

By reducing volatility through these successive layers, the logic aims to provide a clearer picture of market direction than a standard, raw oscillator would allow.

Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
DoubleSmoothStochastic_2523
#include <stdlib.mqh>
//+------------------------------------------------------------------+
//|                                       DoubleSmoothStochastic.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+

// This was converted using YouSky's MT3 to MT4 translator.  I cannot take credit for the code.//

#property indicator_separate_window
#property indicator_minimum 0.00
#property indicator_maximum 100.00
#property indicator_color1 Cyan
#property indicator_buffers 2
#property indicator_color2 Magenta

//+------------------------------------------------------------------+
//| Common External variables                                        |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| External variables                                               |
//+------------------------------------------------------------------+
extern double Slw = 8;
extern double Pds = 13;
extern double Slwsignal = 9;
extern int    Barcount = 2000;

//+------------------------------------------------------------------+
//| Special Convertion Functions                                     |
//+------------------------------------------------------------------+

int LastTradeTime;
double ExtHistoBuffer[];
double ExtHistoBuffer2[];

void SetLoopCount(int loops)
{
}

void SetIndexValue(int shift, double value)
{
  ExtHistoBuffer[shift] = value;
}

void SetIndexValue2(int shift, double value)
{
  ExtHistoBuffer2[shift] = value;
}

double GetIndexValue(int shift)
{
  return(ExtHistoBuffer[shift]);
}

double GetIndexValue2(int shift)
{
  return(ExtHistoBuffer2[shift]);
}

//+------------------------------------------------------------------+
//| End                                                              |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Initialization                                                   |
//+------------------------------------------------------------------+

int init()
{
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID);
   SetIndexBuffer(0, ExtHistoBuffer);
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID);
   SetIndexBuffer(1, ExtHistoBuffer2);
   return(0);
}
int start()
{
//+------------------------------------------------------------------+
//| Local variables                                                  |
//+------------------------------------------------------------------+
double AA = 0;
double bb = 0;
double aa1 = 0;
double cnt1 = 0;
int shift = 0;
double cnt = 0;
double loopbegin = 0;
double loopbegin2 = 0;
double loopbegin3 = 0;
bool first = True;
double prevbars = 0;
double sum = 0;
double smconst = 0;
double smconst1 = 0;
double prev = 0;
double prev1 = 0;
double prev2 = 0;
double prev3 = 0;
double weight = 0;
double linear = 0;
double MAValue = 0;
double MAValue2 = 0;
double mavalue3 = 0;
string MAstring = "";
double MyHigh = 0;
double MyLow = 0;
int counter = 0;
double Price = 0;
double Price1 = 0;
double tmpDevAA = 0;

SetLoopCount(0);
smconst = 2 / (1+Slw);
smconst1 = 2 / (1+Slwsignal);
	      
loopbegin = loopbegin+1; 
for(shift =Barcount;shift >=0 ;shift --)
{ 
    prev = GetIndexValue2(shift+1);
    
    // Yousky 15/05/2006 - Change to avoid Zero divide exception.
    AA = 0;
    tmpDevAA = (High[Highest(NULL, 0, MODE_HIGH,shift+Pds,Pds)] - Low[Lowest(NULL, 0, MODE_LOW,shift+Pds,Pds)]);
    
    if (tmpDevAA != 0)
      AA = 100* ((Close[shift] - Low[Lowest(NULL, 0, MODE_LOW,shift+Pds,Pds)]) / tmpDevAA);
    // ---
      
    MAValue2 = smconst * (AA-prev) + prev;
	SetIndexValue2(shift,MAValue2);
	loopbegin = loopbegin-1; 
} 

loopbegin2 = loopbegin2+1; 
for(shift =Barcount-Pds;shift >=0 ;shift --){ 
MyHigh = -999999;
MyLow = 99999999;
for(counter =shift;counter <=Pds + shift ;counter ++){ 
Price= GetIndexValue2(counter);
if( Price > MyHigh ) 
MyHigh = Price;
if( Pds <= 0 ) 
MyHigh = Price;
if( Price < MyLow ) 
MyLow = Price;
if( Pds <= 0 ) 
MyLow = Price;
} 

prev1 = GetIndexValue(shift+1);
aa1=GetIndexValue2(shift);

// Yousky 15/05/2006 - Change to avoid Zero divide exception.
bb= 0;
if ((MyHigh-MyLow) != 0)
  bb=100*(aa1-MyLow)/(MyHigh-MyLow);
// ---
  
MAValue = smconst * (bb-prev1) + prev1;
SetIndexValue(shift,MAValue);
loopbegin2 = loopbegin2-1; 
} 


loopbegin3 = loopbegin3+1; 
for(shift =Barcount;shift >=0 ;shift --){ 
prev2=GetIndexValue2(shift+1);
prev3=GetIndexValue(shift);
mavalue3= smconst1 * (prev3-prev2) +prev2;

SetIndexValue2(shift,mavalue3);
loopbegin3 = loopbegin3-1;
} 

}

Comments