//+------------------------------------------------------------------+ //| DRAW_COLOR_LINE.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_LINE drawing style" #property description "It draws a line with different colors using the Close price" #property description "The line width, style and color are changed randomly after N ticks." #property indicator_chart_window #property indicator_buffers 2 #property indicator_plots 1 //--- plot ColorLine #property indicator_label1 "ColorLine" #property indicator_type1 DRAW_COLOR_LINE //--- 5 colors #property indicator_color1 clrRed,clrBlue,clrGreen,clrOrange,clrDeepPink // (it's possible to specify up to 64 colors) #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- input parameters input int N=5; // Number of ticks to change properties input int Length=20; // Same color interval (in bars) int line_colors=5; // Number of colors - see #property indicator_color1 //--- plotting buffer double ColorLineBuffer[]; //--- color buffer double ColorLineColors[]; //--- colors array color colors[]={clrRed,clrBlue,clrGreen,clrChocolate,clrMagenta,clrDodgerBlue,clrGoldenrod}; //--- 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,ColorLineBuffer,INDICATOR_DATA); SetIndexBuffer(1,ColorLineColors,INDICATOR_COLOR_INDEX); //--- set random seed MathSrand(GetTickCount()); //--- 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 to change style, color and width ticks++; //--- if ticks>=N if(ticks>=N) { //--- change line properties ChangeLineAppearance(); //--- change colors ChangeColors(colors,5); //--- set ticks counter to 0 ticks=0; } //--- calculation of indicator values for(int i=0;i