//+---------------------------------------------------------------------+ //| Digital_MACD.mq5 | //| Copyright © 2006, CrazyChart | //+---------------------------------------------------------------------+ //| Place the SmoothAlgorithms.mqh file | //| in the directory: terminal_data_folder\MQL5\Include | //+---------------------------------------------------------------------+ #property copyright "Copyright © 2006, CrazyChart" #property link "" //--- Indicator version #property version "1.00" //--- drawing the indicator in a separate window #property indicator_separate_window //--- number of indicator buffers 4 #property indicator_buffers 4 //--- two plots are used #property indicator_plots 2 //+-----------------------------------+ //| Indicator 1 drawing parameters | //+-----------------------------------+ //---- drawing indicator as a four-color histogram #property indicator_type1 DRAW_COLOR_HISTOGRAM //--- the following colors are used in the four color histogram #property indicator_color1 clrMagenta,clrIndianRed,clrGray,clrBlueViolet,clrDeepSkyBlue //--- Indicator line is a solid one #property indicator_style1 STYLE_SOLID //--- indicator line width is 2 #property indicator_width1 2 //--- displaying the indicator label #property indicator_label1 "Digital MACD" //+-----------------------------------+ //| Indicator 2 drawing parameters | //+-----------------------------------+ //---- drawing the indicator as a three-colored line #property indicator_type2 DRAW_COLOR_LINE //---- the following colors are used in a three-color line #property indicator_color2 clrRed,clrGray,clrLimeGreen //--- Indicator line is a solid one #property indicator_style2 STYLE_SOLID //--- indicator line width is 3 #property indicator_width2 3 //---- displaying the signal line label #property indicator_label2 "Signal Line" //+-----------------------------------+ //| Description of smoothing classes | //+-----------------------------------+ #include //+-----------------------------------+ //--- declaration of the CXMA class variables from the SmoothAlgorithms.mqh file CXMA XMA; //+-----------------------------------+ //| Declaration of enumerations | //+-----------------------------------+ enum Applied_price_ //Type of constant { PRICE_CLOSE_ = 1, //Close PRICE_OPEN_, //Open PRICE_HIGH_, //High PRICE_LOW_, //Low PRICE_MEDIAN_, //Median Price (HL/2) PRICE_TYPICAL_, //Typical Price (HLC/3) PRICE_WEIGHTED_, //Weighted Close (HLCC/4) PRICE_SIMPLE_, //Simple Price (OC/2) PRICE_QUARTER_, //Quarted Price (HLOC/4) PRICE_TRENDFOLLOW0_, //TrendFollow_1 Price PRICE_TRENDFOLLOW1_, //TrendFollow_2 Price PRICE_DEMARK_ //Demark Price }; //+-----------------------------------+ //| Indicator input parameters | //+-----------------------------------+ input Smooth_Method Signal_Method=MODE_SMA; //Signal line averaging method input int Signal_XMA=5; //Signal line period input int Signal_Phase=100; // Signal line parameter input Applied_price_ AppliedPrice=PRICE_CLOSE_;//price constant //+-----------------------------------+ //---- declaration of the integer variables for the start of data calculation int min_rates_total,min_rates_1; //--- declaration of dynamic arrays that //--- will be used as indicator buffers double DMACDBuffer[],SignBuffer[],ColorDMACDBuffer[],ColorSignBuffer[]; //+------------------------------------------------------------------+ //| DMACD indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //--- initialization of variables of data calculation start min_rates_1=66; min_rates_total=min_rates_1+XMA.GetStartBars(Signal_Method,Signal_XMA,Signal_Phase)+2; //--- set DMACDBuffer dynamic array as an indicator buffer SetIndexBuffer(0,DMACDBuffer,INDICATOR_DATA); //--- Setting a dynamic array as a color index buffer SetIndexBuffer(1,ColorDMACDBuffer,INDICATOR_COLOR_INDEX); //--- set SignBuffer dynamic array as an indicator buffer SetIndexBuffer(2,SignBuffer,INDICATOR_DATA); //--- Setting a dynamic array as a color index buffer SetIndexBuffer(3,ColorSignBuffer,INDICATOR_COLOR_INDEX); //--- shifting the start of drawing of the indicator PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total); //--- setting the indicator values that won't be visible on a chart PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE); //--- shifting the start of drawing of the indicator PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total); //--- setting the indicator values that won't be visible on a chart PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE); //--- setting up alerts for unacceptable values of external variables XMA.XMALengthCheck("Signal_XMA",Signal_XMA); //--- setting up alerts for unacceptable values of external variables XMA.XMAPhaseCheck("Signal_Phase",Signal_Phase,Signal_Method); //--- initializations of a variable for the indicator short name string shortname; string Smooth=XMA.GetString_MA_Method(Signal_Method); StringConcatenate(shortname,"Digital_MACD( ",Signal_XMA,", ",Smooth," )"); //--- creation of the name to be displayed in a separate sub-window and in a pop up help IndicatorSetString(INDICATOR_SHORTNAME,shortname); //--- determining the accuracy of the indicator values IndicatorSetInteger(INDICATOR_DIGITS,0); //--- initialization end } //+------------------------------------------------------------------+ //| DMACD iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, // number of bars in history at the current tick const int prev_calculated,// amount of history in bars at the previous tick const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- checking if the number of bars is enough for the calculation if(rates_totalrates_total || prev_calculated<=0)// Checking for the first start of the indicator calculation { first1=min_rates_1; // starting number for calculating all bars of the first loop first2=min_rates_1+1; // starting number for calculation of all bars of the second loop first3=min_rates_total+1; // starting index for calculation of all third loop bars } else // starting number for calculation of new bars { first1=prev_calculated-1; first2=first1; first3=first1; } //--- main indicator calculation loop for(bar=first1; bar0) { if(DMACDBuffer[bar]>DMACDBuffer[bar-1]) clr=4; if(DMACDBuffer[bar]DMACDBuffer[bar-1]) clr=1; } ColorDMACDBuffer[bar]=clr; } //--- main loop of the signal line coloring for(bar=first3; barSignBuffer[bar-1]) clr=2; if(DMACDBuffer[bar]