//+------------------------------------------------------------------+ //| CandlesHist.mq5 | //| avoitenko | //| https://login.mql5.com/ru/users/avoitenko | //+------------------------------------------------------------------+ #property copyright "avoitenko" #property link "https://login.mql5.com/ru/users/avoitenko" #property description "Candles histogram" #property version "1.00" #property indicator_separate_window #property indicator_minimum 0 #property indicator_buffers 2 #property indicator_plots 2 #property indicator_type1 DRAW_HISTOGRAM #property indicator_color1 clrOrangeRed #property indicator_style1 STYLE_SOLID #property indicator_width1 3 #property indicator_type2 DRAW_HISTOGRAM #property indicator_color2 clrLimeGreen #property indicator_style2 STYLE_SOLID #property indicator_width2 3 //--- buffers double BodyBuffer[]; double ShadowBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { SetIndexBuffer(0, ShadowBuffer, INDICATOR_DATA); SetIndexBuffer(1, BodyBuffer, INDICATOR_DATA); ArraySetAsSeries(BodyBuffer,true); ArraySetAsSeries(ShadowBuffer,true); PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0); PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0); string short_name = "Candles histogram"; PlotIndexSetString(0,PLOT_LABEL,"Full Height"); PlotIndexSetString(1,PLOT_LABEL,"Body Height"); IndicatorSetInteger(INDICATOR_DIGITS,0); IndicatorSetString(INDICATOR_SHORTNAME,short_name); return(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[]) { ArraySetAsSeries(open,true); ArraySetAsSeries(close,true); ArraySetAsSeries(high,true); ArraySetAsSeries(low,true); int limit; if(prev_calculated>rates_total || prev_calculated<0) return(0); else if(prev_calculated==0) { limit=rates_total-1; for(int i=limit;i>=0;i--) { BodyBuffer[i] = 0.0; ShadowBuffer[i] = 0.0; } } else limit=rates_total-prev_calculated; for(int i=limit; i>=0; i--) { BodyBuffer[i] = MathAbs(close[i] - open[i])/_Point; ShadowBuffer[i] = (high[i] - low[i])/_Point; } return(rates_total); } //+------------------------------------------------------------------+