//+------------------------------------------------------------------+ //| MTF_MACD_Bars.mq5 | //| Copyright © 2008, Kirk Sloan | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2008, Kirk Sloan" #property link "" #property description "" //---- The indicator version #property version "1.00" //---- The indicator is drawn in a separate window #property indicator_separate_window //---- 4 indicator buffers #property indicator_buffers 4 //---- 4 graphical constructions are used #property indicator_plots 4 //+-----------------------------------+ //| Indicator 1 drawing parameters | //+-----------------------------------+ //---- The indicator is drawn as a three color line #property indicator_type1 DRAW_HISTOGRAM //---- Color of the histogram #property indicator_color1 clrMagenta //---- The indicator is drawn as a solid line #property indicator_style1 STYLE_SOLID //---- The width of the indicator line is 3 #property indicator_width1 3 //---- The indicator label #property indicator_label1 "Sig above MACD" //+-----------------------------------+ //| Indicator 2 drawing parameters | //+-----------------------------------+ //---- The indicator is drawn as a three color line #property indicator_type2 DRAW_HISTOGRAM //---- Color of the histogram #property indicator_color2 clrBlue //---- The indicator is drawn as a solid line #property indicator_style2 STYLE_SOLID //---- The width of the indicator line is 3 #property indicator_width2 3 //---- The indicator label #property indicator_label2 "Sig below MACD" //+-----------------------------------+ //| Indicator 3 drawing parameters | //+-----------------------------------+ //---- The indicator is drawn as a three color line #property indicator_type3 DRAW_HISTOGRAM //---- Color of the histogram #property indicator_color3 clrGreen //---- The indicator is drawn as a solid line #property indicator_style3 STYLE_SOLID //---- The width of the indicator line is 3 #property indicator_width3 3 //---- The indicator label #property indicator_label3 "Sig below MACD & Above 0" //+-----------------------------------+ //| Indicator 4 drawing parameters | //+-----------------------------------+ //---- The indicator is drawn as a three color line #property indicator_type4 DRAW_HISTOGRAM //---- Color of the histogram #property indicator_color4 clrRed //---- The indicator is drawn as a solid line #property indicator_style4 STYLE_SOLID //---- The width of the indicator line is 3 #property indicator_width4 3 //---- The indicator label #property indicator_label4 "Sig above MACD & Below 0" //+-----------------------------------+ //| Declaring constants | //+-----------------------------------+ #define RESET 0 // A constant for returning indicator recalculation command to the terminal //+-----------------------------------+ //| INPUT PARAMETERS OF THE INDICATOR| //+-----------------------------------+ input ENUM_TIMEFRAMES TimeFrame=PERIOD_H4;//Chart period //+-----------------------------------+ //| INPUT PARAMETERS OF THE INDICATOR| //+-----------------------------------+ input int MACD_Fast=8; input int MACD_Slow=17; input int MACD_Signal=9; //+-----------------------------------+ //---- Declaring dynamic arrays that will // further be used as indicator buffers double ExtMapBuffer1[]; double ExtMapBuffer2[]; double ExtMapBuffer3[]; double ExtMapBuffer4[]; //---- Declaring a variable for storing the results of indicator initialization bool Init; //---- Declaring integer variables of data calculation start int min_rates_total; //---- Declaring integer variables for the indicator handles int MACD_Handle; //+------------------------------------------------------------------+ //| Getting a string timeframe | //+------------------------------------------------------------------+ string GetStringTimeframe(ENUM_TIMEFRAMES timeframe) { //---- return(StringSubstr(EnumToString(timeframe),7,-1)); //---- } //+------------------------------------------------------------------+ //| Stochastic indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //---- Initialization of variables of the start of data calculation min_rates_total=3; Init=true; //---- Checking correctness of the chart periods if(TimeFramerates_total || prev_calculated<=0)// checking for the first start of calculation of an indicator { limit=rates_total-min_rates_total-1; // starting index for the calculation of all bars LastCountBar=rates_total; } else limit=int(LastCountBar)+rates_total-prev_calculated; // starting index for the calculation of new bars //---- indexing elements in arrays as in timeseries ArraySetAsSeries(time,true); //---- Main calculation loop of the indicator for(bar=limit; bar>=0 && !IsStopped(); bar--) { //---- Zero out the contents of the indicator buffers for the calculation ExtMapBuffer1[bar]=EMPTY_VALUE; ExtMapBuffer2[bar]=EMPTY_VALUE; ExtMapBuffer3[bar]=EMPTY_VALUE; ExtMapBuffer4[bar]=EMPTY_VALUE; //---- Copy the new data into the array if(CopyTime(Symbol(),TimeFrame,time[bar],1,iTime)<=0) return(RESET); if(time[bar]>=iTime[0] && time[bar+1]Main[0]) ExtMapBuffer1[bar]=+1;//Sig above MACD if(Signal[0]0) ExtMapBuffer3[bar]=+1;//Sig below MACD & Above 0 if(Signal[0]>Main[0] && Main[0]<0) ExtMapBuffer4[bar]=-1;//Sig above MACD & Below 0 } //---- return(rates_total); } //+------------------------------------------------------------------+