//+------------------------------------------------------------------+ //| DRAW_HISTOGRAM2.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_HISTOGRAM2 drawing style" #property description "It draws a line from Open to Close" #property description "The color, width and style changed randomly" #property description "every N ticks" #property indicator_chart_window #property indicator_buffers 2 #property indicator_plots 1 //--- plot Histogram_2 #property indicator_label1 "Histogram_2" #property indicator_type1 DRAW_HISTOGRAM2 #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- input parameters input int N=5; // Number of ticks to change histogram properties //--- indicator buffers double Histogram_2Buffer1[]; double Histogram_2Buffer2[]; //--- invisible day int invisible_day; //--- colors array color colors[]={clrRed,clrBlue,clrGreen}; //--- line styles array ENUM_LINE_STYLE styles[]={STYLE_SOLID,STYLE_DASH,STYLE_DOT,STYLE_DASHDOT,STYLE_DASHDOTDOT}; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- set index buffers SetIndexBuffer(0,Histogram_2Buffer1,INDICATOR_DATA); SetIndexBuffer(1,Histogram_2Buffer2,INDICATOR_DATA); //--- set empty value PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0); //--- define invisible day randomly invisible_day=MathRand()%6; //--- 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[]) { static int ticks=0; //--- count the ticks ticks++; //--- if ticks>N if(ticks>=N) { //--- change properties ChangeLineAppearance(); //--- set ticks counter to 0 ticks=0; } //--- calculation int start=0; //--- used to determine weekday of the bar MqlDateTime dt; //--- start from if(prev_calculated>0) start=prev_calculated-1; // starting from the previous bar //--- filling the indicator buffer with values for(int i=start;i