[IMPORTANT]
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 clrGreen
#property indicator_color2 clrGreen
#property indicator_color3 clrMagenta
#property indicator_color4 clrMagenta
#property indicator_color5 clrGold
#property indicator_color6 clrGold
extern double Period_1 = 5;
extern double Period_2 = 13;
extern double Period_3 = 34;
extern int Deviation_1 = 1;
extern int Step_1 = 3;
extern int Deviation_2 = 8;
extern int Step_2 = 5;
extern int Deviation_3 = 21;
extern int Step_3 = 12;
double Up_1[];
double Dn_1[];
double Up_2[];
double Dn_2[];
double Up_3[];
double Dn_3[];
int Per1;
int Per2;
int Per3;
int Dev1;
int Stp1;
int Dev2;
int Stp2;
int Dev3;
int Stp3;
int init(){
SetIndexStyle(0,DRAW_ARROW,0,1);
SetIndexArrow(0,140);
SetIndexBuffer(0,Up_1);
SetIndexStyle(1,DRAW_ARROW,0,1);
SetIndexArrow(1,140);
SetIndexBuffer(1,Dn_1);
SetIndexStyle(2,DRAW_ARROW,0,2);
SetIndexArrow(2,141);
SetIndexBuffer(2,Up_2);
SetIndexStyle(3,DRAW_ARROW,0,2);
SetIndexArrow(3,141);
SetIndexBuffer(3,Dn_2);
SetIndexStyle(4,DRAW_ARROW,0,4);
SetIndexArrow(4,142);
SetIndexBuffer(4,Up_3);
SetIndexStyle(5,DRAW_ARROW,0,4);
SetIndexArrow(5,142);
SetIndexBuffer(5,Dn_3);
for (int i=0; i<6; i++){
SetIndexEmptyValue(i,0.0);
}
Per1 = ceil(Period() * Period_1);
Per2 = ceil(Period() * Period_2);
Per3 = ceil(Period() * Period_3);
int CDev=0;
int CSt=0;
int Mass[];
int C=0;
if (GetDevStep(Deviation_1, Step_1, C, Mass)==1){
Stp1=Mass[1];
Dev1=Mass[0];
}
if (GetDevStep(Deviation_2, Step_2, C, Mass)==1){
Stp2=Mass[1];
Dev2=Mass[0];
}
if (GetDevStep(Deviation_3, Step_3, C, Mass)==1){
Stp3=Mass[1];
Dev3=Mass[0];
}
return(0);
}
int start(){
ZZ(Up_1,Dn_1,Period_1,Dev1,Stp1);
ZZ(Up_2,Dn_2,Period_2,Dev2,Stp2);
ZZ(Up_3,Dn_3,Period_3,Dev3,Stp3);
return(0);
}
int ZZ( double& UP[], double& DN[], int Periods, int Deviation, int Step ){
int i, back;
int Last_High, Last_Low;
double val, res;
double Current_Low, Current_High, Last_H, Last_L;
for(i=Bars-Periods; i>=0; i--){
val=Low[Lowest(NULL,0,MODE_LOW,Periods,i)];
if(val==Last_L) val=0.0;
else{
Last_L=val;
if((Low-val)>(Deviation*Point)) val=0.0;
else{
for(back=1; back<=Step; back++){
res=UP[i+back];
if((res!=0)&&(res>val)) UP[i+back]=0.0;
}
}
}
UP=val;
val = High[Highest(NULL,0,MODE_HIGH,Periods,i)];
if(val==Last_H) val=0.0;
else{
Last_H=val;
if((val-High)>(Deviation*Point)) val=0.0;
else{
for(back=1; back<=Step; back++){
res=DN[i+back];
if((res!=0)&&(res<val)) DN[i+back]=0.0;
}
}
}
DN=val;
}
Last_H=-1; Last_High=-1;
Last_L=-1; Last_Low=-1;
for(i=Bars-Periods; i>=0; i--){
Current_Low=UP;
Current_High=DN;
if((Current_Low==0)&&(Current_High==0)) continue;
if(Current_High!=0){
if(Last_H>0){
if(Last_H<Current_High) DN[Last_High]=0;
else DN=0;
}
if(Last_H<Current_High || Last_H<0){
Last_H=Current_High;
Last_High=i;
}
Last_L=-1;
}
if(Current_Low!=0){
if(Last_L>0){
if(Last_L>Current_Low) UP[Last_Low]=0;
else UP=0;
}
if((Current_Low<Last_L)||(Last_L<0)){
Last_L=Current_Low;
Last_Low=i;
}
Last_H=-1;
}
}
for(i=Bars-1; i>=0; i--){
if(i>=Bars-Periods) UP=0.0;
else{
res=DN;
if(res!=0.0) DN=res;
}
}
return(0);
}
int GetMass(int val, int& M_Count, int& VMass[]){
if (val>0){
M_Count++;
int mc=ArrayResize(VMass,M_Count);
if (mc==0) return(-1);
VMass[M_Count-1]=val;
return(1);
}
else return(0);
}
int GetDevStep(int Dev, int Step, int& M_Count, int& VMass[]){
M_Count=0;
ArrayResize(VMass,M_Count);
if (GetMass(Dev,M_Count,VMass)==0) {
return(-2);
}
return(1);
}[/IMPORTANT]