//+------------------------------------------------------------------+ //| DRAW_COLOR_ZIGZAG.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 "DRAW_COLOR_ZIGZAG Indicator Demo" #property description "Draws colored zigzag line. Color depends on number of day in a week." #property description "Symbol, and lines color and thickness are changing " #property description "at random every N ticks" #property indicator_chart_window #property indicator_buffers 3 #property indicator_plots 1 //--- plot Color_Zigzag #property indicator_label1 "Color_Zigzag" #property indicator_type1 DRAW_COLOR_ZIGZAG //--- Define 8 colors to color the sections (stored in separate array) #property indicator_color1 clrRed,clrBlue,clrGreen,clrYellow,clrMagenta,clrCyan,clrLime,clrOrange #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- input parameter input int N=5; // Number of ticks to make changes int color_sections; //--- Buffers for values of line ends double Color_ZigzagBuffer1[]; double Color_ZigzagBuffer2[]; //--- Buffer for color indices of line ends double Color_ZigzagColors[]; //--- Array of 14 elements to store colors color colors[]= { clrRed,clrBlue,clrGreen,clrChocolate,clrMagenta,clrDodgerBlue,clrGoldenrod, clrIndigo,clrLightBlue,clrAliceBlue,clrMoccasin,clrWhiteSmoke,clrCyan,clrMediumPurple }; //--- Array to store lines drawing styles 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_ZigzagBuffer1,INDICATOR_DATA); SetIndexBuffer(1,Color_ZigzagBuffer2,INDICATOR_DATA); SetIndexBuffer(2,Color_ZigzagColors,INDICATOR_COLOR_INDEX); //---- Number of colors to color zigzag sections color_sections=8; // See comment to the #property indicator_color1 //--- 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; //--- Calculate ticks to change style, color and thickness of line ticks++; //--- If we have accumulated enough ticks if(ticks>=N) { //--- Change line properties ChangeLineAppearance(); //--- Change colors to color the sections ChangeColors(colors,color_sections); //--- Reset the ticks counter to zero ticks=0; } //--- The time structure is needed to get the weekday of each bar MqlDateTime dt; //--- Start calculations int start=0; //--- If indicator was calculated on the previous tick, start calculation from the penultimate if(prev_calculated!=0) start=prev_calculated-1; //--- Calculations loop for(int i=start;i