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

//|                                                   Area Chart.mq5 |

//|                              Copyright © 2020, Vladimir Karputov |

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

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

#property copyright "Copyright © 2020, Vladimir Karputov"

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

#property version   "1.00"

#property indicator_chart_window

#property indicator_buffers 3

#property indicator_plots   2

//--- plot Area

#property indicator_label1  "Area"

#property indicator_type1   DRAW_FILLING

#property indicator_color1  C'190,228,252'

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- plot Line

#property indicator_label2  "Line"

#property indicator_type2   DRAW_LINE

#property indicator_color2  clrDeepSkyBlue

#property indicator_style2  STYLE_SOLID

#property indicator_width2  3

//--- input parameters

/**/

//--- indicator buffers

double   AreaBuffer1[];

double   AreaBuffer2[];

double   LineBuffer[];

//---

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,AreaBuffer1,INDICATOR_DATA);

   SetIndexBuffer(1,AreaBuffer2,INDICATOR_DATA);

   SetIndexBuffer(2,LineBuffer,INDICATOR_DATA);

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

  {

//--- transparent graph

   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++)

     {

      AreaBuffer1[i]=close[i];

      AreaBuffer2[i]=0.0;

      LineBuffer[i]=close[i];

     }

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

   return(rates_total);

  }

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

Comments