Help add EMA to ADX code

Back to topics list To post a new topic, please log in or register
avatar
2
with_ko 2016.07.17 06:34
 
 I want make code Indicator   .. I wanted to add EMA -1  to  ADX -14  
avatar
164
rod178 2016.07.17 08:08 #
 
avatar
2
with_ko 2016.07.17 08:24 #
 

Help me  !!!!!!!! I make Code  ADX 14  add EMA1  and EMA1_ shift -1  to sample  but  ema1 and ema1_shift 1   no have indicator

 


#property indicator_buffers 4
#property indicator_color1 OrangeRed
#property indicator_color2 Lime
#property indicator_color3 Magenta
#property indicator_color4 White


//---- input parameters

extern int ADXPeriod = 14;
extern int Period_EMA1 = 1;
extern int Period_EMA1_Shift=1;
extern int ModeMA  = 0;

//---- buffers

double ADXBuffer[];
double PlusDiBuffer[];
double MinusDiBuffer[];
double PlusSdiBuffer[];
double MinusSdiBuffer[];
double TempBuffer[];
double EMA1Buffer[];



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 3 additional buffers are used for counting.

   IndicatorBuffers(7);
   
//---- indicator buffers
   SetIndexBuffer(0,ADXBuffer);
   SetIndexBuffer(1,PlusDiBuffer);
   SetIndexBuffer(2,MinusDiBuffer);
   SetIndexBuffer(3,PlusSdiBuffer);
   SetIndexBuffer(4,MinusSdiBuffer);
   SetIndexBuffer(5,TempBuffer);
   SetIndexBuffer(6,EMA1Buffer);   
   
   
//---- name for DataWindow and indicator subwindow label

   IndicatorShortName("ADX("+ADXPeriod+")");
   SetIndexLabel(0,"ADX");
   SetIndexLabel(1,"+DI");
   SetIndexLabel(2,"-DI");
   SetIndexLabel(3,"EMA1");   
   
   
//----

   SetIndexDrawBegin(0,ADXPeriod);
   SetIndexDrawBegin(1,ADXPeriod);
   SetIndexDrawBegin(2,ADXPeriod);
   SetIndexDrawBegin(3,Period_EMA1);  
   
   
//----

   return(0);
  }
//+------------------------------------------------------------------+
//| Average Directional Movement Index                               |
//+------------------------------------------------------------------+
int start()
  {
   double pdm,mdm,tr;
   double price_high,price_low;
   int    starti,i,counted_bars=IndicatorCounted();
   
//+------------------------------------------------------------------+

   i=Bars-2;
   PlusSdiBuffer[i+1]=0;
   MinusSdiBuffer[i+1]=0;
   if(counted_bars>=i) i=Bars-counted_bars-1;
   starti=i;
   
//+------------------------------------------------------------------+

   while(i>=0)
     {
      price_low=Low[i];
      price_high=High[i];
      
      
      pdm=price_high-High[i+1];
      mdm=Low[i+1]-price_low;
      if(pdm<0) pdm=0;  // +DM
      if(mdm<0) mdm=0;  // -DM
      if(pdm==mdm) { pdm=0; mdm=0; }
      else if(pdm<mdm) pdm=0;
           else if(mdm<pdm) mdm=0;
     
      double num1=MathAbs(price_high-price_low);
      double num2=MathAbs(price_high-Close[i+1]);
      double num3=MathAbs(price_low-Close[i+1]);
      tr=MathMax(num1,num2);
      tr=MathMax(tr,num3);
      
      //---- counting plus/minus direction
      
      if(tr==0) { PlusSdiBuffer[i]=0; MinusSdiBuffer[i]=0; }
      else      { PlusSdiBuffer[i]=100.0*pdm/tr; MinusSdiBuffer[i]=100.0*mdm/tr; }
      //----
      i--;
     }
     
     
//+------------------------------------------------------------------+   

  
//---- last counted bar will be recounted

   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   
   
//+------------------------------------------------------------------+  

 
//---- apply EMA to +DI

   for(i=0; i<=limit; i++)
      PlusDiBuffer[i]=iMAOnArray(PlusSdiBuffer,Bars,ADXPeriod,0,MODE_EMA,i);
      
      
//+------------------------------------------------------------------+  

    
//---- apply EMA to -DI

   for(i=0; i<=limit; i++)
      MinusDiBuffer[i]=iMAOnArray(MinusSdiBuffer,Bars,ADXPeriod,0,MODE_EMA,i);
      
      
//+------------------------------------------------------------------+   

   
//---- Directional Movement (DX)

   i=Bars-2;
   TempBuffer[i+1]=0;
   i=starti;
   while(i>=0)
     {
      double div=MathAbs(PlusDiBuffer[i]+MinusDiBuffer[i]);
      if(div==0.00) TempBuffer[i]=0;
      else TempBuffer[i]=100*(MathAbs(PlusDiBuffer[i]-MinusDiBuffer[i])/div);
      i--;
     }
     
     
     
//+------------------------------------------------------------------+
     
//---- ADX is exponential moving average on DX

   for(i=0; i<limit; i++)  ADXBuffer[i]=iMAOnArray(TempBuffer,Bars,ADXPeriod,0,MODE_EMA,i); 
   
   
  
      
//+------------------------------------------------------------------+      
      


      
//----
   return(0);
  }
  
  
//+------------------------------------------------------------------+--------------+
avatar
164
rod178 2016.07.17 11:10 #
 

use the src to post code

read the documentation 

Back to topics list  

To add comments, please log in or register