//+------------------------------------------------------------------+ //| ElderImpulse.mq5 | //| Copyright 2018, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Cuong Thai" #include #property indicator_buffers 8 #property indicator_plots 1 //Number of graphic plots #property indicator_type1 DRAW_COLOR_BARS //Drawing style - color candles #property indicator_color1 Red,Blue,Green //--- input parameters input int InpFast=12; input int InpSlow=16; input int EMA=13; input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE; // Applied price //--- indicator buffers double buffer_open[],buffer_high[],buffer_low[],buffer_close[]; //Buffers for data double barColors[]; double ExtFastMaBuffer[]; double ExtSlowMaBuffer[]; double ExtEMaBuffer[]; //--- MA handles int ExtFastMaHandle; int ExtSlowMaHandle; int ExtEMaHandle; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,buffer_open,INDICATOR_DATA); SetIndexBuffer(1,buffer_high,INDICATOR_DATA); SetIndexBuffer(2,buffer_low,INDICATOR_DATA); SetIndexBuffer(3,buffer_close,INDICATOR_DATA); SetIndexBuffer(4,barColors,INDICATOR_COLOR_INDEX); SetIndexBuffer(5,ExtFastMaBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(6,ExtSlowMaBuffer,INDICATOR_CALCULATIONS); PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,3); PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,Red); PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,Blue); PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,Green); ExtFastMaHandle=iMA(NULL,0,InpFast,0,MODE_EMA,InpAppliedPrice); ExtSlowMaHandle=iMA(NULL,0,InpSlow,0,MODE_EMA,InpAppliedPrice); ExtEMaHandle=iMA(NULL,0,EMA,0,MODE_EMA,InpAppliedPrice); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ 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 &tick_volume[], const long &volume[], const int &spread[]) { //--- check for data if(rates_totalrates_total || prev_calculated<0) to_copy=rates_total; else { to_copy=rates_total-prev_calculated; if(prev_calculated>0) to_copy++; } //--- get Fast EMA buffer if(IsStopped()) return(0); //Checking for stop flag if(CopyBuffer(ExtFastMaHandle,0,0,to_copy,ExtFastMaBuffer)<=0) { Print("Getting fast EMA is failed! Error",GetLastError()); return(0); } //--- get Slow EMA buffer if(IsStopped()) return(0); //Checking for stop flag if(CopyBuffer(ExtSlowMaHandle,0,0,to_copy,ExtSlowMaBuffer)<=0) { Print("Getting slow EMA is failed! Error",GetLastError()); return(0); } //--- get EMA13 buffer if(IsStopped()) return(0); //Checking for stop flag if(CopyBuffer(ExtEMaHandle,0,0,to_copy,ExtEMaBuffer)<=0) { Print("Getting EMA 13 is failed! Error",GetLastError()); return(0); } //--- int limit; if(prev_calculated==0) limit=1; else limit=prev_calculated; //--- calculate MACD double Macd1 = 0.0; double Macd2 = 0.0; for(int i=limit;iMacd1) && (ExtEMaBuffer[i]>ExtEMaBuffer[i-1])) barColors[i]=2; else if((Macd2