Cumulative candle 2

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

//|                                          Cumulative candle 2.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   "2.000"

#property description "A;8 High 2KH5 ?@54K4CI53> High - MB> A25G0 'KGLO',"

#property description "   5A;8 Low =865 ?@54K4CI53> Low - MB> A25G0 '54256LO'"

#property description "If the High is higher than the previous High, it is a 'Bullish' candlestick,"

#property description "   if the Low is below the previous Low, it is a 'Bearish' candlestick"

#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=1;

      m_high=high[limit];

      m_low=low[limit];

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

     }

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

     {

      // --- 1

      if((high[i]<high[i-1] && low[i]>low[i-1]) || (high[i]>high[i-1] && low[i]<low[i-1]))

        {

         HighBuffer[i]=0.0;

         HighColor[i]=0.0;

         LowBuffer[i]=0.0;

         LowColor[i]=0.0;

         m_high=high[i];

         m_low=low[i];

         continue;

        }

      //--- 2. high[i]>high[i-1]

      if(high[i]>high[i-1])

        {

         HighBuffer[i]=high[i];

         HighColor[i]=0.0;

         LowBuffer[i]=0.0;

         LowColor[i]=0.0;

        }

      //--- 3. low[i]<low[i-1]

      if(low[i]<low[i-1])

        {

         HighBuffer[i]=0.0;

         HighColor[i]=1.0;

         LowBuffer[i]=low[i];

         LowColor[i]=1.0;

        }

     }

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

   return(rates_total);

  }

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

Comments