//+------------------------------------------------------------------+ //| PatternMACD.mq4 | //| Copyright © 2011, Khlystov Vladimir | //| http://cmillion.narod.ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2011, cmillion@narod.ru" #property link "http://cmillion.narod.ru" #property indicator_separate_window #property indicator_buffers 6 #property indicator_color1 Silver #property indicator_color2 Red #property indicator_color3 Red #property indicator_color4 Blue #property indicator_color5 Blue #property indicator_color6 Red #property indicator_width1 2 #property indicator_width5 1 #property indicator_width6 1 #property indicator_level1 0.0015 #property indicator_level2 0.0030 #property indicator_level3 0.0045 #property indicator_level4 -0.0015 #property indicator_level5 -0.0030 #property indicator_level6 -0.0045 //---- indicator parameters extern int FastEMA=12; extern int SlowEMA=26; extern int SignalSMA=9; extern bool DrawInfo = true; //---- indicator buffers double MacdBuffer[]; double SignalBuffer[]; double BufferUp[]; double BufferDn[]; double BufferBuy[]; double BufferSell[]; double Dn0,Dn1,Dn2,Up0,Up1,Up2; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- drawing settings SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexStyle(1,DRAW_LINE); SetIndexDrawBegin(1,SignalSMA); IndicatorDigits(Digits+1); SetIndexStyle(2,DRAW_ARROW); SetIndexArrow(2,217); SetIndexStyle(3,DRAW_ARROW); SetIndexArrow(3,218); SetIndexStyle(4,DRAW_ARROW); SetIndexArrow(4,233); SetIndexStyle(5,DRAW_ARROW); SetIndexArrow(5,234); //---- indicator buffers mapping SetIndexBuffer(0,MacdBuffer); SetIndexBuffer(1,SignalBuffer); SetIndexBuffer(2,BufferUp); SetIndexBuffer(3,BufferDn); SetIndexBuffer(4,BufferBuy); SetIndexBuffer(5,BufferSell); //---- name for DataWindow and indicator subwindow label IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")"); SetIndexLabel(0,"MACD"); SetIndexLabel(1,"Signal"); SetIndexLabel(4,"Buy"); SetIndexLabel(5,"Sell"); //---- initialization done if (DrawInfo) ObjectsDeleteAll(); return(0); } //+------------------------------------------------------------------+ //| Moving Averages Convergence/Divergence | //+------------------------------------------------------------------+ int start() { int limit; int counted_bars=IndicatorCounted(); if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; for(int i=0; i=0; i--) { if (BufferUp[i+1]==EMPTY_VALUE && MacdBuffer[i+2] < MacdBuffer[i+1] && MacdBuffer[i+1] > MacdBuffer[i]) {BufferUp[i+1]=MacdBuffer[i+1];Up2=Up1;Up1=Up0;Up0=MacdBuffer[i+1];} if (BufferDn[i+1]==EMPTY_VALUE && MacdBuffer[i+2] > MacdBuffer[i+1] && MacdBuffer[i+1] < MacdBuffer[i]) {BufferDn[i+1]=MacdBuffer[i+1];Dn2=Dn1;Dn1=Dn0;Dn0=MacdBuffer[i+1];} if (BufferUp[i+1]!=EMPTY_VALUE) { if (Up1 > 0.0045 && Up0 > 0.0030 && Up0 < 0.0045 && Dn0>0) {BufferSell[i]=MacdBuffer[i];Text(Red,"А",i);} //паттерн А if (Dn0 < -0.0030 && Dn0 > -0.0045 && Up0 < -0.0015 && Up0 > -0.0030) {BufferSell[i]=MacdBuffer[i];Text(Red,"С",i);} //паттерн C if (Up2 < Up1 && Up1 > Up0 && Up0 > 0.0000 && Up1 > 0.0045 && Up2 > 0.0000 && Dn0 > 0.0030 && Dn1 > 0.0030/* && Dn0 < 0.0045 && Dn1 < 0.0045*/) {BufferSell[i]=MacdBuffer[i];Text(Red,"г & п",i);} //голова и плечи if (Up1 > Up0 && Up0 > 0.0045 && Dn0 > 0.0045) {BufferSell[i]=MacdBuffer[i];Text(Red,"дв",i);} //двойная вершина if (Up0 > -0.0015 && Up0 < -0.0000 && Dn0 < -0.0015) {BufferSell[i]=MacdBuffer[i];Text(Red,"р0",i);} //разворот у ноля } if (BufferDn[i+1]!=EMPTY_VALUE) { if (Dn1 < -0.0045 && Dn0 < -0.0030 && Dn0 > -0.0045 && Up0 < 0) {BufferBuy[i]=MacdBuffer[i];Text(Blue,"D",i);} //паттерн D if (Up0 > 0.0030 && Up0 < 0.0045 && Dn0 > 0.0015 && Dn0 < 0.0030) {BufferBuy[i]=MacdBuffer[i];Text(Blue,"B",i);} //паттерн B if (Dn2 > Dn1 && Dn1 < Dn0 && Dn0 < -0.0000 && Dn1 < -0.0045 && Dn2 < -0.0000 && Up0 < -0.0030 && Up1 < -0.0030/* && Up0 > -0.0045 && Up1 > -0.0045*/) {BufferBuy[i]=MacdBuffer[i];Text(Blue,"г & п",i);} //голова и плечи if (Dn1 < Dn0 && Dn0 < -0.0045 && Up0 < -0.0045) {BufferBuy[i]=MacdBuffer[i];Text(Blue,"дд",i);} //двойное дно if (Dn0 < 0.0015 && Dn0 > 0.0000 && Up0 > 0.0015) {BufferBuy[i]=MacdBuffer[i];Text(Blue,"р0",i);} //разворот у ноля } } //Comment("Up2 ",Up2," Up1 ",Up1," Up0 ",Up0," Dn2 ",Dn2," Dn1 ",Dn1," Dn0 ",Dn0); for(i=0; i