//+------------------------------------------------------------------+
//|                                                FiveStep-T06R.mq4 |
//+------------------------------------------------------------------+

#property copyright " Copyright © 2006, HomeSoft-Tartan Corp."
#property link      " spiky@transkeino.ru"

#property indicator_chart_window
#property indicator_color1 Lime
#property indicator_buffers 2
#property indicator_color2 Gold
#include <stdlib.mqh>

extern double depth = 20;
extern double deviation = 5;
extern double backstep = 3;
extern double mBar = 50;

double Buffer1[];
double Buffer2[];

int shift = 0;
double ssig = 0;
double bsig = 0;
double zz = 0;
double zzo = 0;
double k = 0;
int i = 0;
double jb = 0;
double js = 0;
double sflag = 0;
double bflag = 0;
double null = 0;

int init()
{
   SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID);
   SetIndexBuffer(0, Buffer1);
   SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID);
   SetIndexBuffer(1, Buffer2);
   return(0);
}
int start()
{

for(shift=Bars-1;shift>=0;shift--){ 
	Buffer1[shift]=0;
	Buffer2[shift]=0;
} 

null=0.00001;

for(shift=mBar;shift>=0;shift--){ 

zz=iCustom(NULL, 0, "ZigZagS",depth,deviation,backstep,mBar,0,shift);
if(zz!=0 && zz!=zzo) zzo=zz;

k=0;js=0;jb=0;
for(i=shift+1;i<=shift+5;i++){ 
if(Close[i]==Open[i]) k=k+1;
if(Close[i]>Open[i]) js=js+1;
if(Close[i]<Open[i]) jb=jb+1;
} 

if(((zz>Open[shift] && zz!=0) || (zzo>Open[shift] && zz==0)) 
                 && js+k==5 && k<=1 && jb==0) { sflag=1;ssig=High[shift]+5*Point;}  else ssig=null;
   
if(((zz<Open[shift] && zz!=0) || (zzo<Open[shift] && zz==0)) 
                 && jb+k==5 && k<=1 && js==0) { bflag=1;bsig=Low[shift]-5*Point;}  else bsig=null;
                 
if(ssig>1) bflag=0; 
if(bsig>1) sflag=0;

if(ssig==null && sflag==1 && zz!=0 && Open[shift]<zz) ssig=High[shift]+5*Point; else ssig=null;
if(bsig==null && bflag==1 && zz!=0 && Open[shift]>zz) bsig=Low[shift]-5*Point; else bsig=null; 


	Buffer1[shift]=ssig;
	Buffer2[shift]=bsig;} 
  return(0);
}