# Get time value of last zag and zag

73

Hello,

Could somebody helt me get the time of the last zig and zag value. I have this to find the value:

```      int m5, x5;     //Her er det egentlig m, x men jeg førte også på valutaparet
x5=0;
while(m5<2)
{
if(zig5>0) zag5=zig5;
zig5=iCustom(NULL, 5, "ZigZag",ExtDepth,ExtDeviation,ExtBackstep,0, x5); // husk å bruke rett timeframe
if(zig5>0) m5+=1;
x5++;
}

When I have the time I will use iBarshift to find the barshift:

zag5Barshift = iBarShift(NULL,0,timezag5);
zig5Barshift = iBarShift(NULL,0,timezig5);
```
15582

1. IBarShift takes a TIME and give you the SHIFT. If you already have the shift just use Time[shift]
2. Just get the last two non-zero zigzag shifts and you're done - no iBarShift needed.
```for(x5 = 0; x5 < Bars; x5++){
zig5=iCustom(NULL, 5, "ZigZag",ExtDepth,ExtDeviation,ExtBackstep,0, x5); // husk å bruke rett timeframe
if(zig5 != 0.) break;
}
for(m5 = x5+1; m5 < Bars; m5++){
zig5=iCustom(NULL, 5, "ZigZag",ExtDepth,ExtDeviation,ExtBackstep,0, m5); // husk å bruke rett timeframe
if(zig5 != 0.) break;
}
Print("last two are at ",
m5, "<", Time[m5], "> and ",
x5,"<", Time[x5], ">");
```
73

Great! I then wantet to use the time and shift values further in my EA so I created TimeAtZig,TimeAtZag,BarAtZig,BarAtZag and BarDifference like this. I guess thats the way to to it but I'm just learning:-) In case somebody else need it:

```double zig5;
double zag5;
double TimeAtZig;
double TimeAtZag;
int BarAtZig ;
int BarAtZag ;
int BarDifference;
int ExtDepth=5; // zigzag indicator
int ExtDeviation=5;
int ExtBackstep=3;

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
{
//----

int m5, x5;     //Her er det egentlig m, x men jeg førte også på valutaparet
x5=0;
while(m5<2)
{
if(zig5>0) zag5=zig5;
zig5=iCustom(NULL, 5, "ZigZag",ExtDepth,ExtDeviation,ExtBackstep,0, x5); // husk å bruke rett timeframe
if(zig5>0) m5+=1;
x5++;
}

for(x5 = 0; x5 < Bars; x5++){
zig5=iCustom(NULL, 5, "ZigZag",ExtDepth,ExtDeviation,ExtBackstep,0, x5);
if(zig5 != 0.) break;
}
for(m5 = x5+1; m5 < Bars; m5++){
zig5=iCustom(NULL, 5, "ZigZag",ExtDepth,ExtDeviation,ExtBackstep,0, m5);
if(zig5 != 0.) break;
}
TimeAtZig = Time[m5];
TimeAtZag = Time[x5];
BarAtZig = m5;
BarAtZag = x5;
BarDifference = BarAtZig - BarAtZag;

Alert( "TimeAtZig ", TimeToStr(TimeAtZig, TIME_SECONDS)," TimeAtZag ",TimeToStr(TimeAtZag,TIME_SECONDS));
Alert( "BarAtZig ", BarAtZig,"  BarAtZag ",BarAtZag, " BarDifference " , BarDifference);

//----
return(0);
}
//+------------------------------------------------------------------+```