//+------------------------------------------------------------------+ //| MACD - RSI.mq4 | //| Copyright © 2009, MetaQuotes Software Corp. | //| http://www.metaquotes.net/ | //| made in Russia by lukas1 | //+------------------------------------------------------------------+ #property copyright "Copyright © 2009, MetaQuotes Software Corp." #property link "lukas1@ngs.ru" //---- indicator settings #property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 Silver #property indicator_color2 Red #property indicator_color3 DodgerBlue #property indicator_width1 2 //---- indicator parameters extern int FastEMA=12; extern int SlowEMA=26; extern int SignalSMA=9; //---- input parameters extern int RSIPeriod=14; extern double caliber=4.0; //need for RSI caliber //---- buffers double RSIBuffer[]; double PosBuffer[]; double NegBuffer[]; //---- indicator buffers double MacdBuffer[]; double SignalBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { IndicatorBuffers(5); //---- drawing settings SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexStyle(1,DRAW_LINE); SetIndexStyle(2,DRAW_LINE); SetIndexDrawBegin(1,SignalSMA); IndicatorDigits(Digits+1); //---- indicator buffers mapping SetIndexBuffer(0,MacdBuffer); SetIndexBuffer(1,SignalBuffer); SetIndexBuffer(2,RSIBuffer); SetIndexBuffer(3,PosBuffer); SetIndexBuffer(4,NegBuffer); //---- name for DataWindow and indicator subwindow label IndicatorShortName("MACD-RSI("+FastEMA+","+SlowEMA+","+SignalSMA+"),("+RSIPeriod+")"); SetIndexLabel(0,"MACD"); SetIndexLabel(1,"Signal"); SetIndexLabel(2,"RSI"); //---- initialization done return(0); } //+------------------------------------------------------------------+ //| Moving Averages Convergence/Divergence | //+------------------------------------------------------------------+ int start() { int limit; int counted_bars=IndicatorCounted(); double rel,negative,positive; //---- last counted bar will be recounted if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; //---- macd counted in the 1-st buffer for(int i=0; i=RSIPeriod) i=Bars-counted_bars-1; while(i>=0) { double sumn=0.0,sump=0.0; if(i==Bars-RSIPeriod-1) { int k=Bars-2; //---- initial accumulation while(k>=i) { rel=MacdBuffer[k]-MacdBuffer[k+1]; if(rel>0) sump+=rel; else sumn-=rel; k--; } positive=sump/RSIPeriod; negative=sumn/RSIPeriod; } else { //---- smoothed moving average rel=MacdBuffer[i]-MacdBuffer[i+1]; if(rel>0) sump=rel; else sumn=-rel; positive=(PosBuffer[i+1]*(RSIPeriod-1)+sump)/RSIPeriod; negative=(NegBuffer[i+1]*(RSIPeriod-1)+sumn)/RSIPeriod; } PosBuffer[i]=positive; NegBuffer[i]=negative; if(negative==0.0) RSIBuffer[i]=0.0; else RSIBuffer[i]=caliber*Point*(50.0-100.0/(1+positive/negative) ); i--; } return(0); } //+------------------------------------------------------------------+