Author: Copyright © 2020, Vladimir Karputov
0 Views
0 Downloads
0 Favorites
Dot Bars
ÿþ//+------------------------------------------------------------------+

//|                                                     Dot Bars.mq5 |

//|                              Copyright © 2020, Vladimir Karputov |

//|                     https://www.mql5.com/ru/market/product/43161 |

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

#property copyright "Copyright © 2020, Vladimir Karputov"

#property link      "https://www.mql5.com/ru/market/product/43161"

#property version   "1.000"

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_plots   1

//--- plot Price

#property indicator_label1  "Price"

#property indicator_type1   DRAW_COLOR_ARROW

#property indicator_color1  clrDodgerBlue,clrTomato

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- input parameters

input ENUM_APPLIED_PRICE   Inp_applied_price = PRICE_CLOSE; // Type of price

input uchar                Inp_arrow_code    = 159;         // Arrow code (font Wingdings)

//--- indicator buffers

double   PriceBuffer[];

double   PriceColors[];

//---

color    clr_background;

color    clr_volume;

color    clr_chart_up;

color    clr_chart_down;

color    clr_chart_line;

color    clr_candle_bull;

color    clr_candle_bear;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,PriceBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,PriceColors,INDICATOR_COLOR_INDEX);

//--- define the symbol code for drawing in PLOT_ARROW

   PlotIndexSetInteger(0,PLOT_ARROW,Inp_arrow_code);

//--- Set as an empty value 0

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

//---

//---

   string label="";

   switch(Inp_applied_price)

     {

      case PRICE_CLOSE:

         label="Close Price";

         break;

      case PRICE_OPEN:

         label="Open Price";

         break;

      case PRICE_HIGH:

         label="High Price";;

         break;

      case PRICE_LOW:

         label="Low Price";

         break;

      case PRICE_MEDIAN:

         label="Median Price";

         break;

      case PRICE_TYPICAL:

         label="Typical Price";

         break;

      case PRICE_WEIGHTED:

         label="Weighted Close Price";

         break;

     }

   PlotIndexSetString(0,PLOT_LABEL,label);

//--- save

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

   clr_volume     = (color)ChartGetInteger(0,CHART_COLOR_VOLUME,0);

   clr_chart_up   = (color)ChartGetInteger(0,CHART_COLOR_CHART_UP,0);

   clr_chart_down = (color)ChartGetInteger(0,CHART_COLOR_CHART_DOWN,0);

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

   clr_candle_bull= (color)ChartGetInteger(0,CHART_COLOR_CANDLE_BULL,0);

   clr_candle_bear= (color)ChartGetInteger(0,CHART_COLOR_CANDLE_BEAR,0);

//--- transparent graph

   ChartSetInteger(0,CHART_COLOR_VOLUME,clrNONE);

   ChartSetInteger(0,CHART_COLOR_CHART_UP,clrNONE);

   ChartSetInteger(0,CHART_COLOR_CHART_DOWN,clrNONE);

   ChartSetInteger(0,CHART_COLOR_CHART_LINE,clrNONE);

   ChartSetInteger(0,CHART_COLOR_CANDLE_BULL,clrNONE);

   ChartSetInteger(0,CHART_COLOR_CANDLE_BEAR,clrNONE);

//---

   return(INIT_SUCCEEDED);

  }

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

//| Indicator deinitialization function                              |

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

void OnDeinit(const int reason)

  {

//--- restore all chart colors

   ChartSetInteger(0,CHART_COLOR_BACKGROUND,clr_background);

   ChartSetInteger(0,CHART_COLOR_VOLUME,clr_volume);

   ChartSetInteger(0,CHART_COLOR_CHART_UP,clr_chart_up);

   ChartSetInteger(0,CHART_COLOR_CHART_DOWN,clr_chart_down);

   ChartSetInteger(0,CHART_COLOR_CHART_LINE,clr_chart_line);

   ChartSetInteger(0,CHART_COLOR_CANDLE_BULL,clr_candle_bull);

   ChartSetInteger(0,CHART_COLOR_CANDLE_BEAR,clr_candle_bear);

   ChartRedraw(0);

  }

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

//| 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[])

  {

//---

   int limit=prev_calculated-1;

   if(prev_calculated==0)

      limit=0;

   for(int i=limit; i<rates_total; i++)

     {

      switch(Inp_applied_price)

        {

         case PRICE_CLOSE:

            PriceBuffer[i]=close[i];

            break;

         case PRICE_OPEN:

            PriceBuffer[i]=open[i];

            break;

         case PRICE_HIGH:

            PriceBuffer[i]=high[i];

            break;

         case PRICE_LOW:

            PriceBuffer[i]=low[i];

            break;

         case PRICE_MEDIAN:

            PriceBuffer[i]=(high[i] + low[i])/2.0;

            break;

         case PRICE_TYPICAL:

            PriceBuffer[i]=(high[i] + low[i] + close[i])/3.0;

            break;

         case PRICE_WEIGHTED:

            PriceBuffer[i]=(high[i] + low[i] + close[i] + close[i])/4.0;

            break;

        }

      if(open[i]<close[i])

         PriceColors[i]=0.0;

      else

         PriceColors[i]=1.0;

     }

//--- return value of prev_calculated for next call

   return(rates_total);

  }

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

Comments