DivergenceViewer_MultiSymbols_AD

Author: Scriptong
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
DivergenceViewer_MultiSymbols_AD
ÿþ#property copyright "Scriptong"

#property link      "http://advancetools.net"

#property description "English: Multisymbols scaner of divergence.\nRussian: C;LB820;NB=K9 A:0=5@ 4825@35=F89."

#property version "1.04"

#property strict



#define     MAX_SYMBOLS                                        50



#property indicator_chart_window



#include <Divergence_Viewer_MultiSymbols_Classes_AD.mqh>



enum ENUM_YESNO

{

   NO,                                                                                             // No / 5B

   YES                                                                                             // Yes / 0

};



enum ENUM_ONOFF

{

   OFF,                                                                                            // Off / K:;.

   ON                                                                                              // On / :;.

};



struct TFInfo

{

   ENUM_TIMEFRAMES      tf;

   string               text;

};



// 0AB@>5G=K5 ?0@0<5B@K 8=48:0B>@0

input ENUM_INDICATOR_TYPE      i_indicatorType       = WILLIAM_BLAU;                               // Base indicator / 07>2K9 8=48:0B>@

input int                      i_divergenceDepth     = 20;                                         // Depth of 2nd ref. point search / ;C18=0 ?>8A:0 2>9 >?. B>G:8



input string                   i_string1             = "The base indicator parameters / 0@0<5B@K 107>2>3> 8=48:0B>@0";            // ============================

input int                      i_barsPeriod1         = 8000;                                       // First calculate period / 5@2K9 ?5@8>4 @0AG5B0

input int                      i_barsPeriod2         = 2;                                          // Second calculate period / B>@>9 ?5@8>4 @0AG5B0

input int                      i_barsPeriod3         = 1;                                          // Third calculate period / "@5B89 ?5@8>4 @0AG5B0

input ENUM_APPLIED_PRICE       i_indAppliedPrice     = PRICE_CLOSE;                                // Applied price of indicator / &5=0 @0AG5B0 8=48:0B>@0

input ENUM_MA_METHOD           i_indMAMethod         = MODE_EMA;                                   // MA calculate method / 5B>4 @0AG5B0 A@54=53>



input string                   i_string2             = "Price extremum parameters / 0@0<5B@K F5=>2>3> M:AB@5<C<0";            // ============================

input int                      i_findExtInterval     = 10;                                         // Price ext. to indicator ext. / B M:AB. F5=K 4> M:AB. 8=4.

input ENUM_MARKET_APPLIED_PRICE i_marketAppliedPrice = MARKET_APPLIED_PRICE_CLOSE;                 // Applied price of market / A?>;L7C5<0O @K=>G=0O F5=0



input string                   i_string3             = "Custom indicator / >;L7>20B5;LA:89 8=48:0B>@";            // ============================

input string                   i_customName          = "Sentiment_Line";                           // The name of indicator / <O 8=48:0B>@0

input int                      i_customBuffer        = 0;                                          // Index of data buffer / =45:A 1CD5@0 4;O AJ5<0 40==KE

input ENUM_CUSTOM_PARAM_CNT    i_customParamCnt      = PARAM_CNT_3;                                // Amount of ind. parameters / >;-2> ?0@0<5B@>2 8=48:0B>@0

input double                   i_customParam1         = 13.0;                                      // Value of the 1st parameter / =0G5=85 1->3> ?0@0<5B@0

input double                   i_customParam2         = 1.0;                                       // Value of the 2nd parameter / =0G5=85 2->3> ?0@0<5B@0

input double                   i_customParam3         = 0.0;                                       // Value of the 3rd parameter / =0G5=85 3->3> ?0@0<5B@0

input double                   i_customParam4         = 0.0;                                       // Value of the 4th parameter / =0G5=85 4->3> ?0@0<5B@0

input double                   i_customParam5         = 0.0;                                       // Value of the 5th parameter / =0G5=85 5->3> ?0@0<5B@0

input double                   i_customParam6         = 0.0;                                       // Value of the 6th parameter / =0G5=85 6->3> ?0@0<5B@0

input double                   i_customParam7         = 0.0;                                       // Value of the 7th parameter / =0G5=85 7->3> ?0@0<5B@0

input double                   i_customParam8         = 0.0;                                       // Value of the 8th parameter / =0G5=85 8->3> ?0@0<5B@0

input double                   i_customParam9         = 0.0;                                       // Value of the 9th parameter / =0G5=85 9->3> ?0@0<5B@0

input double                   i_customParam10        = 0.0;                                       // Value of the 10th parameter / =0G5=85 10->3> ?0@0<5B@0

input double                   i_customParam11        = 0.0;                                       // Value of the 11th parameter / =0G5=85 11->3> ?0@0<5B@0

input double                   i_customParam12        = 0.0;                                       // Value of the 12th parameter / =0G5=85 12->3> ?0@0<5B@0

input double                   i_customParam13        = 0.0;                                       // Value of the 13th parameter / =0G5=85 13->3> ?0@0<5B@0

input double                   i_customParam14        = 0.0;                                       // Value of the 14th parameter / =0G5=85 14->3> ?0@0<5B@0

input double                   i_customParam15        = 0.0;                                       // Value of the 15th parameter / =0G5=85 15->3> ?0@0<5B@0

input double                   i_customParam16        = 0.0;                                       // Value of the 16th parameter / =0G5=85 16->3> ?0@0<5B@0

input double                   i_customParam17        = 0.0;                                       // Value of the 17th parameter / =0G5=85 17->3> ?0@0<5B@0

input double                   i_customParam18        = 0.0;                                       // Value of the 18th parameter / =0G5=85 18->3> ?0@0<5B@0

input double                   i_customParam19        = 0.0;                                       // Value of the 19th parameter / =0G5=85 19->3> ?0@0<5B@0

input double                   i_customParam20        = 0.0;                                       // Value of the 20th parameter / =0G5=85 20->3> ?0@0<5B@0



input string                   i_string4             = "Filters / $8;LB@K";                        // ============================

input ENUM_ONOFF               i_useCoincidenceCharts = OFF;                                       // The coincidence of charts / !>2?045=85 3@0D8:>2



input string                   i_string5             = "Symbols and periods / !8<2>;K 8 ?5@8>4K";  // ============================

input string                   i_symbols             = "EURUSD,USDCHF,GBPUSD,USDJPY";              // Symbols separated by commas / !8<2>;K, @0745;5==K5 70?OBK<8

input ENUM_YESNO               i_tfM1                = YES;                                        // Use TF M1 / A?>;L7>20BL "$ 1

input ENUM_YESNO               i_tfM5                = YES;                                        // Use TF M5 / A?>;L7>20BL "$ 5

input ENUM_YESNO               i_tfM15               = NO;                                         // Use TF M15 / A?>;L7>20BL "$ 15

input ENUM_YESNO               i_tfM30               = NO;                                         // Use TF M30 / A?>;L7>20BL "$ 30

input ENUM_YESNO               i_tfH1                = YES;                                        // Use TF H1 / A?>;L7>20BL "$ H1

input ENUM_YESNO               i_tfH4                = YES;                                        // Use TF H4 / A?>;L7>20BL "$ H4

input ENUM_YESNO               i_tfD1                = YES;                                        // Use TF D1 / A?>;L7>20BL "$ D1

input ENUM_YESNO               i_tfW1                = YES;                                        // Use TF W1 / A?>;L7>20BL "$ W1

input ENUM_YESNO               i_tfMN1               = YES;                                        // Use TF MN1 / A?>;L7>20BL "$ MN1



input string                   i_string6             = "Parameters of divergence / 0@0<5B@K 4825@35=F89";                    // ============================

input color                    i_divAbsentColor      = clrDarkSlateGray;                           // Color of divergence absent / &25B >BACBAB28O 4825@35=F88

input ENUM_YESNO               i_isAlert             = YES;                                        // Alert on divergence? / !83=0; ?@8 4825@35=F88?

input ENUM_YESNO               i_isPush              = YES;                                        // Notification on divergence? / #254><;OBL ?@8 4825@35=F88?

input string                   i_string6_1           = "Divergence class A / 825@35=F88 :;0AA0 ";// ============================

input ENUM_YESNO               i_showClassA          = YES;                                        // Show / B>1@060BL

input color                    i_bullsDivAColor      = clrBlue;                                    // Color of bulls divergence line / &25B ;8=89 1KGL59 4825@35=F88

input color                    i_bearsDivAColor      = clrRed;                                     // Color of bears divergence line / &25B ;8=89 <542. 4825@35=F88

input string                   i_string6_2           = "Divergence class B / 825@35=F88 :;0AA0 B";// ============================

input ENUM_YESNO               i_showClassB          = YES;                                        // Show / B>1@060BL

input color                    i_bullsDivBColor      = clrDodgerBlue;                              // Color of bulls divergence line / &25B ;8=89 1KGL59 4825@35=F88

input color                    i_bearsDivBColor      = clrMaroon;                                  // Color of bears divergence line / &25B ;8=89 <542. 4825@35=F88

input string                   i_string6_3           = "Divergence class C / 825@35=F88 :;0AA0 C";// ============================

input ENUM_YESNO               i_showClassC          = YES;                                        // Show / B>1@060BL

input color                    i_bullsDivCColor      = clrDeepSkyBlue;                             // Color of bulls divergence line / &25B ;8=89 1KGL59 4825@35=F88

input color                    i_bearsDivCColor      = clrPurple;                                  // Color of bears divergence line / &25B ;8=89 <542. 4825@35=F88

input string                   i_string6_4           = "Hidden divergence / !:@KB0O 4825@35=F8O";  // ============================

input ENUM_YESNO               i_showHidden          = YES;                                        // Show / B>1@060BL

input color                    i_bullsDivHColor      = clrYellowGreen;                             // Color of bulls divergence line / &25B ;8=89 1KGL59 4825@35=F88

input color                    i_bearsDivHColor      = clrIndigo;                                  // Color of bears divergence line / &25B ;8=89 <542. 4825@35=F88



input string                   i_string7             = "Parameters of a table / 0@0<5B@K B01;8FK";// ================================

input color                    i_chartBackground     = clrBlack;                                   // Color of background / &25B D>=0

input color                    i_columnHeaderColor   = clrYellow;                                  // Color of column headers / &25B 703>;>2:>2 AB>;1F>2

input int                      i_indBarsCount        = 1000;                                       // The start bar index / =45:A =0G0;L=>3> 10@0 4;O ?>8A:0



// Global variables of indicator

bool              g_showBidLine,

                  g_showAskLine,

                  g_showOHLC,

                  g_showPeriodSep,

                  g_showGrid,

                  g_showOneClick,

                  g_showTradeLevels,

                  g_showChartShift,

                  g_activate;                                                                      // Sign of successfull initialization of the indicator



int               g_tfsCnt;

string            g_lSymbols[];

TFInfo            g_tfInfo[9];



int               g_divObjectsCnt,

                  g_symbolsCnt;

                  

ENUM_CHART_MODE   g_chartMode;



ENUM_CHART_VOLUME_MODE g_chartVolumeMode;



color             g_chartForeground,

                  g_chartBackground,

                  g_chartLineColor;

                  

Divergence        *g_divergence[MAX_SYMBOLS * 9];                                                  // Array of divergence objects



// Named constants

#define COLUMN_HEADER_X_START                         60

#define COLUMN_HEADER_Y_START                         10

#define COLUMN_WIDTH                                  50



#define ROW_HEADER_X_START                            25

#define ROW_HEADER_Y_START                            30

#define ROW_HEIGHT                                    20



#define DATA_X_START                                  40

#define DATA_Y_START                                  30



#define COLUMN_SIGN                                   "_COLUMN_"

#define ROW_SIGN                                      "_ROW_"

#define DIV_SIGN                                      "_DIV_"



#define HEADER_FONT_NAME                              "Consolas"

#define HEADER_FONT_SIZE                              9

#define DIVERGENCE_FONT_NAME                          "Impact"

#define DIVERGENCE_FONT_SIZE                          10

            

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

//| Custom indicator initialization function                                                                                                                                                          |

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

int OnInit()

{

   g_activate = false;   

   g_divObjectsCnt = 0;                                                                          

   

   if (!IsTuningParametersCorrect())                                                               

      return INIT_FAILED;  

            

   if (!InitializeClasses())                                                               

      return INIT_FAILED;  

      

   HideChart();

   ShowHeaders();



   g_activate = true; 

   EventSetTimer(1);                                                                             

   return INIT_SUCCEEDED;

}

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

//| Checking the correctness of input parameters                                                                                                                                                      |

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

bool IsTuningParametersCorrect()

{

   string name = WindowExpertName();

   bool isRussianLang = (TerminalInfoString(TERMINAL_LANGUAGE) == "Russian");



   if (i_barsPeriod1 < 1)

   {

      Alert(name, (isRussianLang)? ": ?5@2>5 :>;8G5AB2> 10@>2 4;O @0AG5B0 ?>:070=89 8=48:0B>@0 <5=55 1. =48:0B>@ >B:;NG5=." : 

                                   ": the first amount of bars for calculate the indicator values is less then 1. The indicator is turned off.");

      return false;

   }



   if (i_barsPeriod2 < 1)

   {

      Alert(name, (isRussianLang)? ": 2B>@>5 :>;8G5AB2> 10@>2 4;O @0AG5B0 ?>:070=89 8=48:0B>@0 <5=55 1. =48:0B>@ >B:;NG5=." :

                                   ": the second amount of bars for calculate the indicator values is less then 1. The indicator is turned off.");

      return false;

   }



   if (i_barsPeriod3 < 1)

   {

      Alert(name, (isRussianLang)? ": B@5BL5 :>;8G5AB2> 10@>2 4;O @0AG5B0 ?>:070=89 8=48:0B>@0 <5=55 1. =48:0B>@ >B:;NG5=." :

                                   ": the third amount of bars for calculate the indicator values is less then 1. The indicator is turned off.");

      return false;

   }



   if (i_findExtInterval < 1)

   {

      Alert(name, (isRussianLang)? ": 8=B5@20; ?>8A:0 M:AB@5<C<0 F5=K 4>;65= 1KBL 1>;55 =C;O 10@>2. =48:0B>@ >B:;NG5=." :

                                   ": the interval of search of price extremum must be greater than zero bars. The indicator is turned off.");

      return false;

   }

   

   FormTimeFrames();

   if (g_tfsCnt < 1)

   {

      Alert(name, (isRussianLang)? ": =8 >48= B09<D@59< =5 2K1@0=. =48:0B>@ >B:;NG5=." :

                                   ": no timeframe was selected. The indicator is turned off.");

      return false;

   }



   return true;

}

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

//| Form timeframe data                                                                                                                                                                               |

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

void FormTimeFrames()

{

   g_tfsCnt = 0;

   SaveTimeframe(i_tfM1, PERIOD_M1, "M1");

   SaveTimeframe(i_tfM5, PERIOD_M5, "M5");

   SaveTimeframe(i_tfM15, PERIOD_M15, "M15");

   SaveTimeframe(i_tfM30, PERIOD_M30, "M30");

   SaveTimeframe(i_tfH1, PERIOD_H1, "H1");

   SaveTimeframe(i_tfH4, PERIOD_H4, "H4");

   SaveTimeframe(i_tfD1, PERIOD_D1, "D1");

   SaveTimeframe(i_tfW1, PERIOD_W1, "W1");

   SaveTimeframe(i_tfMN1, PERIOD_MN1, "MN1");

}

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

//| Save one timeframe                                                                                                                                                                                |

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

void SaveTimeframe(ENUM_YESNO isTF, ENUM_TIMEFRAMES tf, string tfName)

{

   if (isTF == NO)

      return;

      

   g_tfInfo[g_tfsCnt].tf = tf;

   g_tfInfo[g_tfsCnt].text = tfName;

   g_tfsCnt++;

}

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

//| Classes initialization                                                                                                                                                                            |

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

bool InitializeClasses()

{

   string name = WindowExpertName();

   bool isRussianLang = (TerminalInfoString(TERMINAL_LANGUAGE) == "Russian");

   

   // Split the string of symbols

   g_symbolsCnt = StringSplit(i_symbols, ',', g_lSymbols);

   if (g_symbolsCnt <= 0)

   {

      Alert(WindowExpertName(), (isRussianLang)? ": A?8A>: >BA;568205<KE A8<2>;>2 A>AB02;5= =5?@028;L=>. =48:0B>@ >B:;NG5=." :

                                                 ": the list of monitored symbols compiled incorrectly. The indicator is turned off.");

      return false;

   }



   if (g_symbolsCnt > MAX_SYMBOLS)

   {

      Alert(WindowExpertName(), (isRussianLang)? ": :>;8G5AB2> 8A?>;L7C5<KE A8<2>;>2 =5 4>;6=> 1KBL 1>;LH5 G5< " + IntegerToString(MAX_SYMBOLS) + ". =48:0B>@ >B:;NG5=." :

                                                 ": the number of symbols used must not be more than " + IntegerToString(MAX_SYMBOLS) + ". The indicator is turned off.");

      return false;

   }

   

   // Create g_tfsCnt objects of Divergence class for each symbol

   for (int i = 0; i < g_symbolsCnt; i++)

      if (!IsCreateDivergence(g_lSymbols[i]))

      {

         Alert(WindowExpertName(), (isRussianLang)? ": =5 C40;>AL A>740BL M:75<?;O@ >1J5:B0 4;O A8<2>;0 " + g_lSymbols[i] + ". =48:0B>@ >B:;NG5=." :

                                                    ": failed to create an instance of the symbol " + g_lSymbols[i] + ". The indicator is turned off.");

         return false;

      }



   return true;

}

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

//| Create g_tfsCnt objects of Divergence class for each symbol                                                                                                                                       |

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

bool IsCreateDivergence(string symbol)

{

   for (int i = 0; i < g_tfsCnt; i++)

   {

      g_divergence[g_divObjectsCnt] = new Divergence(symbol, g_tfInfo[i].tf, i_indicatorType, i_divergenceDepth, i_barsPeriod1, i_barsPeriod2, i_barsPeriod3, i_indAppliedPrice, i_indMAMethod, 

                                                     i_findExtInterval, i_marketAppliedPrice, i_customName, i_customBuffer, i_customParamCnt, i_customParam1, i_customParam2, i_customParam3, 

                                                     i_customParam4, i_customParam5, i_customParam6, i_customParam7, i_customParam8, i_customParam9, i_customParam10, i_customParam11, i_customParam12,

                                                     i_customParam13, i_customParam14, i_customParam15, i_customParam16, i_customParam17, i_customParam18, i_customParam19, i_customParam20,

                                                     i_useCoincidenceCharts == ON, i_showClassA == YES, i_bullsDivAColor, i_bearsDivAColor, i_showClassB == YES, i_bullsDivBColor, i_bearsDivBColor, 

                                                     i_showClassC == YES, i_bullsDivCColor, i_bearsDivCColor, i_showHidden == YES, i_bullsDivHColor, i_bearsDivHColor, i_indBarsCount);

      if (g_divergence[g_divObjectsCnt] == NULL)

         return false;

         

      if (!g_divergence[g_divObjectsCnt].Init())

         return false;

         

      g_divObjectsCnt++;

   }

   

   return true;

}

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

//| Hide a chart view                                                                                                                                                                                 |

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

void HideChart()

{

   g_chartMode = (ENUM_CHART_MODE)ChartGetInteger(0, CHART_MODE);

   g_chartBackground = (color)ChartGetInteger(0, CHART_COLOR_BACKGROUND);

   g_chartLineColor = (color)ChartGetInteger(0, CHART_COLOR_CHART_LINE);

   g_chartForeground = (color)ChartGetInteger(0, CHART_COLOR_FOREGROUND);

   

   g_showAskLine = (bool)ChartGetInteger(0, CHART_SHOW_ASK_LINE);

   g_showBidLine = (bool)ChartGetInteger(0, CHART_SHOW_BID_LINE);

   g_showGrid = (bool)ChartGetInteger(0, CHART_SHOW_GRID);

   g_showOHLC = (bool)ChartGetInteger(0, CHART_SHOW_OHLC);

   g_showOneClick = (bool)ChartGetInteger(0, CHART_SHOW_ONE_CLICK);

   g_showPeriodSep = (bool)ChartGetInteger(0, CHART_SHOW_PERIOD_SEP);

   g_showTradeLevels = (bool)ChartGetInteger(0, CHART_SHOW_TRADE_LEVELS);

   g_showChartShift = (bool)ChartGetInteger(0, CHART_SHIFT);

   

   g_chartVolumeMode = (ENUM_CHART_VOLUME_MODE)ChartGetInteger(0, CHART_SHOW_VOLUMES);

   

   ChartSetInteger(0, CHART_MODE, CHART_LINE);

   ChartSetInteger(0, CHART_COLOR_CHART_LINE, i_chartBackground);

   ChartSetInteger(0, CHART_COLOR_BACKGROUND, i_chartBackground);

   ChartSetInteger(0, CHART_COLOR_FOREGROUND, i_chartBackground);

   

   ChartSetInteger(0, CHART_SHOW_ASK_LINE, false);

   ChartSetInteger(0, CHART_SHOW_BID_LINE, false);

   ChartSetInteger(0, CHART_SHOW_GRID, false);

   ChartSetInteger(0, CHART_SHOW_OHLC, false);

   ChartSetInteger(0, CHART_SHOW_ONE_CLICK, false);

   ChartSetInteger(0, CHART_SHOW_PERIOD_SEP, false);

   ChartSetInteger(0, CHART_SHOW_TRADE_LEVELS, false);

   ChartSetInteger(0, CHART_SHIFT, false);

   

   ChartSetInteger(0, CHART_SHOW_VOLUMES, CHART_VOLUME_HIDE);

}

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

//| Restore the chart view                                                                                                                                                                            |

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

void RestoreChart()

{

   ChartSetInteger(0, CHART_MODE, g_chartMode);

   ChartSetInteger(0, CHART_COLOR_CHART_LINE, g_chartLineColor);

   ChartSetInteger(0, CHART_COLOR_BACKGROUND, g_chartBackground);

   ChartSetInteger(0, CHART_COLOR_FOREGROUND, g_chartForeground);



   ChartSetInteger(0, CHART_SHOW_ASK_LINE, g_showAskLine);

   ChartSetInteger(0, CHART_SHOW_BID_LINE, g_showBidLine);

   ChartSetInteger(0, CHART_SHOW_GRID, g_showGrid);

   ChartSetInteger(0, CHART_SHOW_OHLC, g_showOHLC);

   ChartSetInteger(0, CHART_SHOW_ONE_CLICK, g_showOneClick);

   ChartSetInteger(0, CHART_SHOW_PERIOD_SEP, g_showPeriodSep);

   ChartSetInteger(0, CHART_SHOW_TRADE_LEVELS, g_showTradeLevels);

   ChartSetInteger(0, CHART_SHIFT, g_showChartShift);

   

   ChartSetInteger(0, CHART_SHOW_VOLUMES, g_chartVolumeMode);

}

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

//| Displaying the headers of columns and rows of table                                                                                                                                               |

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

void ShowHeaders()

{

   // The column headers of table

   for (int i = 0; i < g_symbolsCnt; i++)

      ShowText(COLUMN_HEADER_X_START + i * COLUMN_WIDTH, COLUMN_HEADER_Y_START, COLUMN_SIGN + IntegerToString(i), g_lSymbols[i], i_columnHeaderColor, ANCHOR_UPPER, HEADER_FONT_NAME, HEADER_FONT_SIZE);



   // The row headers of table

   for (int i = 0; i < g_tfsCnt; i++)

      ShowText(ROW_HEADER_X_START, ROW_HEADER_Y_START + i * ROW_HEIGHT, ROW_SIGN + IntegerToString(i), g_tfInfo[i].text, i_columnHeaderColor, ANCHOR_RIGHT_UPPER, HEADER_FONT_NAME, HEADER_FONT_SIZE); 

}

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

//| Show the graphic label                                                                                                                                                                            |

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

void ShowText(int x, int y, string sign, string text, color clr, ENUM_ANCHOR_POINT anchor, string fontName, int fontSize, string toolTip = "")

{

   string name = PREFIX + sign;

   

   if (ObjectFind(0, name) < 0)

   {

      ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);

      ObjectSetInteger(0, name, OBJPROP_CORNER, 0);

      

      ObjectSetString(0, name, OBJPROP_FONT, fontName);

      ObjectSetInteger(0, name, OBJPROP_FONTSIZE, fontSize);

      

      ObjectSetInteger(0, name, OBJPROP_ANCHOR, anchor);

      ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false);

      ObjectSetInteger(0, name, OBJPROP_SELECTED, false);

      ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);

   }



   ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x);

   ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y);

   ObjectSetString(0, name, OBJPROP_TEXT, text);

   ObjectSetString(0, name, OBJPROP_TOOLTIP, toolTip);

   ObjectSetInteger(0, name, OBJPROP_COLOR, clr);

}

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

//| Custom indicator deinitialization function                                                                                                                                                        |

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

void OnDeinit(const int reason)

{

   for (int i = g_divObjectsCnt - 1; i >= 0; i--)

      delete g_divergence[i];



   if (!g_activate)

      return;



   RestoreChart();

   DeleteAllObjects();

   EventKillTimer();

}

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

//| Deleting of all graphical objects                                                                                                                                                                 |

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

void DeleteAllObjects()

{

   string prefix = PREFIX;

   int strLen = StringLen(prefix);

   for (int i = ObjectsTotal() - 1; i >= 0; i--)     

      if (StringSubstr(ObjectName(i), 0, strLen) == prefix)

         ObjectDelete(ObjectName(i));

}

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

//| Timer function                                                                                                                                                                                    |

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

void OnTimer()

{

   DivergenceData divData;    

   string className, toolTip;

   color clr;

   for (int i = 0; i < g_divObjectsCnt; i++)

   {

      g_divergence[i].ProcessTick(divData);

      className = divData.divClass;

      toolTip = divData.divClass + ", " + TimeToString(divData.regTime);

      clr = divData.divColor;

      if (divData.divClass == "")

      {

         className = "None";

         toolTip = "None";

         clr = i_divAbsentColor;

      }

      

      ShowText(DATA_X_START + (i / g_tfsCnt) * COLUMN_WIDTH, DATA_Y_START + (i % g_tfsCnt) * ROW_HEIGHT, DIV_SIGN + IntegerToString(i), className, clr, ANCHOR_LEFT_UPPER, HEADER_FONT_NAME, 

               DIVERGENCE_FONT_SIZE, toolTip);

   }

       

   WindowRedraw();   

}

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

//| Custom indicator iteration function                                                                                                                                                               |

//+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime& time[],

                const double& open[],

                const double& high[],

                const double& low[],

                const double& close[],

                const long& tick_volume[],

                const long& volume[],

                const int& spread[])

{

   

   return rates_total;

}

Comments