//+------------------------------------------------------------------+ //| ay-SwingClose.mq4 | //| CopyRight © 2011, ahmad.yani@hotmail.com | //| http://eyesfx.web44.net | //+------------------------------------------------------------------+ #property copyright "CopyRight © 2011, ahmad.yani@hotmail.com" #property link "http://eyesfx.web44.net" #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Red #define UP_DIR 1 #define DN_DIR 2 bool FirstRun = true; int PrevDir = -1 ; datetime LastSwingTime; //---- indicator buffers double ZigZag[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0,DRAW_SECTION); //---- indicator buffers mapping SetIndexBuffer(0, ZigZag); SetIndexEmptyValue(0, EMPTY_VALUE); //---- indicator short name IndicatorShortName("SwingClose"); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit, ibar; if (FirstRun) { LastSwingTime = Time[Bars-1]; FirstRun = false; } limit = iBarShift(NULL, 0, LastSwingTime); int dir; for (ibar=limit-1; ibar>0; ibar--) { ZigZag[ibar] = EMPTY_VALUE; if ( Close[ibar]>Close[ibar+1] ) dir = UP_DIR ; else if (Close[ibar]Close[2] ) currdir1 = UP_DIR; else if ( Close[1]Close[1] ) currdir0 = UP_DIR; else if ( Close[0]