Cumulative candle

Author: Copyright © 2021, Vladimir Karputov
0 Views
0 Downloads
0 Favorites
Cumulative candle
ÿþ//+------------------------------------------------------------------+

//|                                            Cumulative candle.mq5 |

//|                              Copyright © 2021, Vladimir Karputov |

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

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

#property copyright "Copyright © 2021, Vladimir Karputov"

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

#property version   "1.009"

#property indicator_chart_window

#property indicator_buffers 4

#property indicator_plots   2

//--- plot High

#property indicator_label1  "High"

#property indicator_type1   DRAW_COLOR_ARROW

#property indicator_color1  clrBlue,clrRed

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- plot Low

#property indicator_label2  "Low"

#property indicator_type2   DRAW_COLOR_ARROW

#property indicator_color2  clrBlue,clrRed

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1

//--- input parameters

input uchar    InpHighArrowCode     = 167;   // Arrow code "High" (Wingdings font's symbol codes)

input int      InpHighArrowShift    = -5;    // Arrow shift "High" (vertical shift of in pixels)

input uchar    InpLowArrowCode      = 167;   // Arrow code "Low" (Wingdings font's symbol codes)

input int      InpLowArrowShift     = 5;     // Arrow shift "Low" (vertical shift of in pixels)

//--- indicator buffers

double   HighBuffer[];

double   HighColor[];

double   LowBuffer[];

double   LowColor[];

//---

double   m_high=0.0;

double   m_low=0.0;

int      m_type=0;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,HighBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,HighColor,INDICATOR_COLOR_INDEX);

   SetIndexBuffer(2,LowBuffer,INDICATOR_DATA);

   SetIndexBuffer(3,LowColor,INDICATOR_COLOR_INDEX);

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

   PlotIndexSetInteger(0,PLOT_ARROW,InpHighArrowCode);

   PlotIndexSetInteger(1,PLOT_ARROW,InpLowArrowCode);

//--- set the vertical shift of arrows in pixels

   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,InpHighArrowShift);

   PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,InpLowArrowShift);

//--- set as an empty value 0

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);

//---

   return(INIT_SUCCEEDED);

  }

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

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

      m_high=high[limit];

      m_low=low[limit];

      m_type=(open[limit]<close[limit])?1:-1;

     }

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

     {

      int current_type=(open[i]<close[i])?1:-1;

      if(m_type!=current_type)

        {

         m_high=high[i];

         m_low=low[i];

         m_type=current_type;

        }

      else

        {

         if(high[i]>m_high)

            m_high=high[i];

         if(low[i]<m_low)

            m_low=low[i];

         m_type=current_type;

        }

      //---

      HighBuffer[i]=m_high;

      LowBuffer[i]=m_low;

      if(m_type==1)

        {

         HighColor[i]=0.0;

         LowColor[i]=0.0;

        }

      else

        {

         HighColor[i]=1.0;

         LowColor[i]=1.0;

        }

     }

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

   return(rates_total);

  }

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

Comments