Navigation:Home > Content >

DYMI.mq4

Time: 2012-06-04 | Download file:DYMI.mq4

//+------------------------------------------------------------------+
//|                                                          RSI.mq4 |
//|                      Copyright © 2004, 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_minimum 0
#property indicator_maximum 100
#property indicator_buffers 1
#property indicator_level1     10.0
#property indicator_level2     90.0
#property indicator_color1 DodgerBlue
//---- input parameters


extern int stdevLength = 5;
extern int avgOfStdevLength = 10;
extern int DYMILength = 30;
extern int DYMILengthLowerLimit = 3;
extern int DYMILengthUpperLimit = 30;

int RSIPeriod;

//---- buffers
double RSIBuffer[];
double PosBuffer[];
double NegBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(3);
   SetIndexBuffer(1,PosBuffer);
   SetIndexBuffer(2,NegBuffer);
//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,RSIBuffer);
//---- name for DataWindow and indicator subwindow label
   short_name="DYMI("+stdevLength+","+avgOfStdevLength+","+DYMILength+","+DYMILengthLowerLimit+","+DYMILengthUpperLimit+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//----
   SetIndexDrawBegin(0,DYMILength);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Relative Strength Index                                          |
//+------------------------------------------------------------------+
int start()
  {
   int    i,counted_bars=IndicatorCounted(), limitedLength;
//----
   if(Bars<=DYMILength) return(0);
//---- initial zero
   if(counted_bars<1)
      for(i=1;i<=DYMILength;i++) RSIBuffer[Bars-i]=0.0;
//----
   i=Bars-DYMILength-1;
   if(counted_bars>=DYMILength) i=Bars-counted_bars-1;
   while(i>=0)
     { limitedLength  = Get_LimLen(i);
       if (limitedLength != 0)
        RSIBuffer[i] = iRSI(Symbol(),0,limitedLength,PRICE_CLOSE,i);
        else  RSIBuffer[i] =  RSIBuffer[i+1];
      i--;
     }
//----
   return(0);
  }
  
double StdDev(int shift)  
{ 
   int    j;
   int bar = Bars;
   if (barDYMILengthUpperLimit) limitedLength = 0;
   if (limitedLength= DYMILengthLowerLimit && dynamicLength<=DYMILengthUpperLimit) 
    limitedLength = dynamicLength; 
   else limitedLength = 0;
*/
 return(limitedLength);
}

int Get_Value(int shift)
{
 return (Close[shift]-Close[shift+1]);
}
  
  
  
//+------------------------------------------------------------------+

/*

#
# TD Ameritrade IP Company, Inc. (c) 2008-2014
#


input length = 14;
input over_bought = 70;
input over_sold = 30;
input price = close;

def NetChgAvg = ExpAverage(price - price[1], length);
def TotChgAvg = ExpAverage(AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then 50*(NetChgAvg / TotChgAvg+1) else 0;

plot RSI_EMA = ChgRatio;
plot OverSold = over_sold;
plot OverBought = over_bought;

RSI_EMA.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(5));
OverSold.SetDefaultColor(GetColor(5));


---------------

declare lower;

input price = close;
input stdevLength = 5;
input avgOfStdevLength = 10;
input DYMILength = 14;
input DYMILengthLowerLimit = 3;
input DYMILengthUpperLimit = 30;

def std = stdev(price, stdevLength);
def ratio = std / Average(std, avgOfStdevLength);
def dynamicLength = Floor(DYMILength / ratio);
def limitedLength = if dynamicLength between DYMILengthLowerLimit and DYMILengthUpperLimit then dynamicLength else 0;
def sf = 2 / (limitedLength + 1);
def bn = Max(barNumber(), 0);
# 10^-5 precision for ema multiplier
def expIndex = if limitedLength == 0 then 1 else max(1, bn - ceil(-5 / lg(1 - sf)));
def fromIndex = if isNan(expIndex) then 1 else expIndex;
def chg = price - price[1];
def absChg = AbsValue(chg);
def netChgAvg = fold indexN = fromIndex to bn + 1 with accuN do sf * (if isnan(getValue(chg, bn - indexN)) then 0 else getValue(chg, bn - indexN)) + (1 - sf) * accuN;
def totChgAvg = fold indexT = fromIndex to bn + 1 with accuT do sf * (if isnan(getValue(absChg, bn - indexT)) then 0 else getValue(absChg, bn - indexT)) + (1 - sf) * accuT;
def RSI = if totChgAvg != 0 and limitedLength != 0 then 50 * (netChgAvg / totChgAvg + 1) else RSI[1];

plot DYMI = RSI;
plot OverBought = 90;
plot OverSold = 10;

DYMI.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(5));
OverSold.SetDefaultColor(GetColor(5));








*/

Recommend