log in     sign up for free
 
To be a money master, you must first be a self-master.
J. P. Morgan
 
 
Home
systems (285)
 
 
Special offer: buy MetaStock (try for free)   |   Reuters QuoteCenter Real-Time Data (get a free month)   |   EOD Data
Formula Library
 
AmiBroker
MetaTrader
MetaStock
TradeStation
Wealth-Lab
NinjaTrader
 
add your formula
System Library
 
 
Account login
Your email:
Password:
 
Log in
New to s4t? Sign up.
If you forgot your password click here.
Search the Web
 
Custom Search

DS_Stochastic

Formula for: MetaTrader

mql4 indicator

 

 

Views:  2246

Added: November 26, 2006
 
Rate this code:  Rate: 1 Rate: 2 Rate: 3 Rate: 4 Rate: 5
This formula has not been rated yet
 

email this link

 
 
Tags: MetaTrader, mql4 indicator
 


The Indicator DS_Stochastic presents an original Stochastic Oscillator (Stoch), in which aplying EMA smoothing.

The Indicator Fast Stochastic is removed on graph in the manner of two lines %K and %D.

The Formula of the calculation of the indicator Fast Stochastic is following:

DIF1(i) = EMA(Close(i) - MaxHigh(N), S);

DIF2(i) = EMA(MaxHigh(N) - MinLow(N), S);

%K(i) = 100*DIF1(i) / DIF2(i);

%D(i) = 100*EMA(DIF1(i), P) / EMA(DIF2(i), P);


where:
Close(i) - a price of the closing of the current bar;
MaxHigh(N) - maximum High for N previous period;
MinLow(N) - minimum Low for N previous period;
EMA - exponential moving average;
N - a length of the range of the calculation High/Low;
S - a period of the smoothing for %K(i);
P - a period of the smoothing for %D(i).

 

 



Code:

//+------------------------------------------------------------------+
//|                                                DS_Stochastic.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//----
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- input parameters
extern int qPeriod = 13;
extern int rPeriod = 32;
extern int EMAfast = 5;
extern int CountBars = 300;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//----
double krPeriod, kEMAfast;
double mtm, mtmInt, mtmIntPrev, mtm1, mtmInt1, mtmIntPrev1, DS_EMA;
double DS_EMAtopPrev, DS_EMAtop, DS_EMAbottomPrev, DS_EMAbottom, DS;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator lines
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(1, ExtMapBuffer2);
//----
   IndicatorShortName("DS_Stoch (" + qPeriod + "," + rPeriod + "," + EMAfast + ")");
   SetIndexLabel(0, "DS_Stoch");
   SetIndexLabel(1, "Signal");
//---- 
   krPeriod = 2 / (rPeriod + 1.0);
   kEMAfast = 2 / (EMAfast + 1.0);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| DS                                                               |
//+------------------------------------------------------------------+
int start()
  {
   int shift;
   mtmIntPrev = 0.0; 
   mtmIntPrev1 = 0.0; 
   DS_EMAtopPrev = 0.0; 
   DS_EMAbottomPrev = 0.0;
   if(Bars < CountBars + qPeriod)
       return(0);
   for(shift = CountBars; shift >= 0; shift--)
     {
       mtm = Close[shift] - Low[Lowest(NULL, 0, MODE_LOW, qPeriod, shift)];
       if(mtm == 0) 
           mtm = Point;
       mtm1 = High[Highest(NULL, 0, MODE_HIGH, qPeriod, shift)] - 
              Low[Lowest(NULL, 0, MODE_LOW, qPeriod, shift)];
       if(mtm1 == 0) 
           mtm1 = Point;
       mtmInt = mtmIntPrev + krPeriod*(mtm - mtmIntPrev); 
       mtmInt1 = mtmIntPrev1 + krPeriod*(mtm1 - mtmIntPrev1); 
       DS_EMAtop = DS_EMAtopPrev + kEMAfast*(mtmInt - DS_EMAtopPrev); 
       DS_EMAbottom = DS_EMAbottomPrev + kEMAfast*(mtmInt1 - DS_EMAbottomPrev); 
       if(!CompareDouble(mtmInt1, 0.0))
           DS = 100*mtmInt / mtmInt1;
       if(!CompareDouble(DS_EMAbottom, 0.0))       
           DS_EMA = 100*DS_EMAtop / DS_EMAbottom;
       ExtMapBuffer1[shift] = DS;
       ExtMapBuffer2[shift] = DS_EMA;
       mtmIntPrev = mtmInt; 
       mtmIntPrev1 = mtmInt1; 
       DS_EMAtopPrev = DS_EMAtop; 
       DS_EMAbottomPrev = DS_EMAbottom;
     }
//---- 
   return(0);
  }
//+------------------------------------------------------------------+
//| Функция сранения двух вещественных чисел.                        |
//+------------------------------------------------------------------+
bool CompareDouble (double Number1, double Number2)
  {
    bool Compare = NormalizeDouble(Number1 - Number2, 8) == 0;
    return(Compare);
  }
//+------------------------------------------------------------------+

 





Code to difficult? Find somebody to help you with coding here.

 



Author: Collector
Source: http://www.mql4.com/

 

View similar (mql4 indicator for MetaTrader):

Super-Signals
Chaikin's Volatility
Avg Daily Range
ATR Channels
DS_Stochastic
Inside Bar
Inside or Outside Bars
ATR Levels
ATR
ADX Crossing
...
 
 
all formulas for MetaTrader
all formulas

 

 

Email to friend

Top

 

     
However we try to maintain hiqhest possible level of service - most formulas, oscillators, indicators
and systems are submitted by anonymous users.
Therefore S4T™ does not take any responsibility for it's quality.
If you use any of this information, use it at your own risk. You are responsible for your own trading decisions.
Be sure to verify that any information you see on these pages is correct, and is applicable to your particular trade.
In no case will S4T™ be responsible for your trading gains or losses.
PayPalSecure payments by PayPal S4T™ is a part of TAURO EDUCATION NETWORK
 
Privacy note | (c) copyrights systems4trading.com 2006-2009