Bar height histogram

Author: Copyright © 2020, Vladimir Karputov
Price Data Components
0 Views
0 Downloads
0 Favorites
Bar height histogram
ÿþ//+------------------------------------------------------------------+

//|                                         Bar height histogram.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.000"

#property indicator_separate_window

#property indicator_buffers 1

#property indicator_plots   1

//--- plot BarHeight

#property indicator_label1  "BarHeight"

#property indicator_type1   DRAW_HISTOGRAM

#property indicator_color1  clrSpringGreen

#property indicator_style1  STYLE_SOLID

#property indicator_width1  2

//--- input parameters

input uint     InpMinHeight   = 15;    // Minimum bar height, in pips (1.00045-1.00055=1 pips)

//--- indicator buffers

double   BarHeightBuffer[];

//---

double   m_min_bar_height     = 0.0;   // Minimum bar height   -> double

double   m_adjusted_point;             // point value adjusted for 3 or 5 points

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,BarHeightBuffer,INDICATOR_DATA);

//--- an empty value

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

//--- name for DataWindow

   IndicatorSetString(INDICATOR_SHORTNAME,"Bar height histogram"+"("+string(InpMinHeight)+")");

//--- tuning for 3 or 5 digits

   int digits_adjust=1;

   if(Digits()==3 || Digits()==5)

      digits_adjust=10;

   m_adjusted_point=Point()*digits_adjust;



   m_min_bar_height  = InpMinHeight   * m_adjusted_point;

//---

   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;



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

     {

      double bar_height=close[i]-open[i];



      if(InpMinHeight>0)

        {

         BarHeightBuffer[i]=0.0;

         if(bar_height<0.0)

           {

            BarHeightBuffer[i]=(bar_height<=-m_min_bar_height)?bar_height:0.0;

           }

         else

            if(bar_height>0.0)

              {

               BarHeightBuffer[i]=(bar_height>=m_min_bar_height)?bar_height:0.0;

              }

        }

      else

         BarHeightBuffer[i]=bar_height;

     }

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

   return(rates_total);

  }

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

Comments