//+------------------------------------------------------------------+ //| MA_DifHist.mq4 | //| Copyright © 2010, Robert Hill | //| | //| Plot the difference between 2 MAs as a histogram | //+------------------------------------------------------------------+ #property copyright "Copyright © 2010, Robert Hill" //---- indicator settings #property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 Black #property indicator_color2 Red #property indicator_color3 Green //---- input parameters extern int SlowMA_Period = 14; extern int FastMA_Period = 7; extern string m = "--Moving Average Types--"; extern string m0 = " 0 = SMA"; extern string m1 = " 1 = EMA"; extern string m2 = " 2 = SMMA"; extern string m3 = " 3 = LWMA"; extern string m5 = " 4 = LSMA"; extern int SlowMA_Type = 1; extern int FastMA_Type = 1; extern string p = "--Applied Price Types--"; extern string p0 = " 0 = close"; extern string p1 = " 1 = open"; extern string p2 = " 2 = high"; extern string p3 = " 3 = low"; extern string p4 = " 4 = median(high+low)/2"; extern string p5 = " 5 = typical(high+low+close)/3"; extern string p6 = " 6 = weighted(high+low+close+close)/4"; extern int SlowMA_AppliedPrice = 0; extern int FastMA_AppliedPrice = 0; //---- indicator buffers double ExtBuffer0[]; double ExtBuffer1[]; double ExtBuffer2[]; int SlowMA_Mode; int FastMA_Mode; double myPoint; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- drawing settings SetIndexStyle(0,DRAW_NONE); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexStyle(2,DRAW_HISTOGRAM); IndicatorDigits(Digits+1); SetIndexDrawBegin(0,34); SetIndexDrawBegin(1,34); SetIndexDrawBegin(2,34); //---- 3 indicator buffers mapping SetIndexBuffer(0,ExtBuffer0); SetIndexBuffer(1,ExtBuffer1); SetIndexBuffer(2,ExtBuffer2); //---- name for DataWindow and indicator subwindow label IndicatorShortName("MA_DifHist"); SetIndexLabel(1,NULL); SetIndexLabel(2,NULL); switch (SlowMA_Type) { case 1: SlowMA_Mode=MODE_EMA; break; case 2: SlowMA_Mode=MODE_SMMA; break; case 3: SlowMA_Mode=MODE_LWMA; break; case 4: break; default: SlowMA_Mode=MODE_SMA; break; } switch (FastMA_Type) { case 1: FastMA_Mode=MODE_EMA; break; case 2: FastMA_Mode=MODE_SMMA; break; case 3: FastMA_Mode=MODE_LWMA; break; case 4: break; default: FastMA_Mode=MODE_SMA; break; } myPoint = SetPoint(); //---- initialization done return(0); } double SetPoint() { double mPoint; if (Digits < 4) mPoint = 0.01; else mPoint = 0.0001; return(mPoint); } double iLsma(int TimeFrame, int LSMAPeriod, int LSMAPrice,int shift) { double wt; double ma1=iMA(NULL,TimeFrame,LSMAPeriod,0,MODE_SMA ,LSMAPrice,shift); double ma2=iMA(NULL,TimeFrame,LSMAPeriod,0,MODE_LWMA,LSMAPrice,shift); wt = MathFloor((3.0*ma2-2.0*ma1)/myPoint)*myPoint; return(wt); } //+------------------------------------------------------------------+ //| MA_DIfHist | //+------------------------------------------------------------------+ int start() { int limit; int counted_bars=IndicatorCounted(); double FastMA, SlowMA; double current; //---- last counted bar will be recounted if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; //---- macd for(int i=0; i=0; i--) { current=ExtBuffer0[i]; if(current>0.0) up=false; if(current<0.0) up=true; if(!up) { ExtBuffer2[i]=current; ExtBuffer1[i]=0.0; } else { ExtBuffer1[i]=current; ExtBuffer2[i]=0.0; } } //---- done return(0); } //+------------------------------------------------------------------+