Previous Next

GZigZag

The class GZigZag offers the possibility to use the ZigZag indicator in a very simple way.

Simply create the class and the data will be automatically determined. From then on, the values can be read out with the simple specification of the shift offset of the desired Zig-Zag.


Creating and destroying the class

To create the class and destroy it when finished, 5 simple steps are necessary. You can take these steps from the example.

Example:

//--- Include Glib classes
#include <Glib.mqh>

//--- Creation of a pointer to an empty class object
GZigZag *zigZag;


int OnInit ()
{
   //--- Assign the class to the empty class object
   zigZag = gZigZag();

   //--- Initialize the data of the class
   zigZag.Init();

   return(INIT_SUCCEEDED);
}

void OnDeinit (const int reason)
{
   //--- Bei beenden Speicher freigeben
   delete zigZag;
}

From this point on you can use the class functions.

Due to the amount of data Glib produces, a few ticks are required to collect all data when starting.

To check whether all data has been prepared and to avoid errors when starting, it is recommended to check the class function .Ready() for true.

Example:

void OnTick ()
{
   if ( zigZag.Ready() ) //--- Will be executed only when all data are ready
   {
      //--- Output the price of the penultimate extreme point:
      Print( zigZag.Get(PERIOD_D1, 2).price );
   }
}


Class functions

Return value

Function call

Function

Deinit()

Pre-destruction of the class. To remove the class data gently.

void

Init()

Initialization of the class default data. Set up with which default values the class should work.

GStructZigZag

Get()

Get a GStructZigZag object with the data of a given extreme point.

void

GetAll()

Write all extreme point object data to a GStructZigZag array.

void

GetAllLineLengths()

Write all line lengths between the extreme points into a double array.

double

GetPrice()

Get the price of a given extreme point.

void

GetAllPrices()

Write all extreme point prices into a double array.

bool

Ready()

Checks if the class is ready to use.


Class Structures

struct  GStructZigZag
{

   int       shift;   // Shift in bars
   datetime  date;    // Time of the extremum
   double    price;   // Price of the extreme point
   bool      isZig;   // Extreme point upward (Zig)? else downward (Zag).

   long      Volume;  // Volume of the extreme point
   double    RSI;     // RSI value of the extreme point
   double    MFI;     // MFI value of the extreme point
   };