/* * Watts MACD: the MACD indicator as shwon in Watts scalping system. * However, I added a style input choice. Style 0 will plot MACD histograms * in two different colors based on if the histogram bar is > or < 0. The * style choice of 1 will plot MACD histograms in two different colors based * on if current histogram bar is > or < than previous histogram bar. * Style 0 is the original style of Watts system. * * Use it at your own risk. * * Author: Peter Chen * * History: * 6/13/2008: First Verision. */ //---- indicator settings #property indicator_separate_window //Buffers needed to draw indicators #property indicator_buffers 5 //Histograms #property indicator_color1 Gray #property indicator_color2 Lime #property indicator_color3 Red //MA lines on histograms #property indicator_color4 Lime #property indicator_color5 DeepPink #property indicator_width1 1 #property indicator_width2 1 #property indicator_width3 1 #property indicator_width4 2 #property indicator_width5 2 //---- indicator parameters extern int FastEMA = 34; extern int SlowEMA = 89; extern int SignalEMA = 13; extern int HistoSMA1 = 1; extern int HistoSMA5 = 5; extern int Style = 1; //0 or 1 //---- indicator buffers double HistoBuffer[]; double MacdBuffer[]; double SignalBuffer[]; //These are used for painting double MA1Buffer[]; double MA5Buffer[]; double ExtBuffer0[]; double HistoUpBuffer[]; double HistoDnBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //3 additional buffers are used for a total of 8 buffers IndicatorBuffers(8); //---- drawing settings SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexStyle(2,DRAW_HISTOGRAM); SetIndexStyle(3,DRAW_LINE); SetIndexStyle(4,DRAW_LINE); SetIndexDrawBegin(0,SlowEMA); SetIndexDrawBegin(1,SlowEMA); SetIndexDrawBegin(2,SlowEMA); SetIndexDrawBegin(3,SlowEMA); SetIndexDrawBegin(4,SlowEMA); IndicatorDigits(Digits+2); SetIndexBuffer(0,ExtBuffer0); SetIndexBuffer(1,HistoUpBuffer); SetIndexBuffer(2,HistoDnBuffer); SetIndexBuffer(3,MA1Buffer); SetIndexBuffer(4,MA5Buffer); SetIndexBuffer(5,HistoBuffer); SetIndexBuffer(6,MacdBuffer); SetIndexBuffer(7,SignalBuffer); //---- name for DataWindow and indicator subwindow label IndicatorShortName("Watts_MACD("+FastEMA+","+SlowEMA+","+SignalEMA+")"); //---- initialization done return(0); } //+------------------------------------------------------------------+ //| Moving Average of Oscillator | //+------------------------------------------------------------------+ int start() { int limit; double current = 0; double prev = 0; int counted_bars=IndicatorCounted(); if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; for(int i=0; i<limit; i++) MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i); for(i=0; i<limit; i++) SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalEMA,0,MODE_EMA,i); for(i=0; i<limit; i++) HistoBuffer[i]=MacdBuffer[i]-SignalBuffer[i]; for(i=0; i<limit; i++) { MA1Buffer[i]=iMAOnArray(HistoBuffer,Bars,HistoSMA1,0,MODE_SMA,i); } for(i=0; i<limit; i++) { MA5Buffer[i]=iMAOnArray(HistoBuffer,Bars,HistoSMA5,0,MODE_SMA,i); } //Paint the bars for (i = 0; i < limit; i++) { current = HistoBuffer[i]; prev = HistoBuffer[i+1]; if (Style == 0) { if (current > 0) { HistoUpBuffer[i] = current; HistoDnBuffer[i] = 0.0; ExtBuffer0[i] = 0.0; } else if (current < 0) { HistoUpBuffer[i] = 0.0; HistoDnBuffer[i] = current; ExtBuffer0[i] = 0.0; } else { HistoUpBuffer[i] = 0.0; HistoDnBuffer[i] = 0.0; ExtBuffer0[i] = current; } } else { //Assume 1 if (current > prev) { HistoUpBuffer[i] = current; HistoDnBuffer[i] = 0.0; ExtBuffer0[i] = 0.0; } else if (current < prev) { HistoUpBuffer[i] = 0.0; HistoDnBuffer[i] = current; ExtBuffer0[i] = 0.0; } else { HistoUpBuffer[i] = 0.0; HistoDnBuffer[i] = 0.0; ExtBuffer0[i] = current; } } } //---- done return(0); } //+------------------------------------------------------------------+
Sample
Analysis
Market Information Used:
Indicator Curves created:
Implements a curve of type DRAW_HISTOGRAM
Implements a curve of type DRAW_LINE
Indicators Used:
Moving average indicator
Custom Indicators Used:
Order Management characteristics:
Other Features: