Previous Next

GSupportAndResistance

The class GSupportAndResistance is setting important course marks at which support and resistance can be found.

Just create the class and the data will be determined automatically. The values can then be read and used with simple functions.


Creating and destroying the class

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

Example:

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

//--- Creating a pointer to an empty class object
GSupportAndResistance *supportAndResistance;


int OnInit ()
{
   //--- Assign the class to the empty class object
   supportAndResistance = gSupportAndResistance();

   //--- Initialize the class data
   supportAndResistance.Init();

   return(INIT_SUCCEEDED);
}

void OnDeinit (const int reason)
{
   //--- At the end, free memory
   delete supportAndResistance;
}

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 ( supportAndResistance.Ready() ) //--- The code will only be executed when all data is ready
   {
      //--- Draws all found supports, resistances and pivot points on the chart.
      supportAndResistance.Paint();
   }
}


Class functions

Return value

Function call

Function

Deinit()

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

void

Init()

Initialize the class defaults. Configure the class.

void

InitPivots()

Optional initialization of the pivot points.

void

GetAll()

Writes all support and resistance information to a GStructSupportAndResistanceDetails object array.

void

GetAllPrices()

Writes all prices of supports and resistances into a double array.

void

GetPivots()

Adds the prices of the pivot points to a double array.

void

Paint()

Draws support and resistance levels and pivot points on the chart.

void

ClearPaint()

Removes all drawings of the class from the chart.

void

SetFontSize()

Changes the text size of the chart markings created by the class.

void

SetMarkersLengthRight()

Changes the multiplier for setting the maximum length of the drawn lines to the right.

bool

Ready()

Checks if the class is ready for use.

void

ChartEvent()

Sets the chart events to reduce the class and to increase the clarity in the chart.


Structures of the class

struct  GStructSupportAndResistanceDetails
{

   ENUM_TIMEFRAMES  timeFrame;  // Timeframe of the price level
   int              touches;    // Number of touches
   double           price;      // Price of the price level

   datetime         begin;       // Time of first touch
   datetime         end;         // Time of last touch
   int              beginShift;  // Shift of the first touch in bars
   int              endShift;    // Shift of the last touch in bars

   double           singleTouchPrices[];     // Prices of each touch around the course level
   int              singleTouchShiftBars[];  // Shift of individual touches in bars
   int              singleTouchShiftZigZagAbsolute[];  // Shift of single touches in ZigZags
   };


Enumerations of the class

ENUM_SUPPORTANDRESISTANCE

Identifikator

Description

SAR_ALL

All support and resistance lines and pivot points. Please note also .GetPivots()

SAR_SUPPORT

All support lines.

SAR_RESISTANCE

All resistance lines.

SAR_PIVOT

All pivot points.


ENUM_PIVOTS

Identifier

Description

PIVOT

Pivot Point

PIVOT_S1

Pivot Support 1

PIVOT_S2

Pivot Support 2

PIVOT_S3

Pivot Support 3

PIVOT_R1

Pivot Resistance 1

PIVOT_R2

Pivot Resistance 2

PIVOT_R3

Pivot Resistance 3