/*
███████╗ ██████╗ ██████╗ ███████╗██╗  ██╗     ███████╗████████╗ █████╗ ████████╗██╗ ██████╗ ███╗   ██╗
██╔════╝██╔═══██╗██╔══██╗██╔════╝╚██╗██╔╝     ██╔════╝╚══██╔══╝██╔══██╗╚══██╔══╝██║██╔═══██╗████╗  ██║
█████╗  ██║   ██║██████╔╝█████╗   ╚███╔╝█████╗███████╗   ██║   ███████║   ██║   ██║██║   ██║██╔██╗ ██║
██╔══╝  ██║   ██║██╔══██╗██╔══╝   ██╔██╗╚════╝╚════██║   ██║   ██╔══██║   ██║   ██║██║   ██║██║╚██╗██║
██║     ╚██████╔╝██║  ██║███████╗██╔╝ ██╗     ███████║   ██║   ██║  ██║   ██║   ██║╚██████╔╝██║ ╚████║
╚═╝      ╚═════╝ ╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝     ╚══════╝   ╚═╝   ╚═╝  ╚═╝   ╚═╝   ╚═╝ ╚═════╝ ╚═╝  ╚═══╝
*/
//+-------------------------------------------------------------------------------------------+
//|                                                                              VolMTF.mq5   |
//|                                                 Copyright @ 2015 traderathome and qFish   |
//|                                                             Converted from MQL4 to MQL5   |
//+-------------------------------------------------------------------------------------------+
/*---------------------------------------------------------------------------------------------
User Notes:

This indicator is coded to run on MT4 Build 600+.  It draws PVA (Price-Volume Analysis) bars
and candlesticks, as well as standard bars, candlesticks and Heiken-Ashi candles.  In the PVA
mode, an alert option signals when a "Climax" situation exists. Specific details follow.

PVA Bars & Candlesticks -
   The PVA bars and PVA candlesticks are used together with PVA volume for easy recognition of
   when special price and volume situations occur.  The special situations, or requirements for
   the colors used are as follows.

   Situation "Climax"
   Bars with volume >= 200% of the average volume of the 10 previous chart TFs, and bars
   where the product of candle spread x candle volume is >= the highest for the 10 previous
   chart time TFs.
   Default Colors:  Bull bars are green and bear bars are red.

   Situation "Volume Rising Above Average"
   Bars with volume >= 150% of the average volume of the 10 previous chart TFs.
   Default Colors:  Bull bars are blue and bear are blue-violet.

   PVA Color Options -
   There are three PVA color options provided....
     1. Simple:  Use this option for a simple PVA two color display based on Climax only
        situations (an option allows you to include "Rising" volume).  You can change any
        color.  To start, a shade of blue/red are input for the PVA bull/bear bars.
     2. Standard:  Use this option for the 4-color PVA display where you can change any
        color. To start, the traditional PVA colors are input.
     3. Default:  There are no inputs.  The traditional PVA four color display is
        hard coded.  You can easily return to this display anytime while preserving
        those changes you have made to the Simple and the Standard display options.

Selecting the Type of PVA Price Display -
   To display PVA set "__PVA_BAR_STD_HA_1234" to "1".  You can then choose a variety of
   PVA displays with the next input "__PVA_Bars_Candles_Bodies_123".  Input "1" to show a
   PVA bar chart.  Input "2" to show a PVA candlestick chart.  These bar and candlestick
   display on top of the solid color Price Band.  Input "3" to show only the PVA colored
   bodies as overlays on top of a standard MT4 bar or candlestick chart.  These bar and
   candlesticks will not be on top of the solid color Price Band.  Use one of the line
   Price Band options with them.  For these MT4 price draws select chart Properties, on the
   "Colors" tab give a color to "Line graph" and on the "Common" tab uncheck "Line chart"
   and check "Bar chart" or "Candlesticks".  If you make these changes to chart Properties,
   standard bars and candles produced by "__PVA_BAR_STD_HA_1234" equals "2" or "3" will
   still properly display, however, the HA candles produced by "__PVA_BAR_STD_HA_1234"
   equals "4" will not properly display.

The Alert -
   When displaying PVA Candles, this indicator includes a sound-text alert that triggers
   once per TF at the first qualification of the TF bar as a "Climax" situation.  Set both
   "Show_Alert_Label" and "Alert_On" inputs to "true" to operate the alert, and enter your
   "Broker_Name_In_Alert" to avoid confusion if simultaneously using multiple platforms.
   However, "Show_Alert_Label" and "Alert_On", should be set to "false" if also using the
   Volumes Suite indicator, which provides the same alert and is the one to use.

STD Bars, Candlesticks and HA Candles -
   Standard bars, candlesticks and Heiken-Ashi candles (modified to show price gaps) can be
   displayd.  Set "__PVA_BAR_STD_HA_1234" to "2" for bars.  Set "__PVA_BAR_STD_HA_1234"
   to "3" for standard candlesticks.  Set "__PVA_BAR_STD_HA_1234" to "4" for HA candles.
   Chart Properties should be set so no color is assigned to "Line chart" and so that
   "Line chart" is selected.  This prevents any MT4 price draw and allows this indicator
   to produce the various price draws.  If you change from this in order to use MT4 drawn
   prices (see PVA section above) the HA candles will not properly display.  To select colors
   for standard and HA candles and wicks use the input "Non_PVA_Color_Options_1_2_3_4_5".
   These selections color the up/down wicks a shade darker than the bull/bear candle colors,
   which improves the esthetics of the price display.  If you want monochromatic wicks, you
   can simply make "Apply_Wicks_OverRide_Color" be "true" and input the monochromatic color
   you desire at "__Wicks_OverRide_Color_Up" and "__Wicks_OverRide_Color_Dn".  These two
   inputs are the colors used to display standard bars.

                                                                    - Traderathome, 05-30-2015
-----------------------------------------------------------------------------------------------
Acknowledgements:
BetterVolume.mq4 - for initial "climax" candle code definition (BetterVolume_v1.4).

----------------------------------------------------------------------------------------------
Suggested Colors            White Chart        Black Chart        Remarks

indicator_color1            C'006,000,079'     C'140,140,140'     Candlewicks Up
indicator_color2            C'006,000,079''    C'140,140,140'     Candlewicks Dn
indicator_color3            C'159,160,162'     C'159,160,162'     Bull STD Candle
indicator_color4            C'106,106,117'     C'106,106,117'     Bear STD Candle
indicator_color5            C'067,100,214'     C'017,136,255'     Bull Rising
indicator_color6            C'154,038,232'     C'173,051,255'     Bear Rising
indicator_color7            C'000,166,100'     C'031,192,071'     Bull Climax
indicator_color8            C'214,012,083'     C'224,001,006'     Bear Climax

Note: Suggested colors coincide with the colors of the Volumes Suite indicator.
---------------------------------------------------------------------------------------------*/


//+-------------------------------------------------------------------------------------------+
//| Indicator Global Inputs                                                                   |
//+-------------------------------------------------------------------------------------------+
#property copyright "Copyright @ 2015 traderathome and qFish"
#property link      "email: traderathome@msn.com"
#property version   "1.0"
#property indicator_chart_window

// 4 plots x (2 data + 1 color) = 12 buffers
#property indicator_buffers 12
#property indicator_plots   4

// Plot 0: Wicks
#property indicator_type1   DRAW_COLOR_HISTOGRAM2
#property indicator_color1  C'006,000,079', C'006,000,079'
#property indicator_width1  1
#property indicator_label1  "WickHi;WickLo"

// Plot 1: Bodies
#property indicator_type2   DRAW_COLOR_HISTOGRAM2
#property indicator_color2  C'159,160,162', C'106,106,117'
#property indicator_width2  3
#property indicator_label2  "BodyHi;BodyLo"

// Plot 2: Rising Volume
#property indicator_type3   DRAW_COLOR_HISTOGRAM2
#property indicator_color3  C'067,100,214', C'154,038,232'
#property indicator_width3  3
#property indicator_label3  "RiseHi;RiseLo"

// Plot 3: Climax Volume
#property indicator_type4   DRAW_COLOR_HISTOGRAM2
#property indicator_color4  C'000,166,100', C'214,012,083'
#property indicator_width4  3
#property indicator_label4  "ClmxHi;ClmxLo"

//--- Inputs
input bool   Indicator_On                               = true;
input string Select_Price_Style_to_Display              = "";
input int    __PVA_BAR_STD_HA_1234                      = 1;
input string For_PVA_Select_Style_and_Coloring          = "";
input int    __PVA_Bars_Candles_Bodies_123               = 2;
input int    __PVA_Color_Simple_Standard_Default_123     = 3;

input string PVA_Simple_________________                = "";
input color  __Simple_Wicks                             = C'006,000,079';
input color  __Simple_Bull                              = C'159,160,162';
input color  __Simple_Bear                              = C'106,106,117';
input color  __Simple_PVA_Bull                          = C'067,100,214';
input color  __Simple_PVA_Bear                          = C'214,012,083';
input bool   __Include_Rising_Volume                    = false;

input string PVA_Standard_______________                = "";
input color  __Standard_Wicks                           = C'006,000,079';
input color  __Standard_Bull                            = C'159,160,162';
input color  __Standard_Bear                            = C'106,106,117';
input color  __Standard_Bull_Rising                     = C'067,100,214';
input color  __Standard_Bear_Rising                     = C'154,038,232';
input color  __Standard_Bull_Climax                     = C'000,166,100';
input color  __Standard_Bear_Climax                     = C'214,012,083';

input string Alert_______________________               = "";
input bool   Show_Alert_Label                           = false;
input bool   Alert_On                                   = false;
input string Broker_Name_In_Alert                       = "";

input string Non_PVA_Bars______________                 = "";
input color  __Bars_Color                               = C'006,000,079';

input string Non_PVA_Candles___________                 = "";
input int    Non_PVA_Color_Options_1_2_3_4_5            = 1;
input bool   Apply_Wicks_OverRide_Color                 = false;
input color  __Wicks_OverRide_Color_Up                  = C'006,000,079';
input color  __Wicks_OverRide_Color_Dn                  = C'006,000,079';
input color  __1_Wick_Up  = C'054,071,139';  input color  __1_Wick_Dn  = C'149,000,074';
input color  __1_Bull     = C'069,083,180';  input color  __1_Bear     = C'204,036,095';
input color  __2_Wick_Up  = C'054,071,139';  input color  __2_Wick_Dn  = C'143,052,112';
input color  __2_Bull     = C'069,083,180';  input color  __2_Bear     = C'176,049,132';
input color  __3_Wick_Up  = C'046,118,089';  input color  __3_Wick_Dn  = C'149,000,074';
input color  __3_Bull     = C'046,148,115';  input color  __3_Bear     = C'204,036,095';
input color  __4_Wick_Up  = C'046,118,089';  input color  __4_Wick_Dn  = C'143,052,112';
input color  __4_Bull     = C'046,148,115';  input color  __4_Bear     = C'176,049,132';
input color  __5_Wick_Up  = C'006,000,079';  input color  __5_Wick_Dn  = C'006,000,079';
input color  __5_Bull     = C'159,160,162';  input color  __5_Bear     = C'106,106,117';

//--- Buffers: Plot 0 (wicks)
double WickHi[], WickLo[], WickClr[];
//--- Buffers: Plot 1 (bodies)
double BodyHi[], BodyLo[], BodyClr[];
//--- Buffers: Plot 2 (rising)
double RiseHi[], RiseLo[], RiseClr[];
//--- Buffers: Plot 3 (climax)
double ClmxHi[], ClmxLo[], ClmxClr[];

//--- Global variables
bool   Deinitialized;
color  Bull_Wick, Bear_Wick, Bull_Candle, Bear_Candle,
       Bull_Rising, Bear_Rising, Bull_Climax, Bear_Climax;
int    Chart_Scale, Bar_Width;

//--- Default PVA Colors
color  PVA_Normal_Wick  = C'006,000,079';
color  PVA_Normal_Bull  = C'159,160,162';
color  PVA_Normal_Bear  = C'106,106,117';
color  PVA_Bull_Rising  = C'067,100,214';
color  PVA_Bear_Rising  = C'154,038,232';
color  PVA_Bull_Climax  = C'000,166,100';
color  PVA_Bear_Climax  = C'214,012,083';

//--- Alert
bool   Alert_Allowed;
color  Alert_Color;
string text;
string item1 = "[PVA Candles] Alert Box";
string item2 = "[PVA Candles] Alert Text";
string item3 = "[PVA Candles] Alert Dot1";
string item4 = "[PVA Candles] Alert Dot2";

//+-------------------------------------------------------------------------------------------+
//| Deinit                                                                                    |
//+-------------------------------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   for(int k = ObjectsTotal(0) - 1; k >= 0; k--)
   {
      string name = ObjectName(0, k);
      if(StringSubstr(name, 0, 12) == "[PVA Candles")
         ObjectDelete(0, name);
   }
}

//+-------------------------------------------------------------------------------------------+
//| Setup colors and widths dynamically                                                       |
//+-------------------------------------------------------------------------------------------+
void SetupBuffersAndColors()
{
   Chart_Scale = ChartScaleGet();
        if(Chart_Scale == 0) Bar_Width = 1;
   else if(Chart_Scale == 1) Bar_Width = 2;
   else if(Chart_Scale == 2) Bar_Width = 2;
   else if(Chart_Scale == 3) Bar_Width = 3;
   else if(Chart_Scale == 4) Bar_Width = 6;
   else                      Bar_Width = 13;

   // Determine colors based on mode
   if(__PVA_BAR_STD_HA_1234 == 1)
   {
      if(__PVA_Color_Simple_Standard_Default_123 == 1)
      {
         Bull_Wick = __Simple_Wicks;      Bear_Wick = __Simple_Wicks;
         Bull_Candle = __Simple_Bull;     Bear_Candle = __Simple_Bear;
         Bull_Rising = __Simple_PVA_Bull; Bear_Rising = __Simple_PVA_Bear;
         Bull_Climax = __Simple_PVA_Bull; Bear_Climax = __Simple_PVA_Bear;
      }
      else if(__PVA_Color_Simple_Standard_Default_123 == 2)
      {
         Bull_Wick = __Standard_Wicks;        Bear_Wick = __Standard_Wicks;
         Bull_Candle = __Standard_Bull;       Bear_Candle = __Standard_Bear;
         Bull_Rising = __Standard_Bull_Rising; Bear_Rising = __Standard_Bear_Rising;
         Bull_Climax = __Standard_Bull_Climax; Bear_Climax = __Standard_Bear_Climax;
      }
      else
      {
         Bull_Wick = PVA_Normal_Wick;   Bear_Wick = PVA_Normal_Wick;
         Bull_Candle = PVA_Normal_Bull; Bear_Candle = PVA_Normal_Bear;
         Bull_Rising = PVA_Bull_Rising; Bear_Rising = PVA_Bear_Rising;
         Bull_Climax = PVA_Bull_Climax; Bear_Climax = PVA_Bear_Climax;
      }
   }
   else if(__PVA_BAR_STD_HA_1234 == 2)
   {
      Bull_Wick = __Bars_Color; Bear_Wick = __Bars_Color;
   }
   else // STD or HA
   {
      if(Non_PVA_Color_Options_1_2_3_4_5 == 1)
      { Bull_Wick=__1_Wick_Up; Bear_Wick=__1_Wick_Dn; Bull_Candle=__1_Bull; Bear_Candle=__1_Bear; }
      else if(Non_PVA_Color_Options_1_2_3_4_5 == 2)
      { Bull_Wick=__2_Wick_Up; Bear_Wick=__2_Wick_Dn; Bull_Candle=__2_Bull; Bear_Candle=__2_Bear; }
      else if(Non_PVA_Color_Options_1_2_3_4_5 == 3)
      { Bull_Wick=__3_Wick_Up; Bear_Wick=__3_Wick_Dn; Bull_Candle=__3_Bull; Bear_Candle=__3_Bear; }
      else if(Non_PVA_Color_Options_1_2_3_4_5 == 4)
      { Bull_Wick=__4_Wick_Up; Bear_Wick=__4_Wick_Dn; Bull_Candle=__4_Bull; Bear_Candle=__4_Bear; }
      else
      { Bull_Wick=__5_Wick_Up; Bear_Wick=__5_Wick_Dn; Bull_Candle=__5_Bull; Bear_Candle=__5_Bear; }

      if(Apply_Wicks_OverRide_Color)
      { Bull_Wick = __Wicks_OverRide_Color_Up; Bear_Wick = __Wicks_OverRide_Color_Dn; }
   }

   // Apply colors to plots (color index 0=bull, 1=bear)
   PlotIndexSetInteger(0, PLOT_LINE_COLOR, 0, Bull_Wick);
   PlotIndexSetInteger(0, PLOT_LINE_COLOR, 1, Bear_Wick);
   PlotIndexSetInteger(1, PLOT_LINE_COLOR, 0, Bull_Candle);
   PlotIndexSetInteger(1, PLOT_LINE_COLOR, 1, Bear_Candle);
   PlotIndexSetInteger(2, PLOT_LINE_COLOR, 0, Bull_Rising);
   PlotIndexSetInteger(2, PLOT_LINE_COLOR, 1, Bear_Rising);
   PlotIndexSetInteger(3, PLOT_LINE_COLOR, 0, Bull_Climax);
   PlotIndexSetInteger(3, PLOT_LINE_COLOR, 1, Bear_Climax);

   // Apply widths
   PlotIndexSetInteger(0, PLOT_LINE_WIDTH, 1);
   PlotIndexSetInteger(1, PLOT_LINE_WIDTH, Bar_Width);
   PlotIndexSetInteger(2, PLOT_LINE_WIDTH, Bar_Width);
   PlotIndexSetInteger(3, PLOT_LINE_WIDTH, Bar_Width);
}

//+-------------------------------------------------------------------------------------------+
//| Init                                                                                      |
//+-------------------------------------------------------------------------------------------+
int OnInit()
{
   Deinitialized = false;

   // Assign all 12 buffers (4 plots x 3 buffers: hi, lo, color)
   SetIndexBuffer(0,  WickHi,  INDICATOR_DATA);
   SetIndexBuffer(1,  WickLo,  INDICATOR_DATA);
   SetIndexBuffer(2,  WickClr, INDICATOR_COLOR_INDEX);
   SetIndexBuffer(3,  BodyHi,  INDICATOR_DATA);
   SetIndexBuffer(4,  BodyLo,  INDICATOR_DATA);
   SetIndexBuffer(5,  BodyClr, INDICATOR_COLOR_INDEX);
   SetIndexBuffer(6,  RiseHi,  INDICATOR_DATA);
   SetIndexBuffer(7,  RiseLo,  INDICATOR_DATA);
   SetIndexBuffer(8,  RiseClr, INDICATOR_COLOR_INDEX);
   SetIndexBuffer(9,  ClmxHi,  INDICATOR_DATA);
   SetIndexBuffer(10, ClmxLo,  INDICATOR_DATA);
   SetIndexBuffer(11, ClmxClr, INDICATOR_COLOR_INDEX);

   // Empty value = 0 (prices are never 0)
   for(int p = 0; p < 4; p++)
      PlotIndexSetDouble(p, PLOT_EMPTY_VALUE, 0.0);

   SetupBuffersAndColors();
   IndicatorSetString(INDICATOR_SHORTNAME, "Candles Suite");

   // Alert
   if(Show_Alert_Label && __PVA_BAR_STD_HA_1234 == 1)
   {
      text = "PVA";
      Alert_Allowed = Alert_On;
      Alert_Color = Alert_On ? clrLime : clrRed;
   }

   return(INIT_SUCCEEDED);
}

//+-------------------------------------------------------------------------------------------+
//| OnCalculate                                                                               |
//+-------------------------------------------------------------------------------------------+
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[])
{
   if(!Indicator_On)
   {
      if(!Deinitialized) { OnDeinit(0); Deinitialized = true; }
      return(0);
   }

   ArraySetAsSeries(WickHi, true);  ArraySetAsSeries(WickLo, true);  ArraySetAsSeries(WickClr, true);
   ArraySetAsSeries(BodyHi, true);  ArraySetAsSeries(BodyLo, true);  ArraySetAsSeries(BodyClr, true);
   ArraySetAsSeries(RiseHi, true);  ArraySetAsSeries(RiseLo, true);  ArraySetAsSeries(RiseClr, true);
   ArraySetAsSeries(ClmxHi, true);  ArraySetAsSeries(ClmxLo, true);  ArraySetAsSeries(ClmxClr, true);
   ArraySetAsSeries(time, true);
   ArraySetAsSeries(open, true);  ArraySetAsSeries(high, true);
   ArraySetAsSeries(low, true);   ArraySetAsSeries(close, true);
   ArraySetAsSeries(tick_volume, true);

   int limit;
   if(prev_calculated <= 0)
      limit = rates_total - 2;
   else
      limit = rates_total - prev_calculated + 1;

   // Determine what to show
   bool showWicks  = (__PVA_BAR_STD_HA_1234 != 1 || __PVA_Bars_Candles_Bodies_123 != 3);
   bool showBodies = (__PVA_BAR_STD_HA_1234 >= 3) ||
                     (__PVA_BAR_STD_HA_1234 == 1 && __PVA_Bars_Candles_Bodies_123 == 2);
   bool isPVA      = (__PVA_BAR_STD_HA_1234 == 1);
   bool isHA       = (__PVA_BAR_STD_HA_1234 == 4);

   if(!isHA)
   {
      for(int i = limit; i >= 0; i--)
      {
         // Clear all buffers
         WickHi[i]=0; WickLo[i]=0; WickClr[i]=0;
         BodyHi[i]=0; BodyLo[i]=0; BodyClr[i]=0;
         RiseHi[i]=0; RiseLo[i]=0; RiseClr[i]=0;
         ClmxHi[i]=0; ClmxLo[i]=0; ClmxClr[i]=0;

         double hi=high[i], lo=low[i], op=open[i], cl=close[i];
         double bHi=MathMax(op,cl), bLo=MathMin(op,cl);
         int colorIdx = (cl >= op) ? 0 : 1; // 0=bull, 1=bear

         // Wicks
         if(showWicks)
         {
            WickHi[i]  = hi;
            WickLo[i]  = lo;
            WickClr[i] = colorIdx;
         }

         // Bodies
         if(showBodies)
         {
            BodyHi[i]  = bHi;
            BodyLo[i]  = (cl == op) ? op - 0.000001 : bLo;
            BodyClr[i] = colorIdx;
         }

         // PVA analysis
         if(isPVA)
         {
            double av = 0;
            int va = 0;

            // Average volume of prior 10 bars
            for(int j = i+1; j <= i+10 && j < rates_total; j++)
               av += (double)tick_volume[j];
            av /= 10.0;

            // Climax check
            double Range  = hi - lo;
            double Value2 = (double)tick_volume[i] * Range;
            double HiValue2 = 0;
            for(int j = i+1; j <= i+10 && j < rates_total; j++)
            {
               double tv = (double)tick_volume[j] * (high[j] - low[j]);
               if(tv >= HiValue2) HiValue2 = tv;
            }
            if((Value2 >= HiValue2) || ((double)tick_volume[i] >= av * 2)) va = 1;

            // Rising check
            if(va == 0 &&
               ((__PVA_Color_Simple_Standard_Default_123 > 1) ||
               ((__PVA_Color_Simple_Standard_Default_123 == 1) && __Include_Rising_Volume)))
            {
               if((double)tick_volume[i] >= av * 1.5) va = 2;
            }

            // Apply PVA overlay
            if(va == 1)
            {
               ClmxHi[i]  = bHi;
               ClmxLo[i]  = (cl == op) ? op - 0.000001 : bLo;
               ClmxClr[i] = colorIdx;
               if(i == 0 && Alert_Allowed && Alert_On)
               {
                  Alert_Allowed = false;
                  Alert(Broker_Name_In_Alert, ":  ", _Symbol, "-",
                        EnumToString((ENUM_TIMEFRAMES)_Period), "   PVA alert!");
               }
            }
            else if(va == 2)
            {
               RiseHi[i]  = bHi;
               RiseLo[i]  = (cl == op) ? op - 0.000001 : bLo;
               RiseClr[i] = colorIdx;
            }
         }
      }

      // PVA Alert label objects
      ObjectDelete(0, item1); ObjectDelete(0, item2);
      ObjectDelete(0, item3); ObjectDelete(0, item4);
      if(Show_Alert_Label && __PVA_BAR_STD_HA_1234 == 1)
      {
         ObjectCreate(0, item1, OBJ_LABEL, 0, 0, 0);
         ObjectSetInteger(0, item1, OBJPROP_CORNER, CORNER_RIGHT_UPPER);
         ObjectSetInteger(0, item1, OBJPROP_XDISTANCE, 8);
         ObjectSetInteger(0, item1, OBJPROP_YDISTANCE, 4);
         ObjectSetInteger(0, item1, OBJPROP_BACK, false);
         ObjectSetInteger(0, item1, OBJPROP_COLOR, clrWhite);
         ObjectSetString(0, item1, OBJPROP_TEXT, "gggg");
         ObjectSetString(0, item1, OBJPROP_FONT, "Webdings");
         ObjectSetInteger(0, item1, OBJPROP_FONTSIZE, 11);

         ObjectCreate(0, item2, OBJ_LABEL, 0, 0, 0);
         ObjectSetInteger(0, item2, OBJPROP_CORNER, CORNER_RIGHT_UPPER);
         ObjectSetInteger(0, item2, OBJPROP_XDISTANCE, 18);
         ObjectSetInteger(0, item2, OBJPROP_YDISTANCE, 0);
         ObjectSetInteger(0, item2, OBJPROP_BACK, false);
         ObjectSetInteger(0, item2, OBJPROP_COLOR, clrMidnightBlue);
         ObjectSetString(0, item2, OBJPROP_TEXT, text);
         ObjectSetString(0, item2, OBJPROP_FONT, "Verdana");
         ObjectSetInteger(0, item2, OBJPROP_FONTSIZE, 7);

         ObjectCreate(0, item3, OBJ_LABEL, 0, 0, 0);
         ObjectSetInteger(0, item3, OBJPROP_CORNER, CORNER_RIGHT_UPPER);
         ObjectSetInteger(0, item3, OBJPROP_XDISTANCE, 5);
         ObjectSetInteger(0, item3, OBJPROP_YDISTANCE, 2);
         ObjectSetInteger(0, item3, OBJPROP_BACK, false);
         ObjectSetInteger(0, item3, OBJPROP_COLOR, clrDarkSlateBlue);
         ObjectSetString(0, item3, OBJPROP_TEXT, "n");
         ObjectSetString(0, item3, OBJPROP_FONT, "Webdings");
         ObjectSetInteger(0, item3, OBJPROP_FONTSIZE, 7);

         ObjectCreate(0, item4, OBJ_LABEL, 0, 0, 0);
         ObjectSetInteger(0, item4, OBJPROP_CORNER, CORNER_RIGHT_UPPER);
         ObjectSetInteger(0, item4, OBJPROP_XDISTANCE, 5);
         ObjectSetInteger(0, item4, OBJPROP_YDISTANCE, 2);
         ObjectSetInteger(0, item4, OBJPROP_BACK, false);
         ObjectSetInteger(0, item4, OBJPROP_COLOR, Alert_Color);
         ObjectSetString(0, item4, OBJPROP_TEXT, "=");
         ObjectSetString(0, item4, OBJPROP_FONT, "Webdings");
         ObjectSetInteger(0, item4, OBJPROP_FONTSIZE, 7);
      }
   }
   else // Heiken-Ashi
   {
      if(rates_total <= 10) return(0);

      for(int pos = limit; pos >= 0; pos--)
      {
         // Clear
         WickHi[pos]=0; WickLo[pos]=0; WickClr[pos]=0;
         BodyHi[pos]=0; BodyLo[pos]=0; BodyClr[pos]=0;
         RiseHi[pos]=0; RiseLo[pos]=0; RiseClr[pos]=0;
         ClmxHi[pos]=0; ClmxLo[pos]=0; ClmxClr[pos]=0;

         double haOpen2;
         if(low[pos] > high[pos + 1])
            haOpen2 = low[pos];
         else if(high[pos] < low[pos + 1])
            haOpen2 = high[pos];
         else
            haOpen2 = (BodyHi[pos + 1] + BodyLo[pos + 1]) / 2;

         double haClose2 = (open[pos] + high[pos] + low[pos] + close[pos]) / 4;
         double haHigh2  = MathMax(high[pos], MathMax(haOpen2, haClose2));
         double haLow2   = MathMin(low[pos], MathMin(haOpen2, haClose2));
         int colorIdx = (haOpen2 < haClose2) ? 0 : 1;

         WickHi[pos]  = haHigh2;
         WickLo[pos]  = haLow2;
         WickClr[pos] = colorIdx;

         BodyHi[pos]  = MathMax(haOpen2, haClose2);
         BodyLo[pos]  = MathMin(haOpen2, haClose2);
         BodyClr[pos] = colorIdx;
      }
   }

   return(rates_total);
}

//+-------------------------------------------------------------------------------------------+
//| Chart event handler                                                                       |
//+-------------------------------------------------------------------------------------------+
void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
{
   bool wasAllowed = Alert_Allowed;
   SetupBuffersAndColors();
   Alert_Allowed = wasAllowed;
}

//+-------------------------------------------------------------------------------------------+
//| Get chart scale                                                                           |
//+-------------------------------------------------------------------------------------------+
int ChartScaleGet()
{
   long result = -1;
   ChartGetInteger(0, CHART_SCALE, 0, result);
   return((int)result);
}
//+-------------------------------------------------------------------------------------------+
