Navigation´╝ÜHome > Content >

color_MACD.mq5

Time: 2015-03-26 | Download file:color_MACD.mq5

//+------------------------------------------------------------------+
//|                                              MACD - original.mq5 |
//+------------------------------------------------------------------+
#property copyright   ""
#property link        ""
#property description "Moving Average Convergence/Divergence"
#include 

//
//
//
//
//

#property indicator_separate_window
#property indicator_buffers 5
#property indicator_plots   2
#property indicator_type1   DRAW_COLOR_HISTOGRAM
#property indicator_type2   DRAW_LINE
#property indicator_color1  DimGray, LimeGreen, Green, Red, FireBrick
#property indicator_color2  Gold
#property indicator_width1  2
#property indicator_width2  1
#property indicator_label1  "MACD"
#property indicator_label2  "Signal"

//
//
//
//
//

input int                InpFastEMA      = 12;
input int                InpSlowEMA      = 26; 
input int                InpSignalEMA    =  9; 
input ENUM_APPLIED_PRICE InpAppliedPrice = PRICE_CLOSE;

//
//
//
//
//

double  ExtMacdBuffer[];
double  ExtSignalBuffer[];
double  ExtFastMaBuffer[];
double  ExtSlowMaBuffer[];
double  Colors[];


int     ExtFastMaHandle;
int     ExtSlowMaHandle;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

void OnInit()
{
   SetIndexBuffer(0,ExtMacdBuffer,  INDICATOR_DATA);
   SetIndexBuffer(1,Colors         ,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(2,ExtSignalBuffer,INDICATOR_DATA);
   SetIndexBuffer(3,ExtFastMaBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(4,ExtSlowMaBuffer,INDICATOR_CALCULATIONS);

   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,InpSignalEMA-1);
   IndicatorSetString(INDICATOR_SHORTNAME,"MACD original("+string(InpFastEMA)+","+string(InpSlowEMA)+","+string(InpSignalEMA)+")");

   //
   //
   //
   //
   //
   
   ExtFastMaHandle=iMA(NULL,0,InpFastEMA,0,MODE_EMA,InpAppliedPrice);
   ExtSlowMaHandle=iMA(NULL,0,InpSlowEMA,0,MODE_EMA,InpAppliedPrice);
}

//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,const int prev_calculated,
                const datetime &Time[],
                const double &Open[],
                const double &High[],
                const double &Low[],
                const double &Close[],
                const long &TickVolume[],
                const long &Volume[],
                const int &Spread[])
{

   //
   //
   //
   //
   //
   
   if (rates_totalrates_total || prev_calculated<0) to_copy=rates_total;
         else
            {
               to_copy=rates_total-prev_calculated;
               if(prev_calculated>0) to_copy++;
            }
            
   if (!doCopy(ExtFastMaHandle,ExtFastMaBuffer,to_copy,"fast MA buffer")) return(0);
   if (!doCopy(ExtSlowMaHandle,ExtSlowMaBuffer,to_copy,"slow MA buffer")) return(0);

   //
   //
   //
   //
   //
   
   int limit;
   if(prev_calculated==0)
         limit = 0;
   else  limit = prev_calculated-1;
   for(int i=limit;i0)
      {
         if (ExtMacdBuffer[i]>ExtMacdBuffer[i-1]) Colors[i] = 1;
         if (ExtMacdBuffer[i]ExtMacdBuffer[i-1]) Colors[i] = 4;
      }
   }         
   ExponentialMAOnBuffer(rates_total,prev_calculated,0,InpSignalEMA,ExtMacdBuffer,ExtSignalBuffer);
   
   //
   //
   //
   //
   //
   
   return(rates_total);
}
  
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//

bool checkCalculated(int bufferHandle, int total, string checkDescription)
{
   int calculated=BarsCalculated(bufferHandle);
   if (calculated        

Recommend