//+------------------------------------------------------------------+ //| DRAW_COLOR_HISTOGRAM.mq5 | //| Copyright 2011, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2011, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property version "1.00" #property description "This indicator is a demo of DRAW_COLOR_HISTOGRAM drawing style" #property description "It plots a sin(x) function as a color histogram in a separate window" #property description "The color and width are changed randomly after N ticks" #property description "The bars parameter sets the period (in bars) of the sin(x) function" #property indicator_separate_window #property indicator_buffers 2 #property indicator_plots 1 //--- input parameters input int bars=30; // Sin(x) period in bars input int N=5; // Ticks to change properties //--- plot Color_Histogram #property indicator_label1 "Color_Histogram" #property indicator_type1 DRAW_COLOR_HISTOGRAM //--- set 8 colors #property indicator_color1 clrRed,clrGreen,clrBlue,clrYellow,clrMagenta,clrCyan,clrMediumSeaGreen,clrGold #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- indicator data buffer double Color_HistogramBuffer[]; //--- color buffer double Color_HistogramColors[]; //--- additional variables double multiplier; int color_sections; //--- colors array color colors[]= { clrRed,clrBlue,clrGreen,clrChocolate,clrMagenta,clrDodgerBlue,clrGoldenrod, clrIndigo,clrLightBlue,clrAliceBlue,clrMoccasin,clrWhiteSmoke,clrCyan,clrMediumPurple }; //--- line styles array ENUM_LINE_STYLE styles[]={STYLE_SOLID,STYLE_DASH,STYLE_DOT,STYLE_DASHDOT,STYLE_DASHDOTDOT}; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,Color_HistogramBuffer,INDICATOR_DATA); SetIndexBuffer(1,Color_HistogramColors,INDICATOR_COLOR_INDEX); //---- colors color_sections=8; // //--- calc multiplier if(bars>1)multiplier=2.*M_PI/bars; else { PrintFormat("The bars should be greater than 1. bars=%d",bars); //--- exit return(-1); } //--- 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[]) { static int ticks=0; //--- count the ticks ticks++; //--- if ticks>=N if(ticks>=N) { //--- change histogram properties ChangeLineAppearance(); //--- change colors ChangeColors(colors,color_sections); //--- set ticks counter to 0 ticks=0; } //--- calculate indicator values int start=0; //--- if not first call, set starting index if(prev_calculated>0) start=prev_calculated-1; // set starting bar //--- filling the buffer with values for(int i=start;i