//------------------------------------------------------------------------------------
// Nth ZIGZAG value
//------------------------------------------------------------------------------------
double getNthZIGZAGValue(string _SYMBOL, int _TIMEFRAME, bool UpperLower, int Nth)
{
double result = 0;
int i = 0;
int NthZIGZAG = 2*Nth + 1;
double ZIGZAG1 = 0;
double ZIGZAG2 = 0;
while(i < 1000 && NthZIGZAG > 0)
{
result = iCustom(_SYMBOL, _TIMEFRAME, "ZigZag", 12, 5, 3, 0, i);
i++;
if(result > 0)
{
ZIGZAG1 = ZIGZAG2;
ZIGZAG2 = result;
NthZIGZAG--;
continue;
}
}
if(UpperLower)
{
if(ZIGZAG1 > ZIGZAG2)
result = ZIGZAG1;
else
result = ZIGZAG2;
}
else
{
if(ZIGZAG1 > ZIGZAG2)
result = ZIGZAG2;
else
result = ZIGZAG1;
}
return (result);
}
//------------------------------------------------------------------------------------
// Nth ZIGZAG time
//------------------------------------------------------------------------------------
datetime getNthZIGZAGTime(string _SYMBOL, int _TIMEFRAME, bool UpperLower, int Nth)
{
double result = 0;
int i = 0;
int NthZIGZAG = 2*Nth + 1;
double ZIGZAG1 = 0;
double ZIGZAG2 = 0;
int ZIGZAG1Time = 0;
int ZIGZAG2Time = 0;
while(i < 1000 && NthZIGZAG > 0)
{
result = iCustom(_SYMBOL, _TIMEFRAME, "ZigZag", 12, 5, 3, 0, i);
i++;
if(result > 0)
{
ZIGZAG1 = ZIGZAG2;
ZIGZAG2 = result;
ZIGZAG1Time = ZIGZAG2Time;
ZIGZAG2Time = i - 1;
NthZIGZAG--;
continue;
}
}
if(UpperLower)
{
if(ZIGZAG1 > ZIGZAG2)
result = ZIGZAG1Time;
else
result = ZIGZAG2Time;
}
else
{
if(ZIGZAG1 > ZIGZAG2)
result = ZIGZAG2Time;
else
result = ZIGZAG1Time;
}
return(iTime(_SYMBOL, _TIMEFRAME, result));
}
//-----------------------------------------------------------------

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
How to get the tree last values of indicator Zig zag, last high or last low etc.