//+------------------------------------------------------------------+ //| MaBased-ZigZag.mq4 | #property indicator_chart_window #property indicator_buffers 5 #property indicator_color1 Green #property indicator_color2 Black #property indicator_color3 Red #property indicator_color4 Blue #property indicator_color5 Red //---- buffers double zz[]; double ma[]; double ma.fast[]; double up[]; double do[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators IndicatorDigits(Digits); SetIndexStyle(0,DRAW_SECTION,STYLE_SOLID,4); SetIndexBuffer(0,zz); SetIndexEmptyValue(0,0.0); SetIndexStyle(1,DRAW_LINE); SetIndexBuffer(1,ma); SetIndexStyle(2,DRAW_LINE); SetIndexBuffer(2,ma.fast); SetIndexStyle(3,DRAW_ARROW); SetIndexArrow(3,108); SetIndexBuffer(3,up); SetIndexEmptyValue(3,0.0); SetIndexStyle(4,DRAW_ARROW); SetIndexArrow(4,108); SetIndexBuffer(4,do); SetIndexEmptyValue(4,0.0); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ extern int MaSlow.Period=14; extern int MaSlow.Type=MODE_SMMA; extern int MaSlow.Price=PRICE_CLOSE; extern int MaSlow.Shift=0; extern int MaFast.Period=3; extern int MaFast.Type=MODE_SMMA; extern int MaFast.Price=PRICE_CLOSE; extern int MaFast.Shift=0; int start() { int counted_bars=IndicatorCounted(); //---- static int direction=0; static datetime lastChange=0; static int tmpPos=0; for(int i=Bars-counted_bars-1;i>=0;i--){ ma[i]=iMA(Symbol(),Period(),MaSlow.Period,0,MaSlow.Type,MaSlow.Price,i+1+MaSlow.Shift); ma.fast[i]=iMA(Symbol(),Period(),MaFast.Period,0,MaFast.Type,MaFast.Price,i+1+MaFast.Shift); if(ma[i]ma.fast[i]){ if(direction!=-1){ direction=-1; tmpPos=iHighest(Symbol(),Period(),MODE_HIGH,iBarShift(Symbol(),Period(),lastChange,true)-i,i); zz[tmpPos]=High[tmpPos]; do[i]=High[tmpPos]; lastChange=Time[tmpPos]; } } } //---- return(0); } //+------------------------------------------------------------------+