//+------------------------------------------------------------------+ //| DRAW_COLOR_LINE Lite.mq5 | //| Copyright 2016, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2011, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property description "An indicator to demonstrate DRAW_COLOR_LINE" #property description "It draws a line on Close price in colored pieces of 20 bars each" #property description "The width, style and color of the line parts are changed randomly" #property description "every 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 //--- Define 5 colors for coloring each bar (they are stored in the special array) #property indicator_color1 clrBlue,clrRed // (Up to 64 colors can be specified) #property indicator_style1 STYLE_SOLID #property indicator_width1 3 //--- A buffer for plotting double ColorLineBuffer[]; //--- A buffer for storing the line color on each bar double ColorLineColors[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- Binding an array and an indicator buffer SetIndexBuffer(0,ColorLineBuffer,INDICATOR_DATA); SetIndexBuffer(1,ColorLineColors,INDICATOR_COLOR_INDEX); //--- ArraySetAsSeries(ColorLineBuffer,true); ArraySetAsSeries(ColorLineColors,true); //--- 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[]) { ArraySetAsSeries(close,true); if(prev_calculated==0) { for(int i=0;iColorLineBuffer[i+1]) ColorLineColors[i]=0; else ColorLineColors[i]=1; } //--- Return the prev_calculated value for the next call of the function return(rates_total); } //+------------------------------------------------------------------+