Can someone help me how to extract previous three HH, HL, LL and LH from the code of ZigZag indicator? I have removed the indicator functionality portion from the code, so it can be suitably modified to convert into a function.
I would like to convert it into a function.
Thanks in advance for your support and guidance.
//+------------------------------------------------------------------------------------------------------------------------------+//| Script to create Function get_ZigZagValues.mq4//+------------------------------------------------------------------------------------------------------------------------------+#property strictinputint InpDepth = 9; // Depthinputint InpDeviation = 5; // Deviationinputint InpBackstep = 3; // Backstep// Define buffersdouble ExtZigzagBuffer[];
double ExtHighBuffer[];
double ExtLowBuffer[];
// Define Globalsint ExtLevel = 3; // recounting's depth of extremums//+-----------------------------------------------------------------------------------------------------------------------------+//| Custom initialization function//+-----------------------------------------------------------------------------------------------------------------------------+intOnInit()
{
ArrayInitialize(ExtZigzagBuffer,0);
ArrayInitialize(ExtHighBuffer,0);
ArrayInitialize(ExtLowBuffer,0);
//--- first counting positionreturn(Bars - InpDepth);
}
//+-----------------------------------------------------------------------------------------------------------------------------+//| Extract HH, HL, LL and LH prices from the ZigZag indicator code//+-----------------------------------------------------------------------------------------------------------------------------+voidOnStart()
{
int i,limit,counterZ,whatlookfor=0;
int backStep,pos,lasthighpos=0,lastlowpos=0;
double extremum;
double current_Low = 0;
double current_High = 0;
double last_High = 0;
double last_Low = 0;
// Check for history and inputsif(Bars > InpDepth || InpBackstep <= InpDepth)
// First calculationsif(IndicatorCounted() == 0)
limit = (Bars - InpDepth);
else
{
i = counterZ = 0;
// Find first extremum in the depth ExtLevel or 100 last barswhile(counterZ < ExtLevel && i < 100)
{
if(ExtZigzagBuffer[i] != 0)
counterZ++;
i++;
}
// No extremum found, recounting all from beginif(counterZ == 0)
limit = (Bars - InpDepth);
// Set start position to found extremum positionelse
{
limit = i-1;
// What kind of extremum?if(ExtLowBuffer[i] != 0)
{
current_Low = ExtLowBuffer[i]; // Low extremum
whatlookfor = 1; // Will look for the next high extremum
}
else
{
current_High = ExtHighBuffer[i]; // High extremum
whatlookfor = -1; // Will look for the next low extremum
}
// Clear the rest datafor(i = limit-1; i >= 0; i--)
{
ExtZigzagBuffer[i] = 0;
ExtLowBuffer[i] = 0;
ExtHighBuffer[i] = 0;
}
}
}
// Main loopfor(i = limit; i >= 0; i--)
{
// Find lowest Close in depth of bars
extremum = Close[iLowest(NULL,0,MODE_CLOSE,InpDepth,i)];
// This lowest has been found previouslyif(extremum == last_Low)
extremum = 0;
else
{
last_Low = extremum; // New last lowif(Close[i] - extremum > InpDeviation * Point) // Discard extremum if current Close is too high
extremum = 0;
else
{
for(backStep = 1; backStep <= InpBackstep; backStep++) // Clear previous extremums in backstep bars
{
pos = i + backStep;
if(ExtLowBuffer[pos] != 0 && ExtLowBuffer[pos] > extremum)
ExtLowBuffer[pos] = 0;
}
}
}
// Found extremum is current Closeif(Close[i] == extremum)
ExtLowBuffer[i] = extremum;
else
ExtLowBuffer[i] = 0;
// Find highest Close in depth of bars
extremum = Close[iHighest(NULL,0,MODE_CLOSE,InpDepth,i)];
// This highest has been found previouslyif(extremum == last_High)
extremum = 0;
else
{
last_High = extremum; // New last highif(extremum - Close[i] > InpDeviation * Point) // Discard extremum if current Close is too low
extremum = 0;
else
{
for(backStep = 1; backStep <= InpBackstep; backStep++) // Clear previous extremums in backstep bars
{
pos = i + backStep;
if(ExtHighBuffer[pos] != 0 && ExtHighBuffer[pos] < extremum)
ExtHighBuffer[pos] = 0;
}
}
}
// Found extremum is current Closeif(Close[i] == extremum)
ExtHighBuffer[i] = extremum;
else
ExtHighBuffer[i] = 0;
}
// Final cuttingif(whatlookfor == 0)
{
last_Low = 0;
last_High = 0;
}
else
{
last_Low = current_Low;
last_High = current_High;
}
for(i = limit; i >= 0; i--)
{
switch(whatlookfor)
{
case0: // look for peak or lawnif(last_Low == 0 && last_High == 0)
{
if(ExtHighBuffer[i] != 0)
{
last_High = Close[i];
lasthighpos = i;
whatlookfor = -1;
ExtZigzagBuffer[i] = last_High;
}
if(ExtLowBuffer[i] != 0)
{
last_Low = Close[i];
lastlowpos = i;
whatlookfor = 1;
ExtZigzagBuffer[i] = last_Low;
}
}
break;
case1: // look for peakif(ExtLowBuffer[i] != 0 && ExtLowBuffer[i] < last_Low && ExtHighBuffer[i] == 0)
{
ExtZigzagBuffer[lastlowpos] = 0;
lastlowpos = i;
last_Low = ExtLowBuffer[i];
ExtZigzagBuffer[i] = last_Low;
}
if(ExtHighBuffer[i] != 0 && ExtLowBuffer[i] == 0)
{
last_High = ExtHighBuffer[i];
lasthighpos = i;
ExtZigzagBuffer[i] = last_High;
whatlookfor = -1;
}
break;
case -1: // look for lawnif(ExtHighBuffer[i] != 0 && ExtHighBuffer[i] > last_High && ExtLowBuffer[i] == 0)
{
ExtZigzagBuffer[lasthighpos] = 0;
lasthighpos = i;
last_High = ExtHighBuffer[i];
ExtZigzagBuffer[i] = last_High;
}
if(ExtLowBuffer[i]!=0 && ExtHighBuffer[i]==0)
{
last_Low = ExtLowBuffer[i];
lastlowpos = i;
ExtZigzagBuffer[i] = last_Low;
whatlookfor = 1;
}
break;
}
}
// Completed processing
}
//+------------------------------------------------------------------------------------------------------------------------------+
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hi Friend
Can someone help me how to extract previous three HH, HL, LL and LH from the code of ZigZag indicator? I have removed the indicator functionality portion from the code, so it can be suitably modified to convert into a function.
I would like to convert it into a function.
Thanks in advance for your support and guidance.