#property description "Indicator calculates absolute values of the difference between" #property description "Open and Close or High and Low prices displaying them in a separate subwindow" #property description "as a histrogram." //--- indicator settings #property indicator_separate_window #property indicator_buffers 1 #property indicator_plots 1 //---- plot #property indicator_type1 DRAW_HISTOGRAM #property indicator_style1 STYLE_SOLID #property indicator_width1 3 //--- input parameters input bool InpAsSeries=true; // Indexing direction in the indicator buffer input bool InpPrices=true; // Calculation prices (true - Open,Close; false - High,Low) //--- indicator buffer double ExtBuffer[]; //+------------------------------------------------------------------+ //| Calculating indicator values | //+------------------------------------------------------------------+ void CandleSizeOnBuffer(const int rates_total,const int prev_calculated, const double &first[],const double &second[],double &buffer[]) { //--- start variable for calculation of bars int start=prev_calculated; //--- work at the last bar if the indicator values have already been calculated at the previous tick if(prev_calculated>0) start--; //--- define indexing direction in arrays bool as_series_first=ArrayGetAsSeries(first); bool as_series_second=ArrayGetAsSeries(second); bool as_series_buffer=ArrayGetAsSeries(buffer); //--- replace indexing direction with direct one if necessary if(as_series_first) ArraySetAsSeries(first,false); if(as_series_second) ArraySetAsSeries(second,false); if(as_series_buffer) ArraySetAsSeries(buffer,false); //--- calculate indicator values for(int i=start;i<rates_total;i++) buffer[i]=MathAbs(first[i]-second[i]); } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- bind indicator buffers SetIndexBuffer(0,ExtBuffer); //--- set indexing element in the indicator buffer ArraySetAsSeries(ExtBuffer,InpAsSeries); //--- check for what prices the indicator is calculated if(InpPrices) { //--- Open and Close prices PlotIndexSetString(0,PLOT_LABEL,"BodySize"); //--- set the indicator color PlotIndexSetInteger(0,PLOT_LINE_COLOR,clrOrange); } else { //--- High and Low prices PlotIndexSetString(0,PLOT_LABEL,"ShadowSize"); //--- set the indicator color PlotIndexSetInteger(0,PLOT_LINE_COLOR,clrDodgerBlue); } //--- 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[]) { //--- calculate the indicator according to the flag value if(InpPrices) CandleSizeOnBuffer(rates_total,prev_calculated,open,close,ExtBuffer); else CandleSizeOnBuffer(rates_total,prev_calculated,high,low,ExtBuffer); //--- return value of prev_calculated for next call return(rates_total); } |